Clean-up: move global sessiond symbols out of main.o
[lttng-tools.git] / src / bin / lttng-sessiond / utils.c
CommitLineData
8e68d1c8 1/*
996b65c8 2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
1e307fab 3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8e68d1c8 4 *
d14d33bf
AM
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2 only,
7 * as published by the Free Software Foundation.
8e68d1c8 8 *
d14d33bf
AM
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
8e68d1c8 13 *
d14d33bf
AM
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
8e68d1c8
DG
17 */
18
6c1c0768 19#define _LGPL_SOURCE
8e68d1c8 20#include <stdlib.h>
8e68d1c8
DG
21#include <unistd.h>
22
db758600 23#include <common/error.h>
7272acf5 24
8e68d1c8 25#include "utils.h"
0b2dc8df
MD
26#include "lttng-sessiond.h"
27
28int ht_cleanup_pipe[2] = { -1, -1 };
8e68d1c8 29
54d01ffb
DG
30/*
31 * Write to writable pipe used to notify a thread.
32 */
33int notify_thread_pipe(int wpipe)
34{
6cd525e8 35 ssize_t ret;
54d01ffb 36
2f77fc4b
DG
37 /* Ignore if the pipe is invalid. */
38 if (wpipe < 0) {
39 return 0;
40 }
41
6cd525e8
MD
42 ret = lttng_write(wpipe, "!", 1);
43 if (ret < 1) {
7272acf5 44 PERROR("write poll pipe");
54d01ffb
DG
45 }
46
6cd525e8 47 return (int) ret;
54d01ffb
DG
48}
49
0b2dc8df
MD
50void ht_cleanup_push(struct lttng_ht *ht)
51{
6cd525e8 52 ssize_t ret;
0b2dc8df
MD
53 int fd = ht_cleanup_pipe[1];
54
e7e84b72
JG
55 if (!ht) {
56 return;
57 }
5de62fd8
JG
58 if (fd < 0)
59 return;
6cd525e8
MD
60 ret = lttng_write(fd, &ht, sizeof(ht));
61 if (ret < sizeof(ht)) {
0b2dc8df
MD
62 PERROR("write ht cleanup pipe %d", fd);
63 if (ret < 0) {
64 ret = -errno;
65 }
66 goto error;
67 }
68
69 /* All good. Don't send back the write positive ret value. */
70 ret = 0;
71error:
72 assert(!ret);
73}
19a97244
PP
74
75int loglevels_match(int a_loglevel_type, int a_loglevel_value,
76 int b_loglevel_type, int b_loglevel_value, int loglevel_all_type)
77{
78 int match = 1;
79
80 if (a_loglevel_type == b_loglevel_type) {
81 /* Same loglevel type. */
82 if (b_loglevel_type != loglevel_all_type) {
83 /*
84 * Loglevel value must also match since the loglevel
85 * type is not all.
86 */
87 if (a_loglevel_value != b_loglevel_value) {
88 match = 0;
89 }
90 }
91 } else {
92 /* Loglevel type is different: no match. */
93 match = 0;
94 }
95
96 return match;
97}
a1ae2ea5
JD
98
99const char *session_get_base_path(const struct ltt_session *session)
100{
101 struct consumer_output *consumer;
102
103 if (session->kernel_session) {
104 consumer = session->kernel_session->consumer;
105 } else if (session->ust_session) {
106 consumer = session->ust_session->consumer;
107 } else {
108 abort();
109 }
110
111 if (session->net_handle > 0) {
112 return consumer->dst.net.base_dir;
113 } else {
114 return consumer->dst.session_root_path;
115 }
116}
This page took 0.060773 seconds and 4 git commands to generate.