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 void udev_main_log(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);
41 vfprintf(stderr, format, args2);
43 vsyslog(priority, format, args);
47 static int adm_version(struct udev *udev, int argc, char *argv[])
49 printf("%s\n", VERSION);
52 static const struct udevadm_cmd udevadm_version = {
57 static int adm_help(struct udev *udev, int argc, char *argv[]);
58 static const struct udevadm_cmd udevadm_help = {
63 static const struct udevadm_cmd *udevadm_cmds[] = {
70 &udevadm_test_builtin,
75 static int adm_help(struct udev *udev, int argc, char *argv[])
79 fprintf(stderr, "Usage: udevadm [--help] [--version] [--debug] COMMAND [COMMAND OPTIONS]\n");
80 for (i = 0; i < ARRAY_SIZE(udevadm_cmds); i++)
81 if (udevadm_cmds[i]->help != NULL)
82 printf(" %-12s %s\n", udevadm_cmds[i]->name, udevadm_cmds[i]->help);
83 fprintf(stderr, "\n");
87 static int run_command(struct udev *udev, const struct udevadm_cmd *cmd, int argc, char *argv[])
91 if (udev_get_log_priority(udev) < LOG_INFO)
92 udev_set_log_priority(udev, LOG_INFO);
94 info(udev, "calling: %s\n", cmd->name);
95 return cmd->cmd(udev, argc, argv);
98 int main(int argc, char *argv[])
101 static const struct option options[] = {
102 { "debug", no_argument, NULL, 'd' },
103 { "help", no_argument, NULL, 'h' },
104 { "version", no_argument, NULL, 'V' },
115 udev_log_init("udevadm");
116 udev_set_log_fn(udev, udev_main_log);
117 udev_selinux_init(udev);
122 option = getopt_long(argc, argv, "+dhV", options, NULL);
129 if (udev_get_log_priority(udev) < LOG_INFO)
130 udev_set_log_priority(udev, LOG_INFO);
133 rc = adm_help(udev, argc, argv);
136 rc = adm_version(udev, argc, argv);
142 command = argv[optind];
144 info(udev, "runtime dir '%s'\n", udev_get_run_path(udev));
147 for (i = 0; i < ARRAY_SIZE(udevadm_cmds); i++) {
148 if (strcmp(udevadm_cmds[i]->name, command) == 0) {
152 rc = run_command(udev, udevadm_cmds[i], argc, argv);
157 fprintf(stderr, "missing or unknown command\n\n");
158 adm_help(udev, argc, argv);
161 udev_selinux_exit(udev);