Commit | Line | Data |
---|---|---|
0f907de1 | 1 | /* |
ab5be9fa MJ |
2 | * Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com> |
3 | * Copyright (C) 2013 David Goulet <dgoulet@efficios.com> | |
0f907de1 | 4 | * |
ab5be9fa | 5 | * SPDX-License-Identifier: GPL-2.0-only |
0f907de1 | 6 | * |
0f907de1 JD |
7 | */ |
8 | ||
6c1c0768 | 9 | #define _LGPL_SOURCE |
0f907de1 JD |
10 | #include <assert.h> |
11 | #include <stdio.h> | |
12 | #include <stdlib.h> | |
13 | #include <string.h> | |
14 | ||
15 | #include <common/common.h> | |
16 | #include <common/defaults.h> | |
17 | #include <common/utils.h> | |
4b082b12 | 18 | #include <common/path.h> |
0f907de1 JD |
19 | |
20 | #include "lttng-relayd.h" | |
21 | #include "utils.h" | |
22 | ||
753871f3 | 23 | static char *create_output_path_auto(const char *path_name) |
0f907de1 JD |
24 | { |
25 | int ret; | |
26 | char *traces_path = NULL; | |
4f00620d | 27 | const char *default_path; |
0f907de1 | 28 | |
feb0f3e5 | 29 | default_path = utils_get_home_dir(); |
0f907de1 JD |
30 | if (default_path == NULL) { |
31 | ERR("Home path not found.\n \ | |
32 | Please specify an output path using -o, --output PATH"); | |
33 | goto exit; | |
34 | } | |
0f907de1 | 35 | ret = asprintf(&traces_path, "%s/" DEFAULT_TRACE_DIR_NAME |
b729f6f9 | 36 | "/%s", default_path, path_name); |
0f907de1 JD |
37 | if (ret < 0) { |
38 | PERROR("asprintf trace dir name"); | |
39 | goto exit; | |
40 | } | |
41 | exit: | |
0f907de1 JD |
42 | return traces_path; |
43 | } | |
44 | ||
753871f3 | 45 | static char *create_output_path_noauto(const char *path_name) |
0f907de1 JD |
46 | { |
47 | int ret; | |
48 | char *traces_path = NULL; | |
49 | char *full_path; | |
50 | ||
51 | full_path = utils_expand_path(opt_output_path); | |
52 | if (!full_path) { | |
53 | goto exit; | |
54 | } | |
55 | ||
56 | ret = asprintf(&traces_path, "%s/%s", full_path, path_name); | |
57 | if (ret < 0) { | |
58 | PERROR("asprintf trace dir name"); | |
59 | goto exit; | |
60 | } | |
61 | exit: | |
62 | free(full_path); | |
63 | return traces_path; | |
64 | } | |
65 | ||
66 | /* | |
67 | * Create the output trace directory path name string. | |
68 | * | |
69 | * Return the allocated string containing the path name or else NULL. | |
70 | */ | |
753871f3 | 71 | char *create_output_path(const char *path_name) |
0f907de1 JD |
72 | { |
73 | assert(path_name); | |
74 | ||
75 | if (opt_output_path == NULL) { | |
76 | return create_output_path_auto(path_name); | |
77 | } else { | |
78 | return create_output_path_noauto(path_name); | |
79 | } | |
80 | } |