Commit | Line | Data |
---|---|---|
d8d2416d FD |
1 | /* |
2 | * event-notifier-notification.c | |
3 | * | |
4 | * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com> | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; only | |
9 | * version 2.1 of the License. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
21 | #define _LGPL_SOURCE | |
22 | ||
23 | #include <errno.h> | |
24 | #include <lttng/ust-events.h> | |
25 | #include <usterr-signal-safe.h> | |
26 | ||
27 | #include "share.h" | |
28 | ||
29 | void lttng_event_notifier_notification_send( | |
30 | struct lttng_event_notifier *event_notifier) | |
31 | { | |
32 | /* | |
33 | * We want this write to be atomic AND non-blocking, meaning that we | |
34 | * want to write either everything OR nothing. | |
35 | * According to `pipe(7)`, writes that are smaller that the `PIPE_BUF` | |
36 | * value must be atomic, so we assert that the message we send is less | |
37 | * than PIPE_BUF. | |
38 | */ | |
39 | struct lttng_ust_event_notifier_notification notif; | |
40 | ssize_t ret; | |
41 | ||
42 | assert(event_notifier); | |
43 | assert(event_notifier->group); | |
44 | assert(sizeof(notif) <= PIPE_BUF); | |
45 | ||
46 | notif.token = event_notifier->user_token; | |
47 | ||
48 | ret = patient_write(event_notifier->group->notification_fd, ¬if, | |
49 | sizeof(notif)); | |
50 | if (ret == -1) { | |
51 | if (errno == EAGAIN) { | |
52 | DBG("Cannot send event notifier notification without blocking: %s", | |
53 | strerror(errno)); | |
54 | } else { | |
55 | DBG("Error to sending event notifier notification: %s", | |
56 | strerror(errno)); | |
57 | abort(); | |
58 | } | |
59 | } | |
60 | } |