diff --git a/udevcontrol.c b/udevcontrol.c index a983f22..4220eda 100644 --- a/udevcontrol.c +++ b/udevcontrol.c @@ -83,6 +83,8 @@ int main(int argc, char *argv[], char *e ctrl_msg.type = UDEVD_CTRL_START_EXEC_QUEUE; else if (!strcmp(arg, "reload_rules")) ctrl_msg.type = UDEVD_CTRL_RELOAD_RULES; + else if (!strcmp(arg, "restart")) + ctrl_msg.type = UDEVD_CTRL_RESTART; else if (!strncmp(arg, "log_priority=", strlen("log_priority="))) { intval = (int *) ctrl_msg.buf; val = &arg[strlen("log_priority=")]; @@ -123,6 +125,7 @@ int main(int argc, char *argv[], char *e " stop_exec_queue keep udevd from executing events, queue only\n" " start_exec_queue execute events, flush queue\n" " reload_rules reloads the rules files\n" + " restart tells udevd to restart itself\n" " max_childs= maximum number of childs\n" " max_childs_running= maximum number of childs running at the same time\n" " --help print this help text\n\n"); diff --git a/udevd.c b/udevd.c index bb956b5..6e8f6df 100644 --- a/udevd.c +++ b/udevd.c @@ -703,6 +703,13 @@ static void get_ctrl_msg(void) info("udevd message (RELOAD_RULES) received"); reload_config = 1; break; + case UDEVD_CTRL_RESTART: { + char *argv[2] = { "/proc/self/exe", NULL }; + info("udevd message (RESTART) received"); + if (execve(argv[0], argv, environ) == -1) + err("unable to restart udevd: %s", strerror(errno)); + break; + } default: err("unknown control message type"); } @@ -847,6 +854,9 @@ static int init_udevd_socket(void) /* enable receiving of the sender credentials */ setsockopt(udevd_sock, SOL_SOCKET, SO_PASSCRED, &feature_on, sizeof(feature_on)); + retval = fcntl(udevd_sock, F_GETFD); + if (retval != -1) + fcntl(udevd_sock, F_SETFD, retval | FD_CLOEXEC); return 0; } diff --git a/udevd.h b/udevd.h index fce86e7..d681da5 100644 --- a/udevd.h +++ b/udevd.h @@ -46,6 +46,7 @@ enum udevd_ctrl_msg_type { UDEVD_CTRL_SET_MAX_CHILDS, UDEVD_CTRL_SET_MAX_CHILDS_RUNNING, UDEVD_CTRL_RELOAD_RULES, + UDEVD_CTRL_RESTART, }; struct udevd_ctrl_msg {