From nobody@www.freebsd.org  Fri Jun  7 19:47:33 2002
Return-Path: <nobody@www.freebsd.org>
Received: from nwww.freebsd.org (www.FreeBSD.org [216.136.204.117])
	by hub.freebsd.org (Postfix) with ESMTP id 7ED9E37B400
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  7 Jun 2002 19:47:32 -0700 (PDT)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by nwww.freebsd.org (8.12.2/8.12.2) with ESMTP id g582lVhG094559
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 7 Jun 2002 19:47:31 -0700 (PDT)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.2/8.12.2/Submit) id g582lVdL094558;
	Fri, 7 Jun 2002 19:47:31 -0700 (PDT)
Message-Id: <200206080247.g582lVdL094558@www.freebsd.org>
Date: Fri, 7 Jun 2002 19:47:31 -0700 (PDT)
From: Stanley Hopcroft <Stanley.Hopcroft@IPAustralia.Gov.AU>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Follow up of PR/31352 'fcntl(0, F_SETFL, O_NONBLOCK): Inappropriate ioctl for device' from check_by_ssh
X-Send-Pr-Version: www-1.0

>Number:         39018
>Category:       ports
>Synopsis:       Follow up of PR/31352 'fcntl(0, F_SETFL, O_NONBLOCK): Inappropriate ioctl for device' from check_by_ssh
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-ports
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jun 07 19:50:01 PDT 2002
>Closed-Date:    Tue Jun 11 01:18:25 PDT 2002
>Last-Modified:  Tue Jun 11 01:18:25 PDT 2002
>Originator:     Stanley Hopcroft
>Release:        4.5-RELEASE-p[46]
>Organization:
>Environment:
FreeBSD tsitc.aipo.gov.au 4.5-RELEASE-p6 FreeBSD 4.5-RELEASE-p6 #5: Sat Jun  8 08:23:08 EST 2002     root@tsitc.aipo.gov.au:/usr/src/sys/compile/TSITC  i386


Base system ssh (OpenSSH_2.9 FreeBSD localisations 20020307, SSH protocols 1.5/2.0, OpenSSL 0x0090601f)
Netsaint built from source (0.0.7)
check_by_ssh from plugins 1.2.9-4.
Base system gcc (gcc version 2.95.3 20010315 (release) [FreeBSD])
>Description:
Symptoms are exactly as reported by Daniel Lang <dl@leo.org> (Thanks mate)
in PR/31352 ie

Sometime after Netsaint 0.0.7b[2-8] and 0.0.7 is started, Netsaint
logs a warning message from the check_by_ssh plugin that
[\d+] SERVICE ALERT: check_host;Standard host-centric checks;WARNING;SOFT;2;fcntl(0, F_SETFL, O_NONBLOCK): Inappropriate ioctl for device.

Some additional notes are :-

1 Problem only appeared after cvsup to 4.5-RELEASE-p4 and make installworld
(including mergemaster) following the handbooks description

ie make buildworld
   make buildkernel
   make installkernel
   reboot
   make installworld

I think that the problem is related to the shell that Netsaint starts in.

If Netsaint is started with

. login as root (su - )
. /Path/toNetsaint/bin -d /Path/to/Netsaint/etc/netsaint.cfg
. logout of root shell

then some time after logging out as root, the symptoms appear within
8 hours.

However, if Netsaint is started by

. login as root
. /Path/toNetsaint/bin/netsaint /Path/to?netsaint/ect/netsaint.cfg
. root sheell stays logged in

then there are no problems (for at least the 3-4 days I have done this
for).

Mr Langs remarks apply also: manual checks work fine.


>How-To-Repeat:
. start Netsaint as a daemon, log out of root shell, wait no more than
8 hours.
>Fix:
      
>Release-Note:
>Audit-Trail:

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 . . .
 
State-Changed-From-To: open->closed 
State-Changed-By: kuriyama 
State-Changed-When: Tue Jun 11 01:18:11 PDT 2002 
State-Changed-Why:  
Committed, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=39018 
>Unformatted:
