NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/58408: cron ignores parameter "-n" in crontab



The following reply was made to PR bin/58408; it has been noted by GNATS.

From: RVP <rvp%SDF.ORG@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: "Dr. Nicola Mingotti" <nmingotti%gmail.com@localhost>
Subject: Re: bin/58408: cron ignores parameter "-n" in crontab
Date: Wed, 24 Jul 2024 09:43:37 +0000 (UTC)

 On Mon, 22 Jul 2024, Dr. Nicola Mingotti wrote:
 
 > To ease the reproduction of the problem I re-do it all in a VM.
 >
 
 Can you try the patch below?
 
 --- START ---
 diff -urN cron.orig/dist/do_command.c cron/dist/do_command.c
 --- cron.orig/dist/do_command.c	2020-04-18 19:32:19.000000000 +0000
 +++ cron/dist/do_command.c	2024-07-24 08:23:44.648613785 +0000
 @@ -254,12 +254,16 @@
   				log_it("CRON", getpid(), "error",
   				    "no job pid");
   			else {
 -				while (waitpid(jobpid, &jstatus, WNOHANG) == -1)
 +				int rc;
 +				while ((rc = waitpid(jobpid, &jstatus, WNOHANG)) <= 0) {
 +					if (rc == 0)
 +						continue;	/* no stat. change */
   					if (errno != EINTR) {
   						log_it("CRON", getpid(),
   						    "error", "no job pid");
   						break;
   					}
 +				}
   			}
   			/* If everything went well, and -n was set, _and_ we
   			 * have mail, we won't be mailing... so shoot the
 diff -urN cron.orig/dist/popen.c cron/dist/popen.c
 --- cron.orig/dist/popen.c	2018-06-14 22:04:28.000000000 +0000
 +++ cron/dist/popen.c	2024-07-24 08:43:41.156198413 +0000
 @@ -90,7 +90,7 @@
   			break;
   	argv[MAX_ARGV-1] = NULL;
 
 -	switch (pid = vfork()) {
 +	switch (pid = fork()) {
   	case -1:			/* error */
   		(void)close(pdes[0]);
   		(void)close(pdes[1]);
 --- END ---
 
 In addition to mailing on success (with -n), cron doesn't seem to
 kill the mailer process properly either. (I didn't realize 'til
 now how cron worked for `-n' in crontab: Without the `-n', cron
 reads the output of the job, then runs a mailer process and writes
 the output to it. If you add `-n' it does _the same_ thing, then
 instead of closing the pipe on EOF, _kills_ the mailer process.
 This aborts the sending of the collected mail data--a _very_ odd
 way to do things...)
 
 I'll look at this more fully this weekend maybe.
 
 -RVP
 


Home | Main Index | Thread Index | Old Index