2 * Copyright (C) 2005-2011 Kay Sievers <kay@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.
24 #include "udev-util.h"
26 static void print_help(void) {
27 printf("%s control COMMAND\n\n"
28 "Control the udev daemon.\n\n"
29 " -h --help Show this help\n"
30 " --version Show package version\n"
31 " -e --exit Instruct the daemon to cleanup and exit\n"
32 " -l --log-priority=LEVEL Set the udev log level for the daemon\n"
33 " -s --stop-exec-queue Do not execute events, queue only\n"
34 " -S --start-exec-queue Execute events, flush queue\n"
35 " -R --reload Reload rules and databases\n"
36 " -p --property=KEY=VALUE Set a global property for all events\n"
37 " -m --children-max=N Maximum number of children\n"
38 " --timeout=SECONDS Maximum time to block for a reply\n"
39 , program_invocation_short_name);
42 static int adm_control(struct udev *udev, int argc, char *argv[]) {
43 _cleanup_udev_ctrl_unref_ struct udev_ctrl *uctrl = NULL;
47 static const struct option options[] = {
48 { "exit", no_argument, NULL, 'e' },
49 { "log-priority", required_argument, NULL, 'l' },
50 { "stop-exec-queue", no_argument, NULL, 's' },
51 { "start-exec-queue", no_argument, NULL, 'S' },
52 { "reload", no_argument, NULL, 'R' },
53 { "reload-rules", no_argument, NULL, 'R' }, /* alias for -R */
54 { "property", required_argument, NULL, 'p' },
55 { "env", required_argument, NULL, 'p' }, /* alias for -p */
56 { "children-max", required_argument, NULL, 'm' },
57 { "timeout", required_argument, NULL, 't' },
58 { "help", no_argument, NULL, 'h' },
63 fprintf(stderr, "root privileges required\n");
67 uctrl = udev_ctrl_new(udev);
71 while ((c = getopt_long(argc, argv, "el:sSRp:m:h", options, NULL)) >= 0)
74 if (udev_ctrl_send_exit(uctrl, timeout) < 0)
82 i = util_log_priority(optarg);
84 fprintf(stderr, "invalid number '%s'\n", optarg);
87 if (udev_ctrl_send_set_log_level(uctrl, util_log_priority(optarg), timeout) < 0)
94 if (udev_ctrl_send_stop_exec_queue(uctrl, timeout) < 0)
100 if (udev_ctrl_send_start_exec_queue(uctrl, timeout) < 0)
106 if (udev_ctrl_send_reload(uctrl, timeout) < 0)
112 if (strchr(optarg, '=') == NULL) {
113 fprintf(stderr, "expect <KEY>=<value> instead of '%s'\n", optarg);
116 if (udev_ctrl_send_set_env(uctrl, optarg, timeout) < 0)
125 i = strtoul(optarg, &endp, 0);
126 if (endp[0] != '\0' || i < 1) {
127 fprintf(stderr, "invalid number '%s'\n", optarg);
130 if (udev_ctrl_send_set_children_max(uctrl, i, timeout) < 0)
139 seconds = atoi(optarg);
143 fprintf(stderr, "invalid timeout value\n");
153 fprintf(stderr, "Extraneous argument: %s\n", argv[optind]);
154 else if (optind == 1)
155 fprintf(stderr, "Option missing\n");
159 const struct udevadm_cmd udevadm_control = {
162 .help = "Control the udev daemon",