Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 9 Jun 2002 17:50:04 -0700 (PDT)
From:      Stanley Hopcroft <Stanley.Hopcroft@IPAustralia.Gov.AU>
To:        freebsd-ports@FreeBSD.org
Subject:   Re: ports/39018: Follow up of PR/31352 'fcntl(0, F_SETFL, O_NONBLOCK): Inappropriate ioctl for device' from check_by_ssh
Message-ID:  <200206100050.g5A0o4658085@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR ports/39018; it has been noted by GNATS.

From: Stanley Hopcroft <Stanley.Hopcroft@IPAustralia.Gov.AU>
To: FreeBSD-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: ports/39018: Follow up of PR/31352 'fcntl(0, F_SETFL, O_NONBLOCK): Inappropriate ioctl for device' from check_by_ssh
Date: Mon, 10 Jun 2002 10:45:33 +1000

 Dear Sir or Madam,
 
 Here is a letter about this matter from the Netsaint developer (Mr Ethan
 Galstad),
 
 I discovered this problem in Nagios, so it probably exists in
 NetSaint 0.0.7 as well (its fixed in the latest beta of Nagios).  The
 problem is that when starting as a daemon, NetSaint/Nagios used to:
  
         close(0);
         close(1);
         close(2);
  
 in daemon_init() to close stdin, stdout, and stderr.  This caused
 problems because the IPC pipe used to pass service check results back
 to the main process got opened after these statements.  As such,
 stderr output from plugins was sent directly to the IPC pipe, which
 ended up munging service check results in the pipe (and therefore the
 alerts you get).  This appeared to only present a problem if a plugin
 sent output to stderr.  Anyway, stdin/out/err are no longer closed
 when daemonizing, as this causes more problems than it supposedly
 solves.
  
 The problem emerged (for me) after an upgrade to 4.5-RELASE-p4 when the
 this fix was committed,
 
 20020421:       p4      FreeBSD-SA-02:23.stdio
 
 When exec'ing set[ug]id executables, the kernel now ensures that
 the stdio file descriptors (0..2) are open.  
 
 Here is a patch for Netsaint 0.0.7 that works for me. I am __not__ a
 programmer, and have no understanding of why this works.
 
 --- utils.c     Mon Jun 10 10:36:01 2002
 +++ utils.c.orig        Sat Jun  8 18:51:00 2002
 @@ -1854,10 +1854,6 @@
         /* child becomes session leader... */
         setsid();
  
 -       close(STDIN_FILENO) ;
 -       close(STDOUT_FILENO) ;
 -       close(STDERR_FILENO) ;
 -
         /* place a file lock on the lock file */
         lock.l_type=F_WRLCK;
         lock.l_start=0;
 
 Here is Mr Galstads patch (from Nagios CVS. Nagios already closes these 
 fds)
 
 --- utils.c      Mon Jun 10 10:43:54 2002
 +++ utils.c.orig        Sat Jun  8 18:51:00 2002
 @@ -1884,17 +1884,6 @@
         val|=FD_CLOEXEC;
         fcntl(lockfile,F_SETFD,val);
  
 -       /* close existing stdin, stdout, stderr */
 -        close(0);
 -        close(1);
 -        close(2);
 -
 -        /* THIS HAS TO BE DONE TO AVOID PROBLEMS WITH STDERR BEING
 REDIRECTED TO SERVICE MESSAGE PIPE! */
 -        /* re-open stdin, stdout, stderr with known values */
 -        open("/dev/null",O_RDONLY);
 -        open("/dev/null",O_WRONLY);
 -        open("/dev/null",O_WRONLY);
 -
         return OK;
         }
  
 
 As noted above, there are caveats for using this patch. It probably
 should only be used if you are having trouble.
 
 Yours sincerely.
 
 -- 
 Stanley Hopcroft
 
 
 
 MAN GAVE NAMES TO ALL THE ANIMALS
 1979 Special Rider Music
 
 Man gave names to all the animals
 In the beginning, in the beginning.
 Man gave names to all the animals
 In the beginning, long time ago.
 
 He saw an animal that liked to growl,
 Big furry paws and he liked to howl,
 Great big furry back and furry hair.
 "Ah, think I'll call it a bear."
 
 Man gave names to all the animals
 In the beginning, in the beginning.
 Man gave names to all the animals
 In the beginning, long time ago.
 
 He saw an animal up on a hill
 Chewing up so much grass until she was filled.
 He saw milk comin' out but he didn't know how.
 "Ah, think I'll call it a cow."
 
 Man gave names to all the animals
 In the beginning, in the beginning.
 Man gave names to all the animals
 In the beginning, long time ago.
 
 He saw an animal that liked to snort,
 Horns on his head and they weren't too short.
 It looked like there wasn't nothin' that he couldn't pull.
 "Ah, think I'll call it a bull."
 
 Man gave names to all the animals
 In the beginning, in the beginning.
 Man gave names to all the animals
 In the beginning, long time ago.
 
 He saw an animal leavin' a muddy trail,
 Real dirty face and a curly tail.
 He wasn't too small and he wasn't too big.
 "Ah, think I'll call it a pig."
 
 Man gave names to all the animals
 In the beginning, in the beginning.
 Man gave names to all the animals
 In the beginning, long time ago.
 
 Next animal that he did meet
 Had wool on his back and hooves on his feet,
 Eating grass on a mountainside so steep.
 "Ah, think I'll call it a sheep."
 
 Man gave names to all the animals
 In the beginning, in the beginning.
 Man gave names to all the animals
 In the beginning, long time ago.
 
 He saw an animal as smooth as glass
 Slithering his way through the grass.
 Saw him disappear by a tree near a lake . . .
 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200206100050.g5A0o4658085>