1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (C) 2005-2011 Kay Sievers <kay@vrfy.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
24 #include "process-util.h"
25 #include "time-util.h"
26 #include "udev-util.h"
28 #include "udevadm-util.h"
30 static void print_help(void) {
31 printf("%s control OPTION\n\n"
32 "Control the udev daemon.\n\n"
33 " -h --help Show this help\n"
34 " -V --version Show package version\n"
35 " -e --exit Instruct the daemon to cleanup and exit\n"
36 " -l --log-priority=LEVEL Set the udev log level for the daemon\n"
37 " -s --stop-exec-queue Do not execute events, queue only\n"
38 " -S --start-exec-queue Execute events, flush queue\n"
39 " -R --reload Reload rules and databases\n"
40 " -p --property=KEY=VALUE Set a global property for all events\n"
41 " -m --children-max=N Maximum number of children\n"
42 " -t --timeout=SECONDS Maximum time to block for a reply\n"
43 , program_invocation_short_name
);
46 static int adm_control(struct udev
*udev
, int argc
, char *argv
[]) {
47 _cleanup_(udev_ctrl_unrefp
) struct udev_ctrl
*uctrl
= NULL
;
51 static const struct option options
[] = {
52 { "exit", no_argument
, NULL
, 'e' },
53 { "log-priority", required_argument
, NULL
, 'l' },
54 { "stop-exec-queue", no_argument
, NULL
, 's' },
55 { "start-exec-queue", no_argument
, NULL
, 'S' },
56 { "reload", no_argument
, NULL
, 'R' },
57 { "reload-rules", no_argument
, NULL
, 'R' }, /* alias for -R */
58 { "property", required_argument
, NULL
, 'p' },
59 { "env", required_argument
, NULL
, 'p' }, /* alias for -p */
60 { "children-max", required_argument
, NULL
, 'm' },
61 { "timeout", required_argument
, NULL
, 't' },
62 { "version", no_argument
, NULL
, 'V' },
63 { "help", no_argument
, NULL
, 'h' },
67 if (must_be_root() < 0)
70 uctrl
= udev_ctrl_new(udev
);
74 while ((c
= getopt_long(argc
, argv
, "el:sSRp:m:t:Vh", options
, NULL
)) >= 0)
77 if (udev_ctrl_send_exit(uctrl
, timeout
) < 0)
85 i
= util_log_priority(optarg
);
87 log_error("invalid number '%s'", optarg
);
90 if (udev_ctrl_send_set_log_level(uctrl
, util_log_priority(optarg
), timeout
) < 0)
97 if (udev_ctrl_send_stop_exec_queue(uctrl
, timeout
) < 0)
103 if (udev_ctrl_send_start_exec_queue(uctrl
, timeout
) < 0)
109 if (udev_ctrl_send_reload(uctrl
, timeout
) < 0)
115 if (strchr(optarg
, '=') == NULL
) {
116 log_error("expect <KEY>=<value> instead of '%s'", optarg
);
119 if (udev_ctrl_send_set_env(uctrl
, optarg
, timeout
) < 0)
128 i
= strtoul(optarg
, &endp
, 0);
129 if (endp
[0] != '\0' || i
< 1) {
130 log_error("invalid number '%s'", optarg
);
133 if (udev_ctrl_send_set_children_max(uctrl
, i
, timeout
) < 0)
143 r
= parse_sec(optarg
, &s
);
145 return log_error_errno(r
, "Failed to parse timeout value '%s'.", optarg
);
147 if (DIV_ROUND_UP(s
, USEC_PER_SEC
) > INT_MAX
)
148 log_error("Timeout value is out of range.");
150 seconds
= s
!= USEC_INFINITY
? (int) DIV_ROUND_UP(s
, USEC_PER_SEC
) : INT_MAX
;
167 log_error("Extraneous argument: %s", argv
[optind
]);
168 else if (optind
== 1)
169 log_error("Option missing");
173 const struct udevadm_cmd udevadm_control
= {
176 .help
= "Control the udev daemon",