2 * Copyright (C) 2007-2009 Kay Sievers <kay.sievers@vrfy.org>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 static void log_fn(struct udev *udev, int priority,
31 const char *file, int line, const char *fn,
32 const char *format, va_list args)
35 fprintf(stderr, "%s: ", fn);
36 vfprintf(stderr, format, args);
38 vsyslog(priority, format, args);
44 int (*cmd)(struct udev *udev, int argc, char *argv[]);
49 static const struct command cmds[];
51 static int version(struct udev *udev, int argc, char *argv[])
53 printf("%s\n", VERSION);
57 static int help(struct udev *udev, int argc, char *argv[])
59 const struct command *cmd;
61 printf("Usage: udevadm [--help] [--version] [--debug] COMMAND [COMMAND OPTIONS]\n");
62 for (cmd = cmds; cmd->name != NULL; cmd++)
63 if (cmd->help != NULL)
64 printf(" %-12s %s\n", cmd->name, cmd->help);
69 static const struct command cmds[] = {
73 .help = "query sysfs or the udev database",
77 .cmd = udevadm_trigger,
78 .help = "request events from the kernel",
82 .cmd = udevadm_settle,
83 .help = "wait for the event queue to finish",
87 .cmd = udevadm_control,
88 .help = "control the udev daemon",
92 .cmd = udevadm_monitor,
93 .help = "listen to kernel and udev events",
98 .help = "simulation run",
112 static int run_command(struct udev *udev, const struct command *cmd, int argc, char *argv[])
116 if (udev_get_log_priority(udev) < LOG_INFO)
117 udev_set_log_priority(udev, LOG_INFO);
119 info(udev, "calling: %s\n", cmd->name);
120 return cmd->cmd(udev, argc, argv);
123 int main(int argc, char *argv[])
126 static const struct option options[] = {
127 { "debug", no_argument, NULL, 'd' },
128 { "help", no_argument, NULL, 'h' },
129 { "version", no_argument, NULL, 'V' },
140 udev_log_init("udevadm");
141 udev_set_log_fn(udev, log_fn);
142 udev_selinux_init(udev);
147 option = getopt_long(argc, argv, "+dhV", options, NULL);
154 if (udev_get_log_priority(udev) < LOG_INFO)
155 udev_set_log_priority(udev, LOG_INFO);
158 rc = help(udev, argc, argv);
161 rc = version(udev, argc, argv);
167 command = argv[optind];
170 for (i = 0; cmds[i].cmd != NULL; i++) {
171 if (strcmp(cmds[i].name, command) == 0) {
175 rc = run_command(udev, &cmds[i], argc, argv);
180 fprintf(stderr, "missing or unknown command\n\n");
181 help(udev, argc, argv);
184 udev_selinux_exit(udev);