diff options
author | Keith M Wesolowski <wesolows@foobazco.org> | 2013-09-23 21:16:21 +0000 |
---|---|---|
committer | Keith M Wesolowski <wesolows@foobazco.org> | 2013-09-23 21:32:57 +0000 |
commit | 196dc3d35b74b9ef8cc5e2dbf3862c33d8617865 (patch) | |
tree | 29b9dce4c1fb1e6a3c9937a965eba43df09f3f0f | |
parent | 87eeb5da7170503814912ed2d230516d4d1cdd63 (diff) | |
download | illumos-joyent-196dc3d35b74b9ef8cc5e2dbf3862c33d8617865.tar.gz |
OS-2512 crontab behaviour makes it easy to duplicate entries
-rw-r--r-- | usr/src/cmd/cron/crontab.c | 42 | ||||
-rw-r--r-- | usr/src/man/man1/crontab.1 | 35 |
2 files changed, 49 insertions, 28 deletions
diff --git a/usr/src/cmd/cron/crontab.c b/usr/src/cmd/cron/crontab.c index ff39d93824..cdb4e1e394 100644 --- a/usr/src/cmd/cron/crontab.c +++ b/usr/src/cmd/cron/crontab.c @@ -71,7 +71,7 @@ "usage:\n" \ "\tcrontab [file]\n" \ "\tcrontab -e [username]\n" \ - "\tcrontab -l [username]\n" \ + "\tcrontab -l [-g] [username]\n" \ "\tcrontab -r [username]" #define INVALIDUSER "you are not a valid user (no entry in /etc/passwd)." #define NOTALLOWED "you are not authorized to use cron. Sorry." @@ -120,6 +120,7 @@ main(int argc, char **argv) int c, r; int rflag = 0; int lflag = 0; + int gflag = 0; int eflag = 0; int errflg = 0; char *pp; @@ -151,11 +152,14 @@ main(int argc, char **argv) exit(1); } - while ((c = getopt(argc, argv, "elr")) != EOF) + while ((c = getopt(argc, argv, "eglr")) != EOF) switch (c) { case 'e': eflag++; break; + case 'g': + gflag++; + break; case 'l': lflag++; break; @@ -170,6 +174,9 @@ main(int argc, char **argv) if (eflag + lflag + rflag > 1) errflg++; + if (gflag && !lflag) + errflg++; + argc -= optind; argv += optind; if (errflg || argc > 1) @@ -236,28 +243,27 @@ main(int argc, char **argv) exit(0); } if (lflag) { - int sys_done = 0; char sysconf[PATH_MAX]; - if (snprintf(sysconf, sizeof (sysconf), "%s/%s", - SYSCRONDIR, login) < sizeof (sysconf) && - (fp = fopen(sysconf, "r")) != NULL) { + if (gflag) { + if (snprintf(sysconf, sizeof (sysconf), "%s/%s", + SYSCRONDIR, login) < sizeof (sysconf) && + (fp = fopen(sysconf, "r")) != NULL) { + while (fgets(line, CTLINESIZE, fp) != NULL) + fputs(line, stdout); + fclose(fp); + exit(0); + } else { + crabort(BADOPEN); + } + } else { + if ((fp = fopen(cf, "r")) == NULL) + crabort(BADOPEN); while (fgets(line, CTLINESIZE, fp) != NULL) fputs(line, stdout); fclose(fp); - sys_done = 1; - } - - if ((fp = fopen(cf, "r")) == NULL) { - if (!sys_done) - crabort(BADOPEN); - else - exit(0); + exit(0); } - while (fgets(line, CTLINESIZE, fp) != NULL) - fputs(line, stdout); - fclose(fp); - exit(0); } if (eflag) { if ((fp = fopen(cf, "r")) == NULL) { diff --git a/usr/src/man/man1/crontab.1 b/usr/src/man/man1/crontab.1 index aae9ad44f1..927b5345c4 100644 --- a/usr/src/man/man1/crontab.1 +++ b/usr/src/man/man1/crontab.1 @@ -11,7 +11,7 @@ .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH CRONTAB 1 "Apr 6, 2009" +.TH CRONTAB 1 "Sep 23, 2013" .SH NAME crontab \- user crontab file .SH SYNOPSIS @@ -27,7 +27,7 @@ crontab \- user crontab file .LP .nf -\fB/usr/bin/crontab\fR \fB-l\fR [\fIusername\fR] +\fB/usr/bin/crontab\fR \fB-l\fR [\fB-g\fR] [\fIusername\fR] .fi .LP @@ -47,7 +47,7 @@ crontab \- user crontab file .LP .nf -\fB/usr/xpg4/bin/crontab\fR \fB-l\fR [\fIusername\fR] +\fB/usr/xpg4/bin/crontab\fR \fB-l\fR [\fB-g\fR] [\fIusername\fR] .fi .LP @@ -67,7 +67,7 @@ crontab \- user crontab file .LP .nf -\fB/usr/xpg6/bin/crontab\fR \fB-l\fR [\fIusername\fR] +\fB/usr/xpg6/bin/crontab\fR \fB-l\fR [\fB-g\fR] [\fIusername\fR] .fi .LP @@ -92,10 +92,12 @@ If \fBcrontab\fR is invoked with \fIfilename\fR, this overwrites an existing Cron supports a merged crontab with entries coming from either the user's \fB/var/spool/cron/crontabs\fR file or from the user's \fB/etc/cron.d/crontabs\fR file. The entries in the user's -\fB/var/spool/cron/crontabs\fR file are meant to be editable whereas those in -\fB/etc/cron.d/crontabs\fR are meant as system-defined entries which are not -intended to be customized by the user. The dual set of crontab entries is only -of interest to system-defined users such as \fBroot\fR. +\fB/var/spool/cron/crontabs\fR file are editable whereas those in +\fB/etc/cron.d/crontabs\fR are system-defined entries which may not +be customized by the user. The dual set of crontab entries is only +of interest to system-defined users such as \fBroot\fR. Except where +otherwise explicitly indicated, all variants of the \fBcrontab\fR command +act only on the editable crontab files found in \fB/var/spool/cron/crontabs\fR. .SS "\fBcrontab\fR Access Control" .sp .LP @@ -368,8 +370,21 @@ Lists the \fBcrontab\fR file for the invoking user. Only root or a user with the \fBsolaris.jobs.admin\fR authorization can specify a username following the \fB-l\fR option to list the \fBcrontab\fR file of the specified user. .sp -Entries from both the user's \fB/var/spool/cron/crontabs\fR file and thhe user's -\fB/etc/cron.d/crontabs\fR file will be merged in the output. +Entries from the user's \fB/var/spool/cron/crontabs\fR file are listed, unless +the \fB-g\fR option is given, in which case only entries from the user's +\fB/etc/cron.d/crontabs\fR file are listed. +.RE + +.sp +.ne 2 +.na +\fB\fB-g\fR\fR +.ad +.RS 6n +In conjunction with the \fB-l\fR option, lists the global \fBcrontab\fR file +for the invoking or specified user (if authorized) instead of the editable +\fBcrontab\fR file. This option is not valid unless the \fB-l\fR option is +also given. .RE .sp |