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 |
28ab034a JG |
10 | #include "lttng-relayd.hpp" |
11 | #include "utils.hpp" | |
0f907de1 | 12 | |
c9e313bc SM |
13 | #include <common/common.hpp> |
14 | #include <common/defaults.hpp> | |
c9e313bc | 15 | #include <common/path.hpp> |
28ab034a | 16 | #include <common/utils.hpp> |
0f907de1 | 17 | |
28ab034a JG |
18 | #include <stdio.h> |
19 | #include <stdlib.h> | |
20 | #include <string.h> | |
0f907de1 | 21 | |
753871f3 | 22 | static char *create_output_path_auto(const char *path_name) |
0f907de1 JD |
23 | { |
24 | int ret; | |
cd9adb8b | 25 | char *traces_path = nullptr; |
4f00620d | 26 | const char *default_path; |
0f907de1 | 27 | |
feb0f3e5 | 28 | default_path = utils_get_home_dir(); |
cd9adb8b | 29 | if (default_path == nullptr) { |
0f907de1 JD |
30 | ERR("Home path not found.\n \ |
31 | Please specify an output path using -o, --output PATH"); | |
32 | goto exit; | |
33 | } | |
28ab034a | 34 | ret = asprintf(&traces_path, "%s/" DEFAULT_TRACE_DIR_NAME "/%s", default_path, path_name); |
0f907de1 JD |
35 | if (ret < 0) { |
36 | PERROR("asprintf trace dir name"); | |
37 | goto exit; | |
38 | } | |
39 | exit: | |
0f907de1 JD |
40 | return traces_path; |
41 | } | |
42 | ||
753871f3 | 43 | static char *create_output_path_noauto(const char *path_name) |
0f907de1 JD |
44 | { |
45 | int ret; | |
cd9adb8b | 46 | char *traces_path = nullptr; |
0f907de1 JD |
47 | char *full_path; |
48 | ||
49 | full_path = utils_expand_path(opt_output_path); | |
50 | if (!full_path) { | |
51 | goto exit; | |
52 | } | |
53 | ||
54 | ret = asprintf(&traces_path, "%s/%s", full_path, path_name); | |
55 | if (ret < 0) { | |
56 | PERROR("asprintf trace dir name"); | |
57 | goto exit; | |
58 | } | |
59 | exit: | |
60 | free(full_path); | |
61 | return traces_path; | |
62 | } | |
63 | ||
64 | /* | |
65 | * Create the output trace directory path name string. | |
66 | * | |
67 | * Return the allocated string containing the path name or else NULL. | |
68 | */ | |
753871f3 | 69 | char *create_output_path(const char *path_name) |
0f907de1 | 70 | { |
a0377dfe | 71 | LTTNG_ASSERT(path_name); |
0f907de1 | 72 | |
cd9adb8b | 73 | if (opt_output_path == nullptr) { |
0f907de1 JD |
74 | return create_output_path_auto(path_name); |
75 | } else { | |
76 | return create_output_path_noauto(path_name); | |
77 | } | |
78 | } |