2 * Copyright (C) 2005-2006 Kay Sievers <kay.sievers@vrfy.org>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 #include <sys/types.h>
30 #include <sys/socket.h>
36 static void print_help(void)
38 printf("Usage: udevadm control COMMAND\n"
39 " --log-priority=<level> set the udev log level for the daemon\n"
40 " --stop-exec-queue keep udevd from executing events, queue only\n"
41 " --start-exec-queue execute events, flush queue\n"
42 " --reload-rules reloads the rules files\n"
43 " --env=<KEY>=<value> set a global environment variable\n"
44 " --max-childs=<N> maximum number of childs\n"
45 " --help print this help text\n\n");
48 int udevadm_control(struct udev *udev, int argc, char *argv[])
50 struct udev_ctrl *uctrl = NULL;
53 /* compat values with '_' will be removed in a future release */
54 static const struct option options[] = {
55 { "log-priority", 1, NULL, 'l' },
56 { "log_priority", 1, NULL, 'l' + 256 },
57 { "stop-exec-queue", 0, NULL, 's' },
58 { "stop_exec_queue", 0, NULL, 's' + 256 },
59 { "start-exec-queue", 0, NULL, 'S' },
60 { "start_exec_queue", 0, NULL, 'S' + 256},
61 { "reload-rules", 0, NULL, 'R' },
62 { "reload_rules", 0, NULL, 'R' + 256},
63 { "env", 1, NULL, 'e' },
64 { "max-childs", 1, NULL, 'm' },
65 { "max_childs", 1, NULL, 'm' + 256},
66 { "help", 0, NULL, 'h' },
71 fprintf(stderr, "root privileges required\n");
75 uctrl = udev_ctrl_new_from_socket(udev, UDEV_CTRL_SOCK_PATH);
84 option = getopt_long(argc, argv, "l:sSRe:m:M:h", options, NULL);
89 fprintf(stderr, "udevadm control expects commands without underscore, "
90 "this will stop working in a future release\n");
91 err(udev, "udevadm control expects commands without underscore, "
92 "this will stop working in a future release\n");
98 i = log_priority(optarg);
100 fprintf(stderr, "invalid number '%s'\n", optarg);
103 udev_ctrl_send_set_log_level(uctrl, log_priority(optarg));
108 udev_ctrl_send_stop_exec_queue(uctrl);
113 udev_ctrl_send_start_exec_queue(uctrl);
118 udev_ctrl_send_reload_rules(uctrl);
122 if (strchr(optarg, '=') == NULL) {
123 fprintf(stderr, "expect <KEY>=<valaue> instead of '%s'\n", optarg);
126 udev_ctrl_send_set_env(uctrl, optarg);
131 i = strtoul(optarg, &endp, 0);
132 if (endp[0] != '\0' || i < 1) {
133 fprintf(stderr, "invalid number '%s'\n", optarg);
136 udev_ctrl_send_set_max_childs(uctrl, i);
148 /* compat stuff which will be removed in a future release */
149 if (argv[optind] != NULL) {
150 const char *arg = argv[optind];
152 fprintf(stderr, "udevadm control commands requires the --<command> format, "
153 "this will stop working in a future release\n");
154 err(udev, "udevadm control commands requires the --<command> format, "
155 "this will stop working in a future release\n");
157 if (!strncmp(arg, "log_priority=", strlen("log_priority="))) {
158 udev_ctrl_send_set_log_level(uctrl, log_priority(&arg[strlen("log_priority=")]));
161 } else if (!strcmp(arg, "stop_exec_queue")) {
162 udev_ctrl_send_stop_exec_queue(uctrl);
165 } else if (!strcmp(arg, "start_exec_queue")) {
166 udev_ctrl_send_start_exec_queue(uctrl);
169 } else if (!strcmp(arg, "reload_rules")) {
170 udev_ctrl_send_reload_rules(uctrl);
173 } else if (!strncmp(arg, "max_childs=", strlen("max_childs="))) {
174 udev_ctrl_send_set_max_childs(uctrl, strtoul(&arg[strlen("max_childs=")], NULL, 0));
177 } else if (!strncmp(arg, "env", strlen("env"))) {
178 udev_ctrl_send_set_env(uctrl, &arg[strlen("env=")]);
185 fprintf(stderr, "unrecognized command\n");
186 err(udev, "unrecognized command\n");
189 udev_ctrl_unref(uctrl);