From e4f66b7773ae21278bf6b9c02a3282eec5996266 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Mon, 11 May 2015 22:17:49 +0200 Subject: udevd: make udev_ctrl_connection global This allows us to simplify the ctrl_msg handler. Eventually all this global state should move to a Manager object or so. --- src/udev/udevd.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'src/udev') 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(); -- cgit v1.2.3-54-g00ecf