[systemd-devel] [PATCH 2/2] add parameters checking for 'udevadm trigger'
Yang Zhiyong
yangzy.fnst at cn.fujitsu.com
Sun Nov 3 03:50:58 PST 2013
This patch adds parameters checking for 'udevadm trigger'.
---
src/udev/udevadm-trigger.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c
index f472996..ee6a4a0 100644
--- a/src/udev/udevadm-trigger.c
+++ b/src/udev/udevadm-trigger.c
@@ -32,6 +32,7 @@
#include <sys/un.h>
#include "udev.h"
+#include "util.h"
static int verbose;
static int dry_run;
@@ -95,9 +96,12 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[])
TYPE_SUBSYSTEMS,
} device_type = TYPE_DEVICES;
const char *action = "change";
+ static const char action_table[] =
+ "add\0"
+ "remove\0"
+ "change\0";
struct udev_enumerate *udev_enumerate;
int rc = 0;
-
udev_enumerate = udev_enumerate_new(udev);
if (udev_enumerate == NULL) {
rc = 1;
@@ -111,8 +115,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);
- if (option == -1)
+ if (option == -1) {
+ if (optind < argc) {
+ fprintf(stderr, "Extraneous argument: '%s'\n",argv[optind]);
+ rc = 1;
+ goto exit;
+ }
break;
+ }
switch (option) {
case 'v':
@@ -133,7 +143,13 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[])
}
break;
case 'c':
- action = optarg;
+ if (!nulstr_contains(action_table,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);
--
1.8.1
More information about the systemd-devel
mailing list