From ac859449601feae67c5d7c463befc8983f782f3a Mon Sep 17 00:00:00 2001 From: Antonio Huete Jimenez Date: Tue, 17 Aug 2010 18:41:25 +0200 Subject: [PATCH] udevd - Add an option to not daemonize udevd. --- sbin/udevd/udevd.8 | 11 ++++++++++- sbin/udevd/udevd.c | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/sbin/udevd/udevd.8 b/sbin/udevd/udevd.8 index 6d750e661e..78fd364dd7 100644 --- a/sbin/udevd/udevd.8 +++ b/sbin/udevd/udevd.8 @@ -50,6 +50,15 @@ daemon has to be running for the .Xr devattr 3 library to work. .Pp +The options are as follows: +.Bl -tag -width Fl +.It Fl d +Debug option. +Causes +.Nm +to not go to the background. +.El +.Pp The .Nm utility creates the file @@ -59,4 +68,4 @@ This can be used to kill .Nm . .Sh SEE ALSO .Xr devattr 3 , -.Xr rc.conf 5 \ No newline at end of file +.Xr rc.conf 5 diff --git a/sbin/udevd/udevd.c b/sbin/udevd/udevd.c index 84fc9d99b8..ce6d1beba1 100644 --- a/sbin/udevd/udevd.c +++ b/sbin/udevd/udevd.c @@ -59,18 +59,30 @@ #include #include "udevd.h" +int debugopt = 0; + static int udevfd; extern pthread_mutex_t monitor_lock; extern TAILQ_HEAD(udev_monitor_list_head, udev_monitor) udev_monitor_list; extern TAILQ_HEAD(pdev_array_list_head, pdev_array_entry) pdev_array_list; +static void usage(void); + int match_dev_dict(prop_dictionary_t, prop_dictionary_t); prop_dictionary_t find_dev_dict(int64_t, prop_dictionary_t, int *); void udev_read_event(int); prop_array_t udev_getdevs(int); +static +void +usage(void) +{ + fprintf(stderr, "usage: udevd [-d]\n"); + exit(1); +} + int match_dev_dict(prop_dictionary_t dict, prop_dictionary_t match_dict) { @@ -320,14 +332,28 @@ set_killed_signal(void) act.sa_flags = 0; ret = sigaction(SIGTERM, &act, NULL); - return ret; + return ret; } -int main(int argc __unused, char *argv[] __unused) +int main(int argc, char *argv[]) { int error __unused, i, r, s; struct pollfd fds[NFDS]; FILE *pidf; + int ch = 0; + + while ((ch = getopt(argc, argv, "d")) != -1) { + switch(ch) { + case 'd': + debugopt = 1; + break; + default: + usage(); + /* NOT REACHED */ + } + } + argc -= optind; + argv -= optind; TAILQ_INIT(&pdev_array_list); TAILQ_INIT(&udev_monitor_list); @@ -354,8 +380,9 @@ int main(int argc __unused, char *argv[] __unused) set_killed_signal(); - if (daemon(0, 0) == -1) - err(1, "daemon"); + if (debugopt == 0) + if (daemon(0, 0) == -1) + err(1, "daemon"); fprintf(pidf, "%ld\n", (long)getpid()); fclose(pidf); -- 2.41.0