Fix: hash table cleanup call_rcu deadlock
[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
19#define _GNU_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{
35 int ret;
36
2f77fc4b
DG
37 /* Ignore if the pipe is invalid. */
38 if (wpipe < 0) {
39 return 0;
40 }
41
6f94560a
MD
42 do {
43 ret = write(wpipe, "!", 1);
44 } while (ret < 0 && errno == EINTR);
54d01ffb 45 if (ret < 0) {
7272acf5 46 PERROR("write poll pipe");
54d01ffb
DG
47 }
48
49 return ret;
50}
51
b082db07 52/*
050349bb 53 * Return pointer to home directory path using the env variable HOME.
b082db07 54 *
050349bb 55 * No home, NULL is returned.
b082db07
DG
56 */
57const char *get_home_dir(void)
58{
59 return ((const char *) getenv("HOME"));
60}
0b2dc8df
MD
61
62void ht_cleanup_push(struct lttng_ht *ht)
63{
64 int ret;
65 int fd = ht_cleanup_pipe[1];
66
67 if (fd < 0)
68 return;
69 do {
70 ret = write(fd, &ht, sizeof(ht));
71 } while (ret < 0 && errno == EINTR);
72 if (ret < 0 || ret != sizeof(ht)) {
73 PERROR("write ht cleanup pipe %d", fd);
74 if (ret < 0) {
75 ret = -errno;
76 }
77 goto error;
78 }
79
80 /* All good. Don't send back the write positive ret value. */
81 ret = 0;
82error:
83 assert(!ret);
84}
This page took 0.04346 seconds and 5 git commands to generate.