Bug 39018

Summary: Follow up of PR/31352 'fcntl(0, F_SETFL, O_NONBLOCK): Inappropriate ioctl for device' from check_by_ssh
Product: Ports & Packages Reporter: Stanley.Hopcroft <Stanley.Hopcroft>
Component: Individual Port(s)Assignee: freebsd-ports (Nobody) <ports>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   

Description Stanley.Hopcroft 2002-06-08 03:50:01 UTC
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.
Comment 1 Stanley.Hopcroft 2002-06-10 01:45:33 UTC
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 . . .
Comment 2 Jun Kuriyama freebsd_committer freebsd_triage 2002-06-11 09:18:11 UTC
State Changed
From-To: open->closed

Committed, thanks!