1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3 * Copyright (C) 2007-2012 Kay Sievers <kay@vrfy.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "selinux-util.h"
25 #include "string-util.h"
28 static int adm_version(struct udev
*udev
, int argc
, char *argv
[]) {
29 printf("%s\n", VERSION
);
33 static const struct udevadm_cmd udevadm_version
= {
38 static int adm_help(struct udev
*udev
, int argc
, char *argv
[]);
40 static const struct udevadm_cmd udevadm_help
= {
45 static const struct udevadm_cmd
*udevadm_cmds
[] = {
53 &udevadm_test_builtin
,
58 static int adm_help(struct udev
*udev
, int argc
, char *argv
[]) {
61 printf("%s [--help] [--version] [--debug] COMMAND [COMMAND OPTIONS]\n\n"
62 "Send control commands or test the device manager.\n\n"
64 , program_invocation_short_name
);
66 for (i
= 0; i
< ELEMENTSOF(udevadm_cmds
); i
++)
67 if (udevadm_cmds
[i
]->help
!= NULL
)
68 printf(" %-12s %s\n", udevadm_cmds
[i
]->name
, udevadm_cmds
[i
]->help
);
72 static int run_command(struct udev
*udev
, const struct udevadm_cmd
*cmd
, int argc
, char *argv
[]) {
74 log_set_max_level(LOG_DEBUG
);
75 log_debug("calling: %s", cmd
->name
);
76 return cmd
->cmd(udev
, argc
, argv
);
79 int main(int argc
, char *argv
[]) {
81 static const struct option options
[] = {
82 { "debug", no_argument
, NULL
, 'd' },
83 { "help", no_argument
, NULL
, 'h' },
84 { "version", no_argument
, NULL
, 'V' },
95 log_parse_environment();
97 mac_selinux_init("/dev");
99 while ((c
= getopt_long(argc
, argv
, "+dhV", options
, NULL
)) >= 0)
103 log_set_max_level(LOG_DEBUG
);
107 rc
= adm_help(udev
, argc
, argv
);
111 rc
= adm_version(udev
, argc
, argv
);
118 command
= argv
[optind
];
121 for (i
= 0; i
< ELEMENTSOF(udevadm_cmds
); i
++)
122 if (streq(udevadm_cmds
[i
]->name
, command
)) {
125 /* we need '0' here to reset the internal state */
127 rc
= run_command(udev
, udevadm_cmds
[i
], argc
, argv
);
131 fprintf(stderr
, "%s: missing or unknown command\n", program_invocation_short_name
);
134 mac_selinux_finish();