commit 478bd990e6485d4e6995201bead84ebfcdf01461
parent 45dea6be7bad008421ab4025186cef82f3b780b3
Author: Christoph Lohmann <20h@r-36.net>
Date: Sun, 27 Jan 2013 16:38:14 +0100
Adding a better arg.h and making daemonize the default.
Diffstat:
3 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/arg.h b/arg.h
@@ -8,20 +8,23 @@
extern char *argv0;
-#define USED(x) ((void)(x))
+#define USED(x) ((void)(x))
+/* use main(int argc, char *argv[]) */
#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
argv[0] && argv[0][1]\
&& argv[0][0] == '-';\
argc--, argv++) {\
char _argc;\
char **_argv;\
+ int brk;\
if (argv[0][1] == '-' && argv[0][2] == '\0') {\
argv++;\
argc--;\
break;\
}\
- for (argv[0]++, _argv = argv; argv[0][0];\
+ for (brk = 0, argv[0]++, _argv = argv;\
+ argv[0][0] && !brk;\
argv[0]++) {\
if (_argv != argv)\
break;\
@@ -34,8 +37,19 @@ extern char *argv0;
USED(argv);\
USED(argc);
-#define EARGF(x) ((argv[1] == NULL)? ((x), abort(), (char *)0) :\
- (argc--, argv++, argv[0]))
+#define ARGC() _argc
+
+#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
+ ((x), abort(), (char *)0) :\
+ (brk = 1, (argv[0][1] != '\0')?\
+ (&argv[0][1]) :\
+ (argc--, argv++, argv[0])))
+
+#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
+ (char *)0 :\
+ (brk = 1, (argv[0][1] != '\0')?\
+ (&argv[0][1]) :\
+ (argc--, argv++, argv[0])))
#endif
diff --git a/rfkilld.8 b/rfkilld.8
@@ -10,8 +10,8 @@
.Nm
.Bk -words
.Op Fl h
-.Op Fl b
.Op Fl d
+.Op Fl f
.Op Fl l
.Op Fl e Ar etcdir
.Ek
@@ -33,9 +33,6 @@ options and default settings.
.Pp
.Bl -tag -width ".Fl string"
.
-.It Fl b
-Run in background.
-.
.It Fl d
Turn on debug messages. This will not work in conjunction with
-b.
@@ -44,6 +41,9 @@ Turn on debug messages. This will not work in conjunction with
This flag specifies the etcdir, where to run scripts in.
(default: /etc/rfkilld)
.
+.It Fl f
+Run in foreground.
+.
.It Fl h
Show usage.
.
diff --git a/rfkilld.c b/rfkilld.c
@@ -175,7 +175,7 @@ initsignals(void)
void
usage(void)
{
- die("usage: %s [-hbdl] [-e etcdir]\n", argv0);
+ die("usage: %s [-hfdl] [-e etcdir]\n", argv0);
}
int
@@ -191,13 +191,13 @@ main(int argc, char *argv[])
struct pollfd fds;
int i, len, slen, dodaemonize;
- dodaemonize = 0;
+ dodaemonize = 1;
memset(lastname, 0, sizeof(lastname));
memset(lasttype, 0, sizeof(lasttype));
ARGBEGIN {
- case 'b':
- dodaemonize = 1;
+ case 'f':
+ dodaemonize = 0;
break;
case 'd':
printf("dodebug = 1\n");