Branch data Line data Source code
1 : : /* SPDX-License-Identifier: GPL-2.0+ */
2 : : #pragma once
3 : :
4 : : #include "sd-event.h"
5 : :
6 : : #include "macro.h"
7 : : #include "time-util.h"
8 : :
9 : : struct udev_ctrl;
10 : :
11 : : enum udev_ctrl_msg_type {
12 : : _UDEV_CTRL_END_MESSAGES,
13 : : UDEV_CTRL_SET_LOG_LEVEL,
14 : : UDEV_CTRL_STOP_EXEC_QUEUE,
15 : : UDEV_CTRL_START_EXEC_QUEUE,
16 : : UDEV_CTRL_RELOAD,
17 : : UDEV_CTRL_SET_ENV,
18 : : UDEV_CTRL_SET_CHILDREN_MAX,
19 : : UDEV_CTRL_PING,
20 : : UDEV_CTRL_EXIT,
21 : : };
22 : :
23 : : union udev_ctrl_msg_value {
24 : : int intval;
25 : : char buf[256];
26 : : };
27 : :
28 : : typedef int (*udev_ctrl_handler_t)(struct udev_ctrl *udev_ctrl, enum udev_ctrl_msg_type type,
29 : : const union udev_ctrl_msg_value *value, void *userdata);
30 : :
31 : : int udev_ctrl_new_from_fd(struct udev_ctrl **ret, int fd);
32 : 0 : static inline int udev_ctrl_new(struct udev_ctrl **ret) {
33 : 0 : return udev_ctrl_new_from_fd(ret, -1);
34 : : }
35 : :
36 : : int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl);
37 : : struct udev_ctrl *udev_ctrl_ref(struct udev_ctrl *uctrl);
38 : : struct udev_ctrl *udev_ctrl_unref(struct udev_ctrl *uctrl);
39 : : int udev_ctrl_cleanup(struct udev_ctrl *uctrl);
40 : : int udev_ctrl_attach_event(struct udev_ctrl *uctrl, sd_event *event);
41 : : int udev_ctrl_start(struct udev_ctrl *uctrl, udev_ctrl_handler_t callback, void *userdata);
42 : : sd_event_source *udev_ctrl_get_event_source(struct udev_ctrl *uctrl);
43 : :
44 : : int udev_ctrl_wait(struct udev_ctrl *uctrl, usec_t timeout);
45 : :
46 : : int udev_ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int intval, const char *buf);
47 : 0 : static inline int udev_ctrl_send_set_log_level(struct udev_ctrl *uctrl, int priority) {
48 : 0 : return udev_ctrl_send(uctrl, UDEV_CTRL_SET_LOG_LEVEL, priority, NULL);
49 : : }
50 : :
51 : 0 : static inline int udev_ctrl_send_stop_exec_queue(struct udev_ctrl *uctrl) {
52 : 0 : return udev_ctrl_send(uctrl, UDEV_CTRL_STOP_EXEC_QUEUE, 0, NULL);
53 : : }
54 : :
55 : 0 : static inline int udev_ctrl_send_start_exec_queue(struct udev_ctrl *uctrl) {
56 : 0 : return udev_ctrl_send(uctrl, UDEV_CTRL_START_EXEC_QUEUE, 0, NULL);
57 : : }
58 : :
59 : 0 : static inline int udev_ctrl_send_reload(struct udev_ctrl *uctrl) {
60 : 0 : return udev_ctrl_send(uctrl, UDEV_CTRL_RELOAD, 0, NULL);
61 : : }
62 : :
63 : 0 : static inline int udev_ctrl_send_set_env(struct udev_ctrl *uctrl, const char *key) {
64 : 0 : return udev_ctrl_send(uctrl, UDEV_CTRL_SET_ENV, 0, key);
65 : : }
66 : :
67 : 0 : static inline int udev_ctrl_send_set_children_max(struct udev_ctrl *uctrl, int count) {
68 : 0 : return udev_ctrl_send(uctrl, UDEV_CTRL_SET_CHILDREN_MAX, count, NULL);
69 : : }
70 : :
71 : 0 : static inline int udev_ctrl_send_ping(struct udev_ctrl *uctrl) {
72 : 0 : return udev_ctrl_send(uctrl, UDEV_CTRL_PING, 0, NULL);
73 : : }
74 : :
75 : 0 : static inline int udev_ctrl_send_exit(struct udev_ctrl *uctrl) {
76 : 0 : return udev_ctrl_send(uctrl, UDEV_CTRL_EXIT, 0, NULL);
77 : : }
78 : :
79 [ # # ]: 0 : DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_ctrl*, udev_ctrl_unref);
|