From owner-freebsd-hackers Sun Mar 21 15:53: 0 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from frmug.org (frmug-gw.frmug.org [193.56.58.252]) by hub.freebsd.org (Postfix) with ESMTP id 78E6C1512B for ; Sun, 21 Mar 1999 15:52:57 -0800 (PST) (envelope-from roberto@keltia.freenix.fr) Received: (from uucp@localhost) by frmug.org (8.9.1/frmug-2.3/nospam) with UUCP id AAA05721 for freebsd-hackers@FreeBSD.ORG; Mon, 22 Mar 1999 00:52:37 +0100 (CET) (envelope-from roberto@keltia.freenix.fr) Received: by keltia.freenix.fr (Postfix, from userid 101) id 003A7884B; Mon, 22 Mar 1999 00:13:09 +0100 (CET) Date: Mon, 22 Mar 1999 00:13:09 +0100 From: Ollivier Robert To: "FreeBSD Hackers' list" Subject: Fwd: Re: cron problem? Message-ID: <19990322001309.A53335@keltia.freenix.fr> Mail-Followup-To: FreeBSD Hackers' list Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii User-Agent: Mutt/0.95.3i X-Operating-System: FreeBSD 4.0-CURRENT/ELF ctm#5130 AMD-K6 MMX @ 200 MHz Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Wietse found the following while writing Postfix. Can anyone look at it ? ----- Forwarded message from Wietse Venema ----- Subject: Re: cron problem? Date: Fri, 19 Mar 1999 14:59:34 -0500 (EST) From: wietse@porcupine.org (Wietse Venema) Found it. I'll post a patch later. This must be a *BSD oddity. Wietse Problem: Vixie cron output from an /etc/crontab entry is not mailed, unless the crontab line ends with an explicit mail command System: FreeBSD 2.x, BSD/OS 2.x ... (yes I'm not running the latest) Analysis: For the sake of security and robustness, Postfix tries to ensure that stdin/out/err are open before opening anything else. The following code fragment appears in many programs that I wrote in the course of time: for (fd = 0; fd < 3; fd++) if (fstat(fd, &st) == -1 && open("/dev/null", O_WRONLY) != fd) msg_fatal("open /dev/null: %m"); This fragment examines the status of stdin/stdout/stderr. When fstat() returns an error, the code assumes the file descriptor is not in use, and expects that the next open() will allocate that file descriptor. However, the kernel trace shows a small surprise: 3817 sendmail CALL fstat(0,0xefbfddc8) 3817 sendmail RET fstat 0 3817 sendmail CALL fstat(0x1,0xefbfddc8) 3817 sendmail RET fstat -1 errno 9 Bad file descriptor 3817 sendmail CALL open(0x1c8c,0x1,0xefbfde4c) 3817 sendmail NAMI "/dev/null" 3817 sendmail RET open 3 So: fstat(1) returns EBADF, and open() returns 3. Conclusion: file descriptor 1 is still in use. *** Why on earth does fstat() return EBADF on an open file descriptor? *** Workaround: Close the file descriptor after error return from fstat(). The following code does the job. if (fstat(fd, &st) == -1 && (close(fd), open("/dev/null", O_WRONLY)) != fd) msg_fatal("open /dev/null: %m"); ----- End forwarded message ----- -- Ollivier ROBERT -=- FreeBSD: The Power to Serve! -=- roberto@keltia.freenix.fr FreeBSD keltia.freenix.fr 4.0-CURRENT #70: Sat Feb 27 09:43:08 CET 1999 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message