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>
37 static int udev_log = 0;
39 int udevadm_control(int argc, char *argv[])
41 struct udev_ctrl *uctrl;
45 /* compat values with '_' will be removed in a future release */
46 static const struct option options[] = {
47 { "log-priority", 1, NULL, 'l' },
48 { "log_priority", 1, NULL, 'l' + 256 },
49 { "stop-exec-queue", 0, NULL, 's' },
50 { "stop_exec_queue", 0, NULL, 's' + 256 },
51 { "start-exec-queue", 0, NULL, 'S' },
52 { "start_exec_queue", 0, NULL, 'S' + 256},
53 { "reload-rules", 0, NULL, 'R' },
54 { "reload_rules", 0, NULL, 'R' + 256},
55 { "env", 1, NULL, 'e' },
56 { "max-childs", 1, NULL, 'm' },
57 { "max_childs", 1, NULL, 'm' + 256},
58 { "max-childs-running", 1, NULL, 'M' },
59 { "max_childs_running", 1, NULL, 'M' + 256},
60 { "help", 0, NULL, 'h' },
64 env = getenv("UDEV_LOG");
66 udev_log = log_priority(env);
68 logging_init("udevcontrol");
69 dbg("version %s\n", VERSION);
72 fprintf(stderr, "root privileges required\n");
76 uctrl = udev_ctrl_new_from_socket(UDEVD_CTRL_SOCK_PATH);
85 option = getopt_long(argc, argv, "l:sSRe:m:M:h", options, NULL);
90 info("udevadm control expects commands without underscore, "
91 "this will stop working in a future release\n");
92 fprintf(stderr, "udevadm control expects commands without underscore, "
93 "this will stop working in a future release\n");
99 i = log_priority(optarg);
101 fprintf(stderr, "invalid number '%s'\n", optarg);
104 udev_ctrl_set_log_level(uctrl, log_priority(optarg));
108 udev_ctrl_stop_exec_queue(uctrl);
112 udev_ctrl_start_exec_queue(uctrl);
116 udev_ctrl_reload_rules(uctrl);
119 if (strchr(optarg, '=') == NULL) {
120 fprintf(stderr, "expect <KEY>=<valaue> instead of '%s'\n", optarg);
123 udev_ctrl_set_env(uctrl, optarg);
127 i = strtoul(optarg, &endp, 0);
128 if (endp[0] != '\0' || i < 1) {
129 fprintf(stderr, "invalid number '%s'\n", optarg);
132 udev_ctrl_set_max_childs(uctrl, i);
136 i = strtoul(optarg, &endp, 0);
137 if (endp[0] != '\0' || i < 1) {
138 fprintf(stderr, "invalid number '%s'\n", optarg);
141 udev_ctrl_set_max_childs_running(uctrl, i);
145 printf("Usage: udevadm control COMMAND\n"
146 " --log-priority=<level> set the udev log level for the daemon\n"
147 " --stop-exec-queue keep udevd from executing events, queue only\n"
148 " --start-exec-queue execute events, flush queue\n"
149 " --reload-rules reloads the rules files\n"
150 " --env=<KEY>=<value> set a global environment variable\n"
151 " --max-childs=<N> maximum number of childs\n"
152 " --max-childs-running=<N> maximum number of childs running at the same time\n"
153 " --help print this help text\n\n");
160 /* compat stuff which will be removed in a future release */
161 if (argv[optind] != NULL) {
162 const char *arg = argv[optind];
164 fprintf(stderr, "udevadm control commands requires the --<command> format, "
165 "this will stop working in a future release\n");
166 err("udevadm control commands requires the --<command> format, "
167 "this will stop working in a future release\n");
169 if (!strncmp(arg, "log_priority=", strlen("log_priority="))) {
170 udev_ctrl_set_log_level(uctrl, log_priority(&arg[strlen("log_priority=")]));
171 } else if (!strcmp(arg, "stop_exec_queue")) {
172 udev_ctrl_stop_exec_queue(uctrl);
173 } else if (!strcmp(arg, "start_exec_queue")) {
174 udev_ctrl_start_exec_queue(uctrl);
175 } else if (!strcmp(arg, "reload_rules")) {
176 udev_ctrl_reload_rules(uctrl);
177 } else if (!strncmp(arg, "max_childs=", strlen("max_childs="))) {
178 udev_ctrl_set_max_childs(uctrl, strtoul(&arg[strlen("max_childs=")], NULL, 0));
179 } else if (!strncmp(arg, "max_childs_running=", strlen("max_childs_running="))) {
180 udev_ctrl_set_max_childs_running(uctrl, strtoul(&arg[strlen("max_childs_running=")], NULL, 0));
181 } else if (!strncmp(arg, "env", strlen("env"))) {
182 udev_ctrl_set_env(uctrl, &arg[strlen("env=")]);
184 fprintf(stderr, "unrecognized command '%s'\n", arg);
185 err("unrecognized command '%s'\n", arg);
189 udev_ctrl_unref(uctrl);