Subject: Re: Warning message: Why do I care?
To: Greywolf <greywolf@starwolf.com>
From: David Maxwell <david@vex.net>
List: current-users
Date: 07/19/2002 11:49:56
On Thu, Jul 18, 2002 at 07:13:58PM -0700, Greywolf wrote:
> Is there a way to disable these warnings?  This level of warning seems
> over the top to me.  But I'd like other warnings at the same pri.level
> possibly to come through.

A specific example might help convince you that these are significant...

Suppose you invoke /usr/bin/passwd (which is setuid root), with an
invalid command line argument...

$ /usr/bin/passwd -h
passwd: illegal option -- h
usage:
        passwd [-y] [user]
        passwd [-l] [user]


Simple enough, you get an error. Now, using the shell, close the stderr
handle first:

$ /usr/bin/passwd -h 2>&-

No output is returned, you just get your prompt back.
Now, passwd is smart enough to check its arguments first, and return the
error message immediately - but let's pretend for a moment that it
didn't do that right away, and instead opened up some filehandles...

If it opens /etc/passwd first, it will be assigned descriptor 2 'stderr',
and when the usage statement is printed, your passwd file is now
corrupt.

Since the kernel can't sanity check the operation of programs, the best
it can do is warn about this so that you know. So, unless absolutely
neccessary - don't close FDs before running programs.

-- 
David Maxwell, david@vex.net|david@maxwell.net --> Although some of you out
there might find a microwave oven controlled by a Unix system an attractive
idea, controlling a microwave oven is easily accomplished with the smallest
of microcontrollers. - Russ Hersch - (Microcontroller primer and FAQ)