| 1 | /* |
| 2 | * Copyright (C) 2011 EfficiOS Inc. |
| 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 | /* |
| 20 | * Write to writable pipe used to notify a thread. |
| 21 | */ |
| 22 | int notify_thread_pipe(int wpipe) |
| 23 | { |
| 24 | ssize_t ret; |
| 25 | |
| 26 | /* Ignore if the pipe is invalid. */ |
| 27 | if (wpipe < 0) { |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | ret = lttng_write(wpipe, "!", 1); |
| 32 | if (ret < 1) { |
| 33 | PERROR("write poll pipe"); |
| 34 | } |
| 35 | |
| 36 | return (int) ret; |
| 37 | } |
| 38 | |
| 39 | int loglevels_match(int a_loglevel_type, int a_loglevel_value, |
| 40 | int b_loglevel_type, int b_loglevel_value, int loglevel_all_type) |
| 41 | { |
| 42 | int match = 1; |
| 43 | |
| 44 | if (a_loglevel_type == b_loglevel_type) { |
| 45 | /* Same loglevel type. */ |
| 46 | if (b_loglevel_type != loglevel_all_type) { |
| 47 | /* |
| 48 | * Loglevel value must also match since the loglevel |
| 49 | * type is not all. |
| 50 | */ |
| 51 | if (a_loglevel_value != b_loglevel_value) { |
| 52 | match = 0; |
| 53 | } |
| 54 | } |
| 55 | } else { |
| 56 | /* Loglevel type is different: no match. */ |
| 57 | match = 0; |
| 58 | } |
| 59 | |
| 60 | return match; |
| 61 | } |
| 62 | |
| 63 | const char *session_get_base_path(const struct ltt_session *session) |
| 64 | { |
| 65 | return consumer_output_get_base_path(session->consumer); |
| 66 | } |
| 67 | |
| 68 | const char *consumer_output_get_base_path(const struct consumer_output *output) |
| 69 | { |
| 70 | return output->type == CONSUMER_DST_LOCAL ? |
| 71 | output->dst.session_root_path : |
| 72 | output->dst.net.base_dir; |
| 73 | } |