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 static const struct option options[] = {
48 { "log-priority", required_argument, NULL, 'l' },
49 { "stop-exec-queue", no_argument, NULL, 's' },
50 { "start-exec-queue", no_argument, NULL, 'S' },
51 { "reload-rules", no_argument, NULL, 'R' },
52 { "property", required_argument, NULL, 'p' },
53 { "env", required_argument, NULL, 'p' },
54 { "children-max", required_argument, NULL, 'm' },
55 { "help", no_argument, NULL, 'h' },
60 fprintf(stderr, "root privileges required\n");
64 uctrl = udev_ctrl_new_from_socket(udev, UDEV_CTRL_SOCK_PATH);
73 option = getopt_long(argc, argv, "l:sSRp:m:h", options, NULL);
79 i = util_log_priority(optarg);
81 fprintf(stderr, "invalid number '%s'\n", optarg);
84 if (udev_ctrl_send_set_log_level(uctrl, util_log_priority(optarg)) < 0)
90 if (udev_ctrl_send_stop_exec_queue(uctrl) < 0)
96 if (udev_ctrl_send_start_exec_queue(uctrl) < 0)
102 if (udev_ctrl_send_reload_rules(uctrl) < 0)
108 if (strchr(optarg, '=') == NULL) {
109 fprintf(stderr, "expect <KEY>=<value> instead of '%s'\n", optarg);
112 if (udev_ctrl_send_set_env(uctrl, optarg) < 0)
118 i = strtoul(optarg, &endp, 0);
119 if (endp[0] != '\0' || i < 1) {
120 fprintf(stderr, "invalid number '%s'\n", optarg);
123 if (udev_ctrl_send_set_children_max(uctrl, i) < 0)
136 err(udev, "unrecognized command\n");
138 udev_ctrl_unref(uctrl);