Use lttng_read/lttng_write wrappers
[lttng-tools.git] / src / bin / lttng-sessiond / utils.c
1 /*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
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.
8 *
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.
13 *
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.
17 */
18
19 #define _GNU_SOURCE
20 #include <stdlib.h>
21 #include <unistd.h>
22
23 #include <common/error.h>
24
25 #include "utils.h"
26 #include "lttng-sessiond.h"
27
28 int ht_cleanup_pipe[2] = { -1, -1 };
29
30 /*
31 * Write to writable pipe used to notify a thread.
32 */
33 int notify_thread_pipe(int wpipe)
34 {
35 ssize_t ret;
36
37 /* Ignore if the pipe is invalid. */
38 if (wpipe < 0) {
39 return 0;
40 }
41
42 ret = lttng_write(wpipe, "!", 1);
43 if (ret < 1) {
44 PERROR("write poll pipe");
45 }
46
47 return (int) ret;
48 }
49
50 void ht_cleanup_push(struct lttng_ht *ht)
51 {
52 ssize_t ret;
53 int fd = ht_cleanup_pipe[1];
54
55 if (fd < 0)
56 return;
57 ret = lttng_write(fd, &ht, sizeof(ht));
58 if (ret < sizeof(ht)) {
59 PERROR("write ht cleanup pipe %d", fd);
60 if (ret < 0) {
61 ret = -errno;
62 }
63 goto error;
64 }
65
66 /* All good. Don't send back the write positive ret value. */
67 ret = 0;
68 error:
69 assert(!ret);
70 }
This page took 0.029701 seconds and 4 git commands to generate.