2 * Copyright (C) 2005-2011 Kay Sievers <kay.sievers@vrfy.org>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
23 #include <sys/types.h>
24 #include <sys/socket.h>
30 static void print_help(void)
32 printf("Usage: udevadm control COMMAND\n"
33 " --exit instruct the daemon to cleanup and exit\n"
34 " --log-priority=<level> set the udev log level for the daemon\n"
35 " --stop-exec-queue do not execute events, queue only\n"
36 " --start-exec-queue execute events, flush queue\n"
37 " --reload reload rules and databases\n"
38 " --property=<KEY>=<value> set a global property for all events\n"
39 " --children-max=<N> maximum number of children\n"
40 " --timeout=<seconds> maximum time to block for a reply\n"
41 " --help print this help text\n\n");
44 static int adm_control(struct udev *udev, int argc, char *argv[])
46 struct udev_ctrl *uctrl = NULL;
50 static const struct option options[] = {
51 { "exit", no_argument, NULL, 'e' },
52 { "log-priority", required_argument, NULL, 'l' },
53 { "stop-exec-queue", no_argument, NULL, 's' },
54 { "start-exec-queue", no_argument, NULL, 'S' },
55 { "reload", no_argument, NULL, 'R' },
56 { "reload-rules", no_argument, NULL, 'R' },
57 { "property", required_argument, NULL, 'p' },
58 { "env", required_argument, NULL, 'p' },
59 { "children-max", required_argument, NULL, 'm' },
60 { "timeout", required_argument, NULL, 't' },
61 { "help", no_argument, NULL, 'h' },
66 fprintf(stderr, "root privileges required\n");
70 uctrl = udev_ctrl_new(udev);
77 option = getopt_long(argc, argv, "el:sSRp:m:h", options, NULL);
83 if (udev_ctrl_send_exit(uctrl, timeout) < 0)
91 i = util_log_priority(optarg);
93 fprintf(stderr, "invalid number '%s'\n", optarg);
96 if (udev_ctrl_send_set_log_level(uctrl, util_log_priority(optarg), timeout) < 0)
103 if (udev_ctrl_send_stop_exec_queue(uctrl, timeout) < 0)
109 if (udev_ctrl_send_start_exec_queue(uctrl, timeout) < 0)
115 if (udev_ctrl_send_reload(uctrl, timeout) < 0)
121 if (strchr(optarg, '=') == NULL) {
122 fprintf(stderr, "expect <KEY>=<value> instead of '%s'\n", optarg);
125 if (udev_ctrl_send_set_env(uctrl, optarg, timeout) < 0)
134 i = strtoul(optarg, &endp, 0);
135 if (endp[0] != '\0' || i < 1) {
136 fprintf(stderr, "invalid number '%s'\n", optarg);
139 if (udev_ctrl_send_set_children_max(uctrl, i, timeout) < 0)
148 seconds = atoi(optarg);
152 fprintf(stderr, "invalid timeout value\n");
162 if (argv[optind] != NULL)
163 fprintf(stderr, "unknown option\n");
164 else if (optind == 1)
165 fprintf(stderr, "missing option\n");
167 udev_ctrl_unref(uctrl);
171 const struct udevadm_cmd udevadm_control = {
174 .help = "control the udev daemon",