chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
driverd: implement AddMatch/RemoveMatch logic
[elogind.git]
/
src
/
udev
/
udevadm-trigger.c
diff --git
a/src/udev/udevadm-trigger.c
b/src/udev/udevadm-trigger.c
index d52ae461fec027ec7964cc21b867d41d588432a7..d10ca59cca82333d0142e20be4f565f101510e16 100644
(file)
--- a/
src/udev/udevadm-trigger.c
+++ b/
src/udev/udevadm-trigger.c
@@
-32,6
+32,7
@@
#include <sys/un.h>
#include "udev.h"
#include <sys/un.h>
#include "udev.h"
+#include "util.h"
static int verbose;
static int dry_run;
static int verbose;
static int dry_run;
@@
-48,7
+49,7
@@
static void exec_list(struct udev_enumerate *udev_enumerate, const char *action)
printf("%s\n", udev_list_entry_get_name(entry));
if (dry_run)
continue;
printf("%s\n", udev_list_entry_get_name(entry));
if (dry_run)
continue;
-
util_
strscpyl(filename, sizeof(filename), udev_list_entry_get_name(entry), "/uevent", NULL);
+ strscpyl(filename, sizeof(filename), udev_list_entry_get_name(entry), "/uevent", NULL);
fd = open(filename, O_WRONLY);
if (fd < 0)
continue;
fd = open(filename, O_WRONLY);
if (fd < 0)
continue;
@@
-62,7
+63,7
@@
static const char *keyval(const char *str, const char **val, char *buf, size_t s
{
char *pos;
{
char *pos;
-
util_
strscpy(buf, size,str);
+ strscpy(buf, size,str);
pos = strchr(buf, '=');
if (pos != NULL) {
pos[0] = 0;
pos = strchr(buf, '=');
if (pos != NULL) {
pos[0] = 0;
@@
-111,8
+112,14
@@
static int adm_trigger(struct udev *udev, int argc, char *argv[])
char buf[UTIL_PATH_SIZE];
option = getopt_long(argc, argv, "vng:o:t:hc:p:s:S:a:A:y:b:", options, NULL);
char buf[UTIL_PATH_SIZE];
option = getopt_long(argc, argv, "vng:o:t:hc:p:s:S:a:A:y:b:", options, NULL);
- if (option == -1)
+ if (option == -1) {
+ if (optind < argc) {
+ fprintf(stderr, "Extraneous argument: '%s'\n", argv[optind]);
+ rc = 1;
+ goto exit;
+ }
break;
break;
+ }
switch (option) {
case 'v':
switch (option) {
case 'v':
@@
-122,9
+129,9
@@
static int adm_trigger(struct udev *udev, int argc, char *argv[])
dry_run = 1;
break;
case 't':
dry_run = 1;
break;
case 't':
- if (str
cmp(optarg, "devices") == 0
) {
+ if (str
eq(optarg, "devices")
) {
device_type = TYPE_DEVICES;
device_type = TYPE_DEVICES;
- } else if (str
cmp(optarg, "subsystems") == 0
) {
+ } else if (str
eq(optarg, "subsystems")
) {
device_type = TYPE_SUBSYSTEMS;
} else {
log_error("unknown type --type=%s\n", optarg);
device_type = TYPE_SUBSYSTEMS;
} else {
log_error("unknown type --type=%s\n", optarg);
@@
-133,7
+140,13
@@
static int adm_trigger(struct udev *udev, int argc, char *argv[])
}
break;
case 'c':
}
break;
case 'c':
- action = optarg;
+ if (!nulstr_contains("add\0" "remove\0" "change\0", optarg)) {
+ log_error("unknown action '%s'\n", optarg);
+ rc = 2;
+ goto exit;
+ } else {
+ action = optarg;
+ }
break;
case 's':
udev_enumerate_add_match_subsystem(udev_enumerate, optarg);
break;
case 's':
udev_enumerate_add_match_subsystem(udev_enumerate, optarg);
@@
-165,9
+178,9
@@
static int adm_trigger(struct udev *udev, int argc, char *argv[])
/* add sys dir if needed */
if (!startswith(optarg, "/sys"))
/* add sys dir if needed */
if (!startswith(optarg, "/sys"))
-
util_
strscpyl(path, sizeof(path), "/sys", optarg, NULL);
+ strscpyl(path, sizeof(path), "/sys", optarg, NULL);
else
else
-
util_
strscpy(path, sizeof(path), optarg);
+ strscpy(path, sizeof(path), optarg);
util_remove_trailing_chars(path, '/');
dev = udev_device_new_from_syspath(udev, path);
if (dev == NULL) {
util_remove_trailing_chars(path, '/');
dev = udev_device_new_from_syspath(udev, path);
if (dev == NULL) {
@@
-214,7
+227,7
@@
static int adm_trigger(struct udev *udev, int argc, char *argv[])
exec_list(udev_enumerate, action);
goto exit;
default:
exec_list(udev_enumerate, action);
goto exit;
default:
-
goto exit
;
+
assert_not_reached("device_type")
;
}
exit:
udev_enumerate_unref(udev_enumerate);
}
exit:
udev_enumerate_unref(udev_enumerate);