2 * Copyright (C) 2005-2008 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 " --log-priority=<level> set the udev log level for the daemon\n"
34 " --stop-exec-queue keep udevd from executing events, queue only\n"
35 " --start-exec-queue execute events, flush queue\n"
36 " --reload-rules reloads the rules files\n"
37 " --property=<KEY>=<value> set a global property for all events\n"
38 " --children-max=<N> maximum number of children\n"
39 " --help print this help text\n\n");
42 int udevadm_control(struct udev *udev, int argc, char *argv[])
44 struct udev_ctrl *uctrl = NULL;
47 /* compat values with '_' will be removed in a future release */
48 static const struct option options[] = {
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-rules", no_argument, NULL, 'R' },
53 { "property", required_argument, NULL, 'p' },
54 { "env", required_argument, NULL, 'p' },
55 { "children-max", required_argument, NULL, 'm' },
56 { "help", no_argument, NULL, 'h' },
61 fprintf(stderr, "root privileges required\n");
65 uctrl = udev_ctrl_new_from_socket(udev, UDEV_CTRL_SOCK_PATH);
74 option = getopt_long(argc, argv, "l:sSRp:m:h", options, NULL);
80 i = util_log_priority(optarg);
82 fprintf(stderr, "invalid number '%s'\n", optarg);
85 if (udev_ctrl_send_set_log_level(uctrl, util_log_priority(optarg)) < 0)
91 if (udev_ctrl_send_stop_exec_queue(uctrl) < 0)
97 if (udev_ctrl_send_start_exec_queue(uctrl) < 0)
103 if (udev_ctrl_send_reload_rules(uctrl) < 0)
109 if (strchr(optarg, '=') == NULL) {
110 fprintf(stderr, "expect <KEY>=<value> instead of '%s'\n", optarg);
113 if (udev_ctrl_send_set_env(uctrl, optarg) < 0)
119 i = strtoul(optarg, &endp, 0);
120 if (endp[0] != '\0' || i < 1) {
121 fprintf(stderr, "invalid number '%s'\n", optarg);
124 if (udev_ctrl_send_set_children_max(uctrl, i) < 0)
137 err(udev, "unrecognized command\n");
139 udev_ctrl_unref(uctrl);