Subject: bin/21705: crontab -l should suppress stupid headers the way crontab -e does
To: None <gnats-bugs@gnats.netbsd.org>
From: None <kalt@taranis.org>
List: netbsd-bugs
Date: 05/28/2003 15:12:33
>Number:         21705
>Category:       bin
>Synopsis:       crontab -l should suppress stupid headers the way crontab -e does
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed May 28 19:13:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Christophe Kalt
>Release:        NetBSD 1.6.1_STABLE
>Organization:
	
>Environment:
System: NetBSD bzz.taranis.org 1.6.1_STABLE NetBSD 1.6.1_STABLE (bzz) #11: Wed Apr 23 13:22:30 EDT 2003 kalt@bzz.taranis.org:/scratch/NetBSD/1.6.x/obj/scratch/NetBSD/1.6.x/src/sys/arch/sparc/compile/bzz sparc
Architecture: sparc
Machine: sparc
>Description:
By not suppressing the headers it automatically adds, "crontab -l" forces
tools that want to automatically update the crontab to know about these
headers to avoid a growing crontab.
>How-To-Repeat:
$ crontab -l | wc -l
      11
$ crontab -l  > /tmp/test
$ crontab /tmp/test
$ crontab -l | wc -l
      14
>Fix:
Index: crontab.c
===================================================================
RCS file: /pub/NetBSD-CVS/src/usr.sbin/cron/crontab.c,v
retrieving revision 1.15
diff -u -r1.15 crontab.c
--- crontab.c	1999/05/29 18:43:40	1.15
+++ crontab.c	2003/05/28 19:11:09
@@ -264,7 +264,7 @@
 list_cmd() {
 	char	n[MAX_FNAME];
 	FILE	*f;
-	int	ch;
+	int	x, ch;
 
 	log_it(RealUser, Pid, "LIST", User);
 	(void) snprintf(n, sizeof(n), CRON_TAB(User));
@@ -279,6 +279,24 @@
 	/* file is open. copy to stdout, close.
 	 */
 	Set_LineNum(1)
+
+	/* ignore the top few comments since we probably put them there.
+	 */
+	for (x = 0;  x < NHEADER_LINES;  x++) {
+		ch = get_char(f);
+		if (EOF == ch)
+			break;
+		if ('#' != ch) {
+			putc(ch, NewCrontab);
+			break;
+		}
+		while (EOF != (ch = get_char(f)))
+			if (ch == '\n')
+				break;
+		if (EOF == ch)
+			break;
+	}
+
 	while (EOF != (ch = get_char(f)))
 		putchar(ch);
 	fclose(f);
>Release-Note:
>Audit-Trail:
>Unformatted: