Fix: post-clear trace chunk has a late beginning packet
[lttng-tools.git] / src / bin / lttng-relayd / utils.c
CommitLineData
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>
18
19#include "lttng-relayd.h"
20#include "utils.h"
21
753871f3 22static char *create_output_path_auto(const char *path_name)
0f907de1
JD
23{
24 int ret;
25 char *traces_path = NULL;
4f00620d 26 const char *default_path;
0f907de1 27
feb0f3e5 28 default_path = utils_get_home_dir();
0f907de1
JD
29 if (default_path == NULL) {
30 ERR("Home path not found.\n \
31 Please specify an output path using -o, --output PATH");
32 goto exit;
33 }
0f907de1 34 ret = asprintf(&traces_path, "%s/" DEFAULT_TRACE_DIR_NAME
b729f6f9 35 "/%s", default_path, path_name);
0f907de1
JD
36 if (ret < 0) {
37 PERROR("asprintf trace dir name");
38 goto exit;
39 }
40exit:
0f907de1
JD
41 return traces_path;
42}
43
753871f3 44static char *create_output_path_noauto(const char *path_name)
0f907de1
JD
45{
46 int ret;
47 char *traces_path = NULL;
48 char *full_path;
49
50 full_path = utils_expand_path(opt_output_path);
51 if (!full_path) {
52 goto exit;
53 }
54
55 ret = asprintf(&traces_path, "%s/%s", full_path, path_name);
56 if (ret < 0) {
57 PERROR("asprintf trace dir name");
58 goto exit;
59 }
60exit:
61 free(full_path);
62 return traces_path;
63}
64
65/*
66 * Create the output trace directory path name string.
67 *
68 * Return the allocated string containing the path name or else NULL.
69 */
753871f3 70char *create_output_path(const char *path_name)
0f907de1
JD
71{
72 assert(path_name);
73
74 if (opt_output_path == NULL) {
75 return create_output_path_auto(path_name);
76 } else {
77 return create_output_path_noauto(path_name);
78 }
79}
This page took 0.048744 seconds and 4 git commands to generate.