Fix: relayd: rotation failure for multi-domain session
[lttng-tools.git] / src / bin / lttng-relayd / utils.cpp
1 /*
2 * Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com>
3 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9 #define _LGPL_SOURCE
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13
14 #include <common/common.h>
15 #include <common/defaults.h>
16 #include <common/utils.h>
17
18 #include "lttng-relayd.h"
19 #include "utils.h"
20
21 static char *create_output_path_auto(const char *path_name)
22 {
23 int ret;
24 char *traces_path = NULL;
25 const char *default_path;
26
27 default_path = utils_get_home_dir();
28 if (default_path == NULL) {
29 ERR("Home path not found.\n \
30 Please specify an output path using -o, --output PATH");
31 goto exit;
32 }
33 ret = asprintf(&traces_path, "%s/" DEFAULT_TRACE_DIR_NAME
34 "/%s", default_path, path_name);
35 if (ret < 0) {
36 PERROR("asprintf trace dir name");
37 goto exit;
38 }
39 exit:
40 return traces_path;
41 }
42
43 static char *create_output_path_noauto(const char *path_name)
44 {
45 int ret;
46 char *traces_path = NULL;
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 */
69 char *create_output_path(const char *path_name)
70 {
71 LTTNG_ASSERT(path_name);
72
73 if (opt_output_path == NULL) {
74 return create_output_path_auto(path_name);
75 } else {
76 return create_output_path_noauto(path_name);
77 }
78 }
This page took 0.030314 seconds and 4 git commands to generate.