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 int udevadm_control(struct udev *udev, int argc, char *argv[])
39 struct udev_ctrl *uctrl;
42 /* compat values with '_' will be removed in a future release */
43 static const struct option options[] = {
44 { "log-priority", 1, NULL, 'l' },
45 { "log_priority", 1, NULL, 'l' + 256 },
46 { "stop-exec-queue", 0, NULL, 's' },
47 { "stop_exec_queue", 0, NULL, 's' + 256 },
48 { "start-exec-queue", 0, NULL, 'S' },
49 { "start_exec_queue", 0, NULL, 'S' + 256},
50 { "reload-rules", 0, NULL, 'R' },
51 { "reload_rules", 0, NULL, 'R' + 256},
52 { "env", 1, NULL, 'e' },
53 { "max-childs", 1, NULL, 'm' },
54 { "max_childs", 1, NULL, 'm' + 256},
55 { "max-childs-running", 1, NULL, 'M' },
56 { "max_childs_running", 1, NULL, 'M' + 256},
57 { "help", 0, NULL, 'h' },
62 fprintf(stderr, "root privileges required\n");
66 uctrl = udev_ctrl_new_from_socket(udev, UDEVD_CTRL_SOCK_PATH);
75 option = getopt_long(argc, argv, "l:sSRe:m:M:h", options, NULL);
80 info(udev, "udevadm control expects commands without underscore, "
81 "this will stop working in a future release\n");
82 fprintf(stderr, "udevadm control expects commands without underscore, "
83 "this will stop working in a future release\n");
89 i = log_priority(optarg);
91 fprintf(stderr, "invalid number '%s'\n", optarg);
94 udev_ctrl_set_log_level(uctrl, log_priority(optarg));
98 udev_ctrl_stop_exec_queue(uctrl);
102 udev_ctrl_start_exec_queue(uctrl);
106 udev_ctrl_reload_rules(uctrl);
109 if (strchr(optarg, '=') == NULL) {
110 fprintf(stderr, "expect <KEY>=<valaue> instead of '%s'\n", optarg);
113 udev_ctrl_set_env(uctrl, optarg);
117 i = strtoul(optarg, &endp, 0);
118 if (endp[0] != '\0' || i < 1) {
119 fprintf(stderr, "invalid number '%s'\n", optarg);
122 udev_ctrl_set_max_childs(uctrl, i);
126 i = strtoul(optarg, &endp, 0);
127 if (endp[0] != '\0' || i < 1) {
128 fprintf(stderr, "invalid number '%s'\n", optarg);
131 udev_ctrl_set_max_childs_running(uctrl, i);
134 printf("Usage: udevadm control COMMAND\n"
135 " --log-priority=<level> set the udev log level for the daemon\n"
136 " --stop-exec-queue keep udevd from executing events, queue only\n"
137 " --start-exec-queue execute events, flush queue\n"
138 " --reload-rules reloads the rules files\n"
139 " --env=<KEY>=<value> set a global environment variable\n"
140 " --max-childs=<N> maximum number of childs\n"
141 " --max-childs-running=<N> maximum number of childs running at the same time\n"
142 " --help print this help text\n\n");
149 /* compat stuff which will be removed in a future release */
150 if (argv[optind] != NULL) {
151 const char *arg = argv[optind];
153 fprintf(stderr, "udevadm control commands requires the --<command> format, "
154 "this will stop working in a future release\n");
155 err(udev, "udevadm control commands requires the --<command> format, "
156 "this will stop working in a future release\n");
158 if (!strncmp(arg, "log_priority=", strlen("log_priority="))) {
159 udev_ctrl_set_log_level(uctrl, log_priority(&arg[strlen("log_priority=")]));
160 } else if (!strcmp(arg, "stop_exec_queue")) {
161 udev_ctrl_stop_exec_queue(uctrl);
162 } else if (!strcmp(arg, "start_exec_queue")) {
163 udev_ctrl_start_exec_queue(uctrl);
164 } else if (!strcmp(arg, "reload_rules")) {
165 udev_ctrl_reload_rules(uctrl);
166 } else if (!strncmp(arg, "max_childs=", strlen("max_childs="))) {
167 udev_ctrl_set_max_childs(uctrl, strtoul(&arg[strlen("max_childs=")], NULL, 0));
168 } else if (!strncmp(arg, "max_childs_running=", strlen("max_childs_running="))) {
169 udev_ctrl_set_max_childs_running(uctrl, strtoul(&arg[strlen("max_childs_running=")], NULL, 0));
170 } else if (!strncmp(arg, "env", strlen("env"))) {
171 udev_ctrl_set_env(uctrl, &arg[strlen("env=")]);
173 fprintf(stderr, "unrecognized command '%s'\n", arg);
174 err(udev, "unrecognized command '%s'\n", arg);
178 udev_ctrl_unref(uctrl);