1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
From: Christian Kastner <ckk@kvr.at>
Date: Thu, 7 Jan 2016 22:19:41 +0100
Subject: Improved debugging options handling
When building cron with debugging support, include the ability to print the
debug options. When building without support, drop the debugging option
from option parsing.
Forwarded: no
Last-Update: 2016-01-07
---
Makefile | 4 +++-
config.h | 1 +
cron.c | 22 ++++++++++++++++++++--
crontab.c | 12 ++++++++++--
4 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
index c8c3bcf..5f74507 100644
--- a/Makefile
+++ b/Makefile
@@ -71,7 +71,9 @@ LINTFLAGS = -hbxa $(INCLUDE) $(COMPAT) $(DEBUGGING)
#<<want to use a nonstandard CC?>>
#CC = vcc
#<<manifest defines>>
-DEFS =
+# Allow override from command line
+DEBUG_DEFS ?= -DDEBUGGING=0
+DEFS = $(DEBUG_DEFS)
#(SGI IRIX systems need this)
#DEFS = -D_BSD_SIGNALS -Dconst=
#<<the name of the BSD-like install program>>
diff --git a/config.h b/config.h
index 3d2b614..b7f4340 100644
--- a/config.h
+++ b/config.h
@@ -29,6 +29,7 @@
*/
#ifndef DEBUGGING
+#error DEBUGGING not defined
#define DEBUGGING 1 /* 1 or 0 -- do you want debugging code built in? */
#endif
diff --git a/cron.c b/cron.c
index 3659a1f..1d93f1b 100644
--- a/cron.c
+++ b/cron.c
@@ -50,7 +50,17 @@ static void usage __P((void)),
static void
usage() {
- fprintf(stderr, "usage: %s [-x debugflag[,...]]\n", ProgramName);
+#if DEBUGGING
+ char **dflags;
+
+ fprintf(stderr, "usage: %s [-x [", ProgramName);
+ for (dflags = DebugFlagNames; *dflags; dflags++) {
+ fprintf(stderr, "%s%s", *dflags, dflags[1] ? "," : "]");
+ }
+ fprintf(stderr, "]\n");
+#else
+ fprintf(stderr, "usage: %s\n", ProgramName);
+#endif
exit(ERROR_EXIT);
}
@@ -318,6 +328,12 @@ sighup_handler(int x) {
}
+#if DEBUGGING
+const char *getoptarg = "x:";
+#else
+const char *getoptarg = "";
+#endif
+
static void
parse_args(argc, argv)
int argc;
@@ -325,14 +341,16 @@ parse_args(argc, argv)
{
int argch;
- while (EOF != (argch = getopt(argc, argv, "x:"))) {
+ while (EOF != (argch = getopt(argc, argv, getoptarg))) {
switch (argch) {
default:
usage();
+#if DEBUGGING
case 'x':
if (!set_debug_flags(optarg))
usage();
break;
+#endif
}
}
}
diff --git a/crontab.c b/crontab.c
index 76c83be..8cfbeb6 100644
--- a/crontab.c
+++ b/crontab.c
@@ -149,7 +149,12 @@ main(argc, argv)
exit(exitstatus);
/*NOTREACHED*/
}
-
+
+#if DEBUGGING
+const char *getoptarg = "u:lerix:";
+#else
+const char *getoptarg = "u:leri";
+#endif
static void
parse_args(argc, argv)
@@ -172,12 +177,15 @@ parse_args(argc, argv)
}
Filename[0] = '\0';
Option = opt_unknown;
- while (EOF != (argch = getopt(argc, argv, "u:lerx:"))) {
+
+ while (EOF != (argch = getopt(argc, argv, getoptarg))) {
switch (argch) {
+#if DEBUGGING
case 'x':
if (!set_debug_flags(optarg))
usage("bad debug option");
break;
+#endif
case 'u':
if (!(pw = getpwnam(optarg)))
{
|