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.
32 void log_message(int priority, const char *format, ...)
36 if (priority > udev_log_priority)
39 va_start(args, format);
41 vprintf(format, args);
44 vsyslog(priority, format, args);
51 int (*cmd)(int argc, char *argv[], char *envp[]);
56 static const struct command cmds[];
58 static int version(int argc, char *argv[], char *envp[])
60 printf("%s\n", UDEV_VERSION);
64 static int help(int argc, char *argv[], char *envp[])
66 const struct command *cmd;
68 printf("Usage: udevadm COMMAND [OPTIONS]\n");
69 for (cmd = cmds; cmd->name != NULL; cmd++)
70 printf(" %-12s %s\n", cmd->name, cmd->help);
75 static const struct command cmds[] = {
79 .help = "query sysfs or the udev database",
84 .help = "request events from the kernel",
88 .cmd = udevsettle, "",
89 .help = "wait for the event queue to finish",
94 .help = "control the udev daemon",
99 .help = "listen to kernel and udev events",
104 .help = "simulation run",
110 .help = "print the version number",
115 .help = "print this help text",
120 int main(int argc, char *argv[], char *envp[])
124 const struct command *cmd;
127 /* get binary or symlink name */
128 pos = strrchr(argv[0], '/');
134 /* the trailing part of the binary or symlink name is the command */
135 if (strncmp(command, "udev", 4) == 0)
136 command = &command[4];
138 if (command == NULL || command[0] == '\0')
141 /* udevadm itself needs to strip its name from the passed options */
142 if (strcmp(command, "adm") == 0) {
151 /* allow command to be specified as an option */
152 if (strncmp(command, "--", 2) == 0)
155 /* find and execute command */
156 for (cmd = cmds; cmd->name != NULL; cmd++) {
157 if (strcmp(cmd->name, command) == 0) {
158 verbose = cmd->verbose;
159 rc = cmd->cmd(argc, argv, envp);
165 fprintf(stderr, "unknown command, try help\n\n");