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 " --env=<KEY>=<value> set a global environment variable\n"
38 " --max-childs=<N> maximum number of childs\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 { "log_priority", required_argument, NULL, 'l' + 256 },
51 { "stop-exec-queue", no_argument, NULL, 's' },
52 { "stop_exec_queue", no_argument, NULL, 's' + 256 },
53 { "start-exec-queue", no_argument, NULL, 'S' },
54 { "start_exec_queue", no_argument, NULL, 'S' + 256},
55 { "reload-rules", no_argument, NULL, 'R' },
56 { "reload_rules", no_argument, NULL, 'R' + 256},
57 { "env", required_argument, NULL, 'e' },
58 { "max-childs", required_argument, NULL, 'm' },
59 { "max_childs", required_argument, NULL, 'm' + 256},
60 { "help", no_argument, NULL, 'h' },
65 fprintf(stderr, "root privileges required\n");
69 uctrl = udev_ctrl_new_from_socket(udev, UDEV_CTRL_SOCK_PATH);
78 option = getopt_long(argc, argv, "l:sSRe:m:M:h", options, NULL);
83 fprintf(stderr, "udevadm control expects commands without underscore, "
84 "this will stop working in a future release\n");
85 err(udev, "udevadm control expects commands without underscore, "
86 "this will stop working in a future release\n");
92 i = util_log_priority(optarg);
94 fprintf(stderr, "invalid number '%s'\n", optarg);
97 udev_ctrl_send_set_log_level(uctrl, util_log_priority(optarg));
102 udev_ctrl_send_stop_exec_queue(uctrl);
107 udev_ctrl_send_start_exec_queue(uctrl);
112 udev_ctrl_send_reload_rules(uctrl);
116 if (strchr(optarg, '=') == NULL) {
117 fprintf(stderr, "expect <KEY>=<valaue> instead of '%s'\n", optarg);
120 udev_ctrl_send_set_env(uctrl, optarg);
125 i = strtoul(optarg, &endp, 0);
126 if (endp[0] != '\0' || i < 1) {
127 fprintf(stderr, "invalid number '%s'\n", optarg);
130 udev_ctrl_send_set_max_childs(uctrl, i);
142 /* compat stuff which will be removed in a future release */
143 if (argv[optind] != NULL) {
144 const char *arg = argv[optind];
146 fprintf(stderr, "udevadm control commands requires the --<command> format, "
147 "this will stop working in a future release\n");
148 err(udev, "udevadm control commands requires the --<command> format, "
149 "this will stop working in a future release\n");
151 if (!strncmp(arg, "log_priority=", strlen("log_priority="))) {
152 udev_ctrl_send_set_log_level(uctrl, util_log_priority(&arg[strlen("log_priority=")]));
155 } else if (!strcmp(arg, "stop_exec_queue")) {
156 udev_ctrl_send_stop_exec_queue(uctrl);
159 } else if (!strcmp(arg, "start_exec_queue")) {
160 udev_ctrl_send_start_exec_queue(uctrl);
163 } else if (!strcmp(arg, "reload_rules")) {
164 udev_ctrl_send_reload_rules(uctrl);
167 } else if (!strncmp(arg, "max_childs=", strlen("max_childs="))) {
168 udev_ctrl_send_set_max_childs(uctrl, strtoul(&arg[strlen("max_childs=")], NULL, 0));
171 } else if (!strncmp(arg, "env", strlen("env"))) {
172 udev_ctrl_send_set_env(uctrl, &arg[strlen("env=")]);
179 fprintf(stderr, "unrecognized command\n");
180 err(udev, "unrecognized command\n");
183 udev_ctrl_unref(uctrl);