2 * Copyright (C) 2011 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 #include <sys/inotify.h>
33 #include <sys/types.h>
37 static void help(struct udev
*udev
)
39 fprintf(stderr
, "\n");
40 fprintf(stderr
, "Usage: udevadm builtin [--help] <command> <syspath>\n");
41 udev_builtin_list(udev
);
42 fprintf(stderr
, "\n");
45 static int adm_builtin(struct udev
*udev
, int argc
, char *argv
[])
47 static const struct option options
[] = {
48 { "help", no_argument
, NULL
, 'h' },
53 char filename
[UTIL_PATH_SIZE
];
54 struct udev_device
*dev
= NULL
;
55 enum udev_builtin_cmd cmd
;
56 int rc
= EXIT_SUCCESS
;
58 dbg(udev
, "version %s\n", VERSION
);
63 option
= getopt_long(argc
, argv
, "h", options
, NULL
);
73 command
= argv
[optind
++];
74 if (command
== NULL
) {
75 fprintf(stderr
, "command missing\n");
81 syspath
= argv
[optind
++];
82 if (syspath
== NULL
) {
83 fprintf(stderr
, "syspath missing\n\n");
88 /* add /sys if needed */
89 if (strncmp(syspath
, udev_get_sys_path(udev
), strlen(udev_get_sys_path(udev
))) != 0)
90 util_strscpyl(filename
, sizeof(filename
), udev_get_sys_path(udev
), syspath
, NULL
);
92 util_strscpy(filename
, sizeof(filename
), syspath
);
93 util_remove_trailing_chars(filename
, '/');
95 dev
= udev_device_new_from_syspath(udev
, filename
);
97 fprintf(stderr
, "unable to open device '%s'\n\n", filename
);
102 cmd
= udev_builtin_lookup(command
);
103 if (cmd
>= UDEV_BUILTIN_MAX
) {
104 fprintf(stderr
, "unknown command '%s'\n", command
);
110 if (udev_builtin_run(dev
, cmd
, command
, true) < 0) {
111 fprintf(stderr
, "error executing '%s'\n\n", command
);
115 udev_device_unref(dev
);
119 const struct udevadm_cmd udevadm_test_builtin
= {
120 .name
= "test-builtin",
122 .help
= "test a built-in command",