Cleanup: mark utils_get_home_dir as returning a const string
[lttng-tools.git] / src / bin / lttng-relayd / utils.c
CommitLineData
0f907de1
JD
1/*
2 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
3 * David Goulet <dgoulet@efficios.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
6c1c0768 19#define _LGPL_SOURCE
0f907de1
JD
20#include <assert.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24
25#include <common/common.h>
26#include <common/defaults.h>
27#include <common/utils.h>
28
29#include "lttng-relayd.h"
30#include "utils.h"
31
753871f3 32static char *create_output_path_auto(const char *path_name)
0f907de1
JD
33{
34 int ret;
35 char *traces_path = NULL;
4f00620d 36 const char *default_path;
0f907de1 37
feb0f3e5 38 default_path = utils_get_home_dir();
0f907de1
JD
39 if (default_path == NULL) {
40 ERR("Home path not found.\n \
41 Please specify an output path using -o, --output PATH");
42 goto exit;
43 }
0f907de1 44 ret = asprintf(&traces_path, "%s/" DEFAULT_TRACE_DIR_NAME
b729f6f9 45 "/%s", default_path, path_name);
0f907de1
JD
46 if (ret < 0) {
47 PERROR("asprintf trace dir name");
48 goto exit;
49 }
50exit:
0f907de1
JD
51 return traces_path;
52}
53
753871f3 54static char *create_output_path_noauto(const char *path_name)
0f907de1
JD
55{
56 int ret;
57 char *traces_path = NULL;
58 char *full_path;
59
60 full_path = utils_expand_path(opt_output_path);
61 if (!full_path) {
62 goto exit;
63 }
64
65 ret = asprintf(&traces_path, "%s/%s", full_path, path_name);
66 if (ret < 0) {
67 PERROR("asprintf trace dir name");
68 goto exit;
69 }
70exit:
71 free(full_path);
72 return traces_path;
73}
74
75/*
76 * Create the output trace directory path name string.
77 *
78 * Return the allocated string containing the path name or else NULL.
79 */
753871f3 80char *create_output_path(const char *path_name)
0f907de1
JD
81{
82 assert(path_name);
83
84 if (opt_output_path == NULL) {
85 return create_output_path_auto(path_name);
86 } else {
87 return create_output_path_noauto(path_name);
88 }
89}
This page took 0.04274 seconds and 4 git commands to generate.