Skip to contentSkip to conversation

Print usage of udevcontrol when no or invalid command is given

PATCH Applied Tobias Klauser 2 participants 2 messages Jul 2, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Print usage of udevcontrol when no or invalid command is given

When not giving any command to udevcontrol it just prints "missing command". This patch changes udevcontrol to also print the usage in such cases (and additionaly in cases where invalid commands are given).

The patch also cleans up the exit paths.

---
 udevcontrol.c |   29 +++++++++++++++++++----------
 1 files changed, 19 insertions(+), 10 deletions(-)
udevcontrol.c +19 -10
index 8add09e..60d21d2 100644
@@ -33,6 +33,9 @@ #include <sys/un.h>
 #include "udev.h"
 #include "udevd.h"
 
+/* prototypes */
+void usage(void);
+
 /* global variables */
 static int sock = -1;
 static int udev_log = 0;
@@ -51,6 +54,16 @@ void log_message (int priority, const ch
 }
 #endif
 
+void usage(void)
+{
+	printf("Usage: udevcontrol COMMAND\n"
+		"  log_priority=<level> set the udev log level for the daemon\n"
+		"  stop_exec_queue      keep udevd from executing events, queue only\n"
+		"  start_exec_queue     execute events, flush queue\n"
+		"  reload_rules         reloads the rules files\n"
+		"  max_childs=<N>       maximum number of childs running at the same time\n"
+		"  --help               print this help text\n\n");
+}
 
 int main(int argc, char *argv[], char *envp[])
 {
@@ -72,6 +85,7 @@ int main(int argc, char *argv[], char *e
 
 	if (argc < 2) {
 		fprintf(stderr, "missing command\n\n");
+		usage();
 		goto exit;
 	}
 
@@ -100,23 +114,18 @@ int main(int argc, char *argv[], char *e
 			*intval = atoi(val);
 			info("send max_childs=%i", *intval);
 		} else if (strcmp(arg, "help") = 0  || strcmp(arg, "--help") = 0  || strcmp(arg, "-h") = 0) {
-			printf("Usage: udevcontrol COMMAND\n"
-				"  log_priority=<level> set the udev log level for the daemon\n"
-				"  stop_exec_queue      keep udevd from executing events, queue only\n"
-				"  start_exec_queue     execute events, flush queue\n"
-				"  reload_rules         reloads the rules files\n"
-				"  max_childs=<N>       maximum number of childs running at the same time\n"
-				"  --help               print this help text\n\n");
-			exit(0);
+			usage();
+			goto exit;
 		} else {
 			fprintf(stderr, "unknown option\n\n");
-			exit(1);
+			usage();
+			goto exit;
 		}
 	}
 
 	if (getuid() != 0) {
 		fprintf(stderr, "need to be root, exit\n\n");
-		exit(1);
+		goto exit;
 	}
 
 	sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
Signature · 11 lines
1.4.0


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Applied
#1 lore raw

Re: [PATCH] Print usage of udevcontrol when no or invalid command

Quoted 3 lines · Tobias Klauser

When not giving any command to udevcontrol it just prints "missing command". This patch changes udevcontrol to also print the usage in such cases (and additionaly in cases where invalid commands are given).

Applied.

Thanks,
Kay

Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel