2 * Copyright (C) 2007-2012 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/>.
28 void udev_main_log(struct udev
*udev
, int priority
,
29 const char *file
, int line
, const char *fn
,
30 const char *format
, va_list args
)
32 log_metav(priority
, file
, line
, fn
, format
, args
);
35 static int adm_version(struct udev
*udev
, int argc
, char *argv
[])
37 printf("%s\n", VERSION
);
41 static const struct udevadm_cmd udevadm_version
= {
46 static int adm_help(struct udev
*udev
, int argc
, char *argv
[]);
48 static const struct udevadm_cmd udevadm_help
= {
53 static const struct udevadm_cmd
*udevadm_cmds
[] = {
60 &udevadm_test_builtin
,
65 static int adm_help(struct udev
*udev
, int argc
, char *argv
[])
69 fprintf(stderr
, "Usage: udevadm [--help] [--version] [--debug] COMMAND [COMMAND OPTIONS]\n");
70 for (i
= 0; i
< ELEMENTSOF(udevadm_cmds
); i
++)
71 if (udevadm_cmds
[i
]->help
!= NULL
)
72 printf(" %-12s %s\n", udevadm_cmds
[i
]->name
, udevadm_cmds
[i
]->help
);
73 fprintf(stderr
, "\n");
77 static int run_command(struct udev
*udev
, const struct udevadm_cmd
*cmd
, int argc
, char *argv
[])
80 log_set_max_level(LOG_DEBUG
);
81 log_debug("calling: %s\n", cmd
->name
);
82 return cmd
->cmd(udev
, argc
, argv
);
85 int main(int argc
, char *argv
[])
88 static const struct option options
[] = {
89 { "debug", no_argument
, NULL
, 'd' },
90 { "help", no_argument
, NULL
, 'h' },
91 { "version", no_argument
, NULL
, 'V' },
102 log_parse_environment();
104 udev_set_log_fn(udev
, udev_main_log
);
110 option
= getopt_long(argc
, argv
, "+dhV", options
, NULL
);
116 log_set_max_level(LOG_DEBUG
);
117 udev_set_log_priority(udev
, LOG_DEBUG
);
120 rc
= adm_help(udev
, argc
, argv
);
123 rc
= adm_version(udev
, argc
, argv
);
129 command
= argv
[optind
];
132 for (i
= 0; i
< ELEMENTSOF(udevadm_cmds
); i
++) {
133 if (strcmp(udevadm_cmds
[i
]->name
, command
) == 0) {
137 rc
= run_command(udev
, udevadm_cmds
[i
], argc
, argv
);
142 fprintf(stderr
, "missing or unknown command\n\n");
143 adm_help(udev
, argc
, argv
);