Fix: possible null dereference
[lttng-tools.git] / src / bin / lttng-sessiond / utils.c
1 /*
2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9 #define _LGPL_SOURCE
10 #include <stdlib.h>
11 #include <unistd.h>
12
13 #include <common/error.h>
14
15 #include "utils.h"
16 #include "snapshot.h"
17 #include "lttng-sessiond.h"
18
19 int ht_cleanup_pipe[2] = { -1, -1 };
20
21 /*
22 * Write to writable pipe used to notify a thread.
23 */
24 int notify_thread_pipe(int wpipe)
25 {
26 ssize_t ret;
27
28 /* Ignore if the pipe is invalid. */
29 if (wpipe < 0) {
30 return 0;
31 }
32
33 ret = lttng_write(wpipe, "!", 1);
34 if (ret < 1) {
35 PERROR("write poll pipe");
36 }
37
38 return (int) ret;
39 }
40
41 void ht_cleanup_push(struct lttng_ht *ht)
42 {
43 ssize_t ret;
44 int fd = ht_cleanup_pipe[1];
45
46 if (!ht) {
47 return;
48 }
49 if (fd < 0)
50 return;
51 ret = lttng_write(fd, &ht, sizeof(ht));
52 if (ret < sizeof(ht)) {
53 PERROR("write ht cleanup pipe %d", fd);
54 if (ret < 0) {
55 ret = -errno;
56 }
57 goto error;
58 }
59
60 /* All good. Don't send back the write positive ret value. */
61 ret = 0;
62 error:
63 assert(!ret);
64 }
65
66 int loglevels_match(int a_loglevel_type, int a_loglevel_value,
67 int b_loglevel_type, int b_loglevel_value, int loglevel_all_type)
68 {
69 int match = 1;
70
71 if (a_loglevel_type == b_loglevel_type) {
72 /* Same loglevel type. */
73 if (b_loglevel_type != loglevel_all_type) {
74 /*
75 * Loglevel value must also match since the loglevel
76 * type is not all.
77 */
78 if (a_loglevel_value != b_loglevel_value) {
79 match = 0;
80 }
81 }
82 } else {
83 /* Loglevel type is different: no match. */
84 match = 0;
85 }
86
87 return match;
88 }
89
90 const char *session_get_base_path(const struct ltt_session *session)
91 {
92 return consumer_output_get_base_path(session->consumer);
93 }
94
95 const char *consumer_output_get_base_path(const struct consumer_output *output)
96 {
97 return output->type == CONSUMER_DST_LOCAL ?
98 output->dst.session_root_path :
99 output->dst.net.base_dir;
100 }
This page took 0.030806 seconds and 4 git commands to generate.