Re: password (& host?) file lookups, daemons and stray descriptors
From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 06/24/05
- Next message: Mr. Uh Clem: "Re: password (& host?) file lookups, daemons and stray descriptors"
- Previous message: Mr. Uh Clem: "Re: password (& host?) file lookups, daemons and stray descriptors"
- In reply to: Mr. Uh Clem: "password (& host?) file lookups, daemons and stray descriptors"
- Next in thread: Mr. Uh Clem: "Re: password (& host?) file lookups, daemons and stray descriptors"
- Reply: Mr. Uh Clem: "Re: password (& host?) file lookups, daemons and stray descriptors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 24 Jun 2005 01:20:08 -0400
In article <42bb3ac4$0$5702$9a6e19ea@news.newshosting.com>,
"Mr. Uh Clem" <uhclem@DutchElmSt.invalid> wrote:
> I've run into a strange problem on an HP11i system involving
> a daemon program which
>
> * calls getpwuid() as part of a security check during
> initialization
>
> * does the normal daemonization things:
> forks, setsid, etc.,
> close all descriptors,
> redirect 0-2 to /dev/null.
>
> * opens a lockfile and does a lockf on it.
>
> * subsequently calls getpwnam() to obtain a uid.
>
> On this system, the getpwnam() call causes the
> lock to be lost on the lockfile. (We don't seem
> to have this problem on our various other *ix
> flavors, although that could be a matter of
> system configuration: nsswitch.conf, etc.)
>
>
> Debugging shows that getpwuid leaves a descriptor
> open after it is called. From truss, it looks as
> if it creates a socket and leaves it open on fd 3.
> It is not hard to believe that Bad Things Happen(tm)
> when the daemonizing closes all child fds and the
> lockfile winds up with file descriptor 3. Truss
> seems to show the getpwnam() call atempting a sendto()
> on fd 3, failing, then doing it's thing on 4 and
> closing 4.
I think the solution is obvious: don't close all file descriptors, just
redirect 0-2 to /dev/null. You shouldn't close random descriptors
because you have no idea whether they're still in use by some library
routines. You have to assume that if a descriptor was left open, it was
for a reason.
What you may want to do is set the close-on-exec flag on all the
descriptors, if your daemon execs other programs.
-- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me ***
- Next message: Mr. Uh Clem: "Re: password (& host?) file lookups, daemons and stray descriptors"
- Previous message: Mr. Uh Clem: "Re: password (& host?) file lookups, daemons and stray descriptors"
- In reply to: Mr. Uh Clem: "password (& host?) file lookups, daemons and stray descriptors"
- Next in thread: Mr. Uh Clem: "Re: password (& host?) file lookups, daemons and stray descriptors"
- Reply: Mr. Uh Clem: "Re: password (& host?) file lookups, daemons and stray descriptors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|