Fix: define _LGPL_SOURCE in C files
[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
19#define _GNU_SOURCE
6c1c0768 20#define _LGPL_SOURCE
0f907de1
JD
21#include <assert.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25
26#include <common/common.h>
27#include <common/defaults.h>
28#include <common/utils.h>
29
30#include "lttng-relayd.h"
31#include "utils.h"
32
0f907de1
JD
33static char *create_output_path_auto(char *path_name)
34{
35 int ret;
36 char *traces_path = NULL;
37 char *alloc_path = NULL;
38 char *default_path;
39
feb0f3e5 40 default_path = utils_get_home_dir();
0f907de1
JD
41 if (default_path == NULL) {
42 ERR("Home path not found.\n \
43 Please specify an output path using -o, --output PATH");
44 goto exit;
45 }
46 alloc_path = strdup(default_path);
47 if (alloc_path == NULL) {
48 PERROR("Path allocation");
49 goto exit;
50 }
51 ret = asprintf(&traces_path, "%s/" DEFAULT_TRACE_DIR_NAME
52 "/%s", alloc_path, path_name);
53 if (ret < 0) {
54 PERROR("asprintf trace dir name");
55 goto exit;
56 }
57exit:
58 free(alloc_path);
59 return traces_path;
60}
61
62static char *create_output_path_noauto(char *path_name)
63{
64 int ret;
65 char *traces_path = NULL;
66 char *full_path;
67
68 full_path = utils_expand_path(opt_output_path);
69 if (!full_path) {
70 goto exit;
71 }
72
73 ret = asprintf(&traces_path, "%s/%s", full_path, path_name);
74 if (ret < 0) {
75 PERROR("asprintf trace dir name");
76 goto exit;
77 }
78exit:
79 free(full_path);
80 return traces_path;
81}
82
83/*
84 * Create the output trace directory path name string.
85 *
86 * Return the allocated string containing the path name or else NULL.
87 */
88char *create_output_path(char *path_name)
89{
90 assert(path_name);
91
92 if (opt_output_path == NULL) {
93 return create_output_path_auto(path_name);
94 } else {
95 return create_output_path_noauto(path_name);
96 }
97}
This page took 0.036166 seconds and 5 git commands to generate.