From: Christian Kastner <ckk@kvr.at>
Date: Thu, 07 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
Index: cron/config.h
===================================================================
--- cron.orig/config.h
+++ cron/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
 
Index: cron/cron.c
===================================================================
--- cron.orig/cron.c
+++ cron/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
 		}
 	}
 }
Index: cron/crontab.c
===================================================================
--- cron.orig/crontab.c
+++ cron/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)))
 			{
Index: cron/Makefile
===================================================================
--- cron.orig/Makefile
+++ cron/Makefile
@@ -71,7 +71,9 @@ LINTFLAGS	=	-hbxa $(INCLUDE) $(COMPAT) $
 #<<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>>
