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 " --max-childs-running=<N> maximum number of childs running at the same time\n"
46 " --help print this help text\n\n");
49 int udevadm_control(struct udev *udev, int argc, char *argv[])
51 struct udev_ctrl *uctrl = NULL;
54 /* compat values with '_' will be removed in a future release */
55 static const struct option options[] = {
56 { "log-priority", 1, NULL, 'l' },
57 { "log_priority", 1, NULL, 'l' + 256 },
58 { "stop-exec-queue", 0, NULL, 's' },
59 { "stop_exec_queue", 0, NULL, 's' + 256 },
60 { "start-exec-queue", 0, NULL, 'S' },
61 { "start_exec_queue", 0, NULL, 'S' + 256},
62 { "reload-rules", 0, NULL, 'R' },
63 { "reload_rules", 0, NULL, 'R' + 256},
64 { "env", 1, NULL, 'e' },
65 { "max-childs", 1, NULL, 'm' },
66 { "max_childs", 1, NULL, 'm' + 256},
67 { "max-childs-running", 1, NULL, 'M' },
68 { "max_childs_running", 1, NULL, 'M' + 256},
69 { "help", 0, NULL, 'h' },
74 fprintf(stderr, "root privileges required\n");
78 uctrl = udev_ctrl_new_from_socket(udev, UDEV_CTRL_SOCK_PATH);
87 option = getopt_long(argc, argv, "l:sSRe:m:M:h", options, NULL);
92 info(udev, "udevadm control expects commands without underscore, "
93 "this will stop working in a future release\n");
94 fprintf(stderr, "udevadm control expects commands without underscore, "
95 "this will stop working in a future release\n");
101 i = log_priority(optarg);
103 fprintf(stderr, "invalid number '%s'\n", optarg);
106 udev_ctrl_send_set_log_level(uctrl, log_priority(optarg));
111 udev_ctrl_send_stop_exec_queue(uctrl);
116 udev_ctrl_send_start_exec_queue(uctrl);
121 udev_ctrl_send_reload_rules(uctrl);
125 if (strchr(optarg, '=') == NULL) {
126 fprintf(stderr, "expect <KEY>=<valaue> instead of '%s'\n", optarg);
129 udev_ctrl_send_set_env(uctrl, optarg);
134 i = strtoul(optarg, &endp, 0);
135 if (endp[0] != '\0' || i < 1) {
136 fprintf(stderr, "invalid number '%s'\n", optarg);
139 udev_ctrl_send_set_max_childs(uctrl, i);
144 i = strtoul(optarg, &endp, 0);
145 if (endp[0] != '\0' || i < 1) {
146 fprintf(stderr, "invalid number '%s'\n", optarg);
149 udev_ctrl_send_set_max_childs_running(uctrl, i);
161 /* compat stuff which will be removed in a future release */
162 if (argv[optind] != NULL) {
163 const char *arg = argv[optind];
165 fprintf(stderr, "udevadm control commands requires the --<command> format, "
166 "this will stop working in a future release\n");
167 err(udev, "udevadm control commands requires the --<command> format, "
168 "this will stop working in a future release\n");
170 if (!strncmp(arg, "log_priority=", strlen("log_priority="))) {
171 udev_ctrl_send_set_log_level(uctrl, log_priority(&arg[strlen("log_priority=")]));
174 } else if (!strcmp(arg, "stop_exec_queue")) {
175 udev_ctrl_send_stop_exec_queue(uctrl);
178 } else if (!strcmp(arg, "start_exec_queue")) {
179 udev_ctrl_send_start_exec_queue(uctrl);
182 } else if (!strcmp(arg, "reload_rules")) {
183 udev_ctrl_send_reload_rules(uctrl);
186 } else if (!strncmp(arg, "max_childs=", strlen("max_childs="))) {
187 udev_ctrl_send_set_max_childs(uctrl, strtoul(&arg[strlen("max_childs=")], NULL, 0));
190 } else if (!strncmp(arg, "max_childs_running=", strlen("max_childs_running="))) {
191 udev_ctrl_send_set_max_childs_running(uctrl, strtoul(&arg[strlen("max_childs_running=")], NULL, 0));
194 } else if (!strncmp(arg, "env", strlen("env"))) {
195 udev_ctrl_send_set_env(uctrl, &arg[strlen("env=")]);
202 fprintf(stderr, "unrecognized command\n");
203 err(udev, "unrecognized command\n");
206 udev_ctrl_unref(uctrl);