2 * Copyright (C) 2007 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.
34 void log_message(int priority, const char *format, ...)
38 if (priority > udev_log_priority)
41 va_start(args, format);
43 vprintf(format, args);
45 vsyslog(priority, format, args);
52 int (*cmd)(int argc, char *argv[]);
57 static const struct command cmds[];
59 static int version(int argc, char *argv[])
61 printf("%s\n", VERSION);
65 static int help(int argc, char *argv[])
67 const struct command *cmd;
69 printf("Usage: udevadm COMMAND [OPTIONS]\n");
70 for (cmd = cmds; cmd->name != NULL; cmd++)
71 printf(" %-12s %s\n", cmd->name, cmd->help);
76 static const struct command cmds[] = {
80 .help = "query sysfs or the udev database",
85 .help = "request events from the kernel",
89 .cmd = udevsettle, "",
90 .help = "wait for the event queue to finish",
95 .help = "control the udev daemon",
100 .help = "listen to kernel and udev events",
105 .help = "simulation run",
111 .help = "print the version number",
116 .help = "print this help text",
121 int main(int argc, char *argv[])
123 const char *command = argv[1];
130 for (i = 0; cmds[i].cmd != NULL; i++) {
131 if (strcmp(cmds[i].name, command) == 0) {
132 debug = cmds[i].debug;
133 rc = cmds[i].cmd(argc-1, &argv[1]);
138 /* try to find compat link, will be removed in a future release */
140 pos = strrchr(command, '/');
144 /* the trailing part of the binary or link name is the command */
145 if (strncmp(command, "udev", 4) == 0)
146 command = &command[4];
148 for (i = 0; cmds[i].cmd != NULL; i++) {
149 if (strcmp(cmds[i].name, command) == 0) {
154 snprintf(path, sizeof(path), "/proc/%lu/exe", (unsigned long) getppid());
155 len = readlink(path, prog, sizeof(prog));
158 fprintf(stderr, "the program '%s' called '%s', it should use 'udevadm %s <options>', "
159 "this will stop working in a future release\n", prog, argv[0], command);
160 info("the program '%s' called '%s', it should use 'udevadm %s <options>', "
161 "this will stop working in a future release\n", prog, argv[0], command);
163 debug = cmds[i].debug;
164 rc = cmds[i].cmd(argc, argv);
169 fprintf(stderr, "unknown command, try help\n\n");