diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/udev-util.h | 4 | ||||
-rw-r--r-- | src/udev/udevd.c | 42 |
2 files changed, 25 insertions, 21 deletions
diff --git a/src/shared/udev-util.h b/src/shared/udev-util.h index 5f09ce181f..f758ce13e4 100644 --- a/src/shared/udev-util.h +++ b/src/shared/udev-util.h @@ -30,6 +30,8 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_enumerate*, udev_enumerate_unref); DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_event*, udev_event_unref); DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_rules*, udev_rules_unref); DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_ctrl*, udev_ctrl_unref); +DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_ctrl_connection*, udev_ctrl_connection_unref); +DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_ctrl_msg*, udev_ctrl_msg_unref); DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_monitor*, udev_monitor_unref); #define _cleanup_udev_unref_ _cleanup_(udev_unrefp) @@ -38,5 +40,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_monitor*, udev_monitor_unref); #define _cleanup_udev_event_unref_ _cleanup_(udev_event_unrefp) #define _cleanup_udev_rules_unref_ _cleanup_(udev_rules_unrefp) #define _cleanup_udev_ctrl_unref_ _cleanup_(udev_ctrl_unrefp) +#define _cleanup_udev_ctrl_connection_unref_ _cleanup_(udev_ctrl_connection_unrefp) +#define _cleanup_udev_ctrl_msg_unref_ _cleanup_(udev_ctrl_msg_unrefp) #define _cleanup_udev_monitor_unref_ _cleanup_(udev_monitor_unrefp) #define _cleanup_udev_list_cleanup_ _cleanup_(udev_list_cleanup) diff --git a/src/udev/udevd.c b/src/udev/udevd.c index ff36aaf2f1..27d8b125ca 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -53,6 +53,7 @@ static struct udev_rules *rules; static struct udev_ctrl *udev_ctrl; +static struct udev_ctrl_connection *udev_ctrl_conn; static struct udev_monitor *monitor; static int worker_watch[2] = { -1, -1 }; static int fd_signal = -1; @@ -500,7 +501,7 @@ static int event_queue_insert(struct udev_device *dev) { return 0; } -static void worker_kill(struct udev *udev) { +static void worker_kill(void) { struct worker *worker; Iterator i; @@ -677,26 +678,27 @@ static void worker_returned(int fd_worker) { } /* receive the udevd message from userspace */ -static struct udev_ctrl_connection *handle_ctrl_msg(struct udev_ctrl *uctrl) { - struct udev *udev = udev_ctrl_get_udev(uctrl); - struct udev_ctrl_connection *ctrl_conn; - struct udev_ctrl_msg *ctrl_msg = NULL; +static void handle_ctrl_msg(struct udev_ctrl *uctrl) { + _cleanup_udev_ctrl_connection_unref_ struct udev_ctrl_connection *ctrl_conn = NULL; + _cleanup_udev_ctrl_msg_unref_ struct udev_ctrl_msg *ctrl_msg = NULL; const char *str; int i; + assert(uctrl); + ctrl_conn = udev_ctrl_get_connection(uctrl); - if (ctrl_conn == NULL) - goto out; + if (!ctrl_conn) + return; ctrl_msg = udev_ctrl_receive_msg(ctrl_conn); - if (ctrl_msg == NULL) - goto out; + if (!ctrl_msg) + return; i = udev_ctrl_get_set_log_level(ctrl_msg); if (i >= 0) { log_debug("udevd message (SET_LOG_LEVEL) received, log_priority=%i", i); log_set_max_level(i); - worker_kill(udev); + worker_kill(); } if (udev_ctrl_get_stop_exec_queue(ctrl_msg) > 0) { @@ -738,7 +740,7 @@ static struct udev_ctrl_connection *handle_ctrl_msg(struct udev_ctrl *uctrl) { } free(key); } - worker_kill(udev); + worker_kill(); } i = udev_ctrl_get_set_children_max(ctrl_msg); @@ -754,11 +756,10 @@ static struct udev_ctrl_connection *handle_ctrl_msg(struct udev_ctrl *uctrl) { log_debug("udevd message (EXIT) received"); udev_exit = true; /* keep reference to block the client until we exit */ - udev_ctrl_connection_ref(ctrl_conn); + udev_ctrl_conn = udev_ctrl_connection_ref(ctrl_conn); } -out: - udev_ctrl_msg_unref(ctrl_msg); - return udev_ctrl_connection_unref(ctrl_conn); + + return; } static int synthesize_change(struct udev_device *dev) { @@ -1158,7 +1159,6 @@ int main(int argc, char *argv[]) { struct epoll_event ep_signal = { .events = EPOLLIN }; struct epoll_event ep_netlink = { .events = EPOLLIN }; struct epoll_event ep_worker = { .events = EPOLLIN }; - struct udev_ctrl_connection *ctrl_conn = NULL; int r = 0, one = 1; udev = udev_new(); @@ -1397,7 +1397,7 @@ int main(int argc, char *argv[]) { /* discard queued events and kill workers */ event_queue_cleanup(udev, EVENT_QUEUED); - worker_kill(udev); + worker_kill(); /* exit after all has cleaned up */ if (udev_list_node_is_empty(&event_list) && hashmap_isempty(workers)) @@ -1437,7 +1437,7 @@ int main(int argc, char *argv[]) { /* kill idle workers */ if (udev_list_node_is_empty(&event_list)) { log_debug("cleanup idle workers"); - worker_kill(udev); + worker_kill(); } /* check for hanging events */ @@ -1494,7 +1494,7 @@ int main(int argc, char *argv[]) { /* reload requested, HUP signal received, rules changed, builtin changed */ if (reload) { - worker_kill(udev); + worker_kill(); rules = udev_rules_unref(rules); udev_builtin_exit(udev); reload = false; @@ -1569,7 +1569,7 @@ int main(int argc, char *argv[]) { * exit. */ if (is_ctrl) - ctrl_conn = handle_ctrl_msg(udev_ctrl); + handle_ctrl_msg(udev_ctrl); } exit: @@ -1589,7 +1589,7 @@ exit_daemonize: if (worker_watch[WRITE_END] >= 0) close(worker_watch[WRITE_END]); udev_monitor_unref(monitor); - udev_ctrl_connection_unref(ctrl_conn); + udev_ctrl_connection_unref(udev_ctrl_conn); udev_ctrl_unref(udev_ctrl); udev_list_cleanup(&properties_list); mac_selinux_finish(); |