From b52a01ee39dad3b04aaa7e3af7435f062d3e887f Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Fri, 8 Sep 2006 11:27:03 +0200 Subject: [PATCH] udevd: use getopt_long() --- udevd.8 | 5 ++++- udevd.c | 27 +++++++++++++++++++-------- udevd.xml | 7 +++++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/udevd.8 b/udevd.8 index a57ff7aab..bb6d27fb4 100644 --- a/udevd.8 +++ b/udevd.8 @@ -14,7 +14,7 @@ udevd \- event managing daemon .SH "SYNOPSIS" .HP 6 -\fBudevd\fR [\fB\-\-daemon\fR] +\fBudevd\fR [\fB\-\-daemon\fR] [\fB\-\-help\fR] .HP 20 \fBudevcontrol \fR\fB\fIcommand\fR\fR .SH "DESCRIPTION" @@ -25,6 +25,9 @@ udevd listens to kernel uevents and passes the incoming events to udev. It ensur \fB\-\-daemon\fR Detach and run in the background. .TP 3n +\fB\-\-help\fR +Print usage. +.TP 3n \fBlog_priority=\fR\fB\fIvalue\fR\fR udevcontrol can dynamically set the log level of udevd. Valid values are the numerical syslog priorities or their textual representations: \fBerr\fR, diff --git a/udevd.c b/udevd.c index a21d2ab77..df6e22281 100644 --- a/udevd.c +++ b/udevd.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -76,6 +77,7 @@ void log_message(int priority, const char *format, ...) vsyslog(priority, format, args); va_end(args); } + #endif static void asmlinkage udev_event_sig_handler(int signum) @@ -916,7 +918,12 @@ int main(int argc, char *argv[], char *envp[]) fd_set readfds; const char *value; int daemonize = 0; - int i; + int option; + static const struct option options[] = { + { "daemon", 0, NULL, 'd' }, + { "help", 0, NULL, 'h' }, + {} + }; int rc = 1; int maxfd; @@ -926,16 +933,20 @@ int main(int argc, char *argv[], char *envp[]) dbg("version %s", UDEV_VERSION); /* parse commandline options */ - for (i = 1 ; i < argc; i++) { - char *arg = argv[i]; - if (strcmp(arg, "--daemon") == 0 || strcmp(arg, "-d") == 0) + while (1) { + option = getopt_long(argc, argv, "dtvh", options, NULL); + if (option == -1) + break; + + switch (option) { + case 'd': daemonize = 1; - else if (strcmp(arg, "--help") == 0 || strcmp(arg, "-h") == 0) { + break; + case 'h': printf("Usage: udevd [--help] [--daemon]\n"); goto exit; - } else { - fprintf(stderr, "unrecognized option '%s'\n", arg); - err("unrecognized option '%s'\n", arg); + default: + goto exit; } } diff --git a/udevd.xml b/udevd.xml index 7feede277..f0682ed00 100644 --- a/udevd.xml +++ b/udevd.xml @@ -26,6 +26,7 @@ udevd + udevcontrol command @@ -46,6 +47,12 @@ Detach and run in the background. + + + + Print usage. + + -- 2.30.2