From 39a67fdb6974982b5ee13d90fcbdbe24a7ca7281 Mon Sep 17 00:00:00 2001 From: Tomas Mraz <tmraz@fedoraproject.org> Date: Fri, 15 Feb 2019 09:10:10 +0100 Subject: [PATCH] crontab: Make crontab without arguments fail. Although this deviates from POSIX specification it is clearly more sane behavior. --- man/crontab.1 | 25 +++++++++++-------------- src/crontab.c | 11 +++-------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/man/crontab.1 b/man/crontab.1 index 7d387e2..e557a03 100644 --- a/man/crontab.1 +++ b/man/crontab.1 @@ -28,16 +28,18 @@ crontab \- maintains crontab files for individual users .SH SYNOPSIS .B crontab .RB [ -u -.IR user ] " file" +.IR user ] +.RI < "file" +.RB | \ - > .br .B crontab .RB [ -u .IR user ] -.RB [ -l " | " -r " | " -e ]\ [ -i ] +.RB < -l " | " -r " | " -e >\ [ -i ] .RB [ -s ] .br .B crontab -.BR -n\ [ +.BR -n \ [ .IR "hostname " ] .br .B crontab @@ -102,19 +104,11 @@ directory is used. .SH "OPTIONS" .TP .B "\-u" -Appends the name of the user whose crontab is to be modified. If this +Specifies the name of the user whose crontab is to be modified. If this option is not used, .I crontab examines "your" crontab, i.e., the crontab of the person executing the -command. Note that -.BR su (8) -may confuse -.IR crontab , -thus, when executing commands under -.BR su (8) -you should always use the -.B -u -option. If no crontab exists for a particular user, it is created for +command. If no crontab exists for a particular user, it is created for him the first time the .B crontab -u command is used under his username. @@ -195,7 +189,10 @@ Print version and exit. .SH STANDARDS The .I crontab -command conforms to IEEE Std1003.2-1992 (``POSIX''). This new command +command conforms to IEEE Std1003.2-1992 (``POSIX'') with one exception: +For replacing the current crontab with data from standard input the +.B \- +has to be specified on the command line. This new command syntax differs from previous versions of Vixie Cron, as well as from the classic SVR3 syntax. .SH DIAGNOSTICS diff --git a/src/crontab.c b/src/crontab.c index adf1463..d26c2d3 100644 --- a/src/crontab.c +++ b/src/crontab.c @@ -135,8 +135,6 @@ static void usage(const char *msg) { int main(int argc, char *argv[]) { int exitstatus; - char n[] = "-"; /*set the n string to - so we have a valid string to use */ - char *nargv[] = { argv[0], n, NULL }; if ((ProgramName=strrchr(argv[0], '/')) == NULL) { ProgramName = argv[0]; @@ -154,10 +152,6 @@ int main(int argc, char *argv[]) { #if defined(BSD) setlinebuf(stderr); #endif - /*should we desire to make changes to behavior later. */ - if (argv[1] == NULL) { /* change behavior to allow crontab to take stdin with no '-' */ - argv = nargv; - } parse_args(argc, argv); /* sets many globals, opens a file */ check_spool_dir(); if (!allowed(RealUser, CRON_ALLOW, CRON_DENY)) { @@ -328,7 +322,7 @@ static void parse_args(int argc, char *argv[]) { endpwent(); - if (Option == opt_hostset && argv[optind] != NULL) { + if (Option == opt_hostset && argv[optind] != NULL) { HostSpecified = 1; if (strlen(argv[optind]) >= sizeof Host) usage("hostname too long"); @@ -342,13 +336,14 @@ static void parse_args(int argc, char *argv[]) { } else { if (argv[optind] != NULL) { + fprintf(stderr, "optind argv[optind]:%d %s\n", optind, argv[optind]); Option = opt_replace; if (strlen(argv[optind]) >= sizeof Filename) usage("filename too long"); (void) strcpy(Filename, argv[optind]); } else - usage("file name must be specified for replace"); + usage("file name or - (for stdin) must be specified for replace"); } if (Option == opt_replace) { -- 2.40.0