Re: Checkpassword and FD3 - the problem
"Jim Ramsay" <[email protected]> Thu, 10 Apr 2003 10:34:46 -0600
| Newsgroups | gmane.comp.djb.checkpassword |
|---|---|
| Message-ID | <[email protected]> |
"Jason R. Mastaler" <[email protected]> wrote in message news:[email protected]... > Felix von Leitner <[email protected]> writes: > > > You could also try setting the flag yourself. I don't know how it's > > done in python, but in C it's > > > > fcntl(fd,F_SETFD,FD_CLOEXEC); > > Python has a fcntl module: > > http://www.python.org/doc/current/lib/module-fcntl.html Sadly this won't work... it looks like it's not that the FD is not being closed on exec - Quite the contrary. The pipe is closed once the checkpassword program is actually execed. However the real problem is that a new pipe is created in every child every time you fork - and this pipe cannot be altered by the user program. This may well be a bug in the threading library - I'll have to figure out who wrote it first and look into that. But here's an interesting solution: - Fork. - In this child, create a pipe - Close FD's 1 and 2 - Fork again, creating the grandchild - This strange pipe now lives in FD 1 and 2, leaving FD3 free for the grandchild to connect one end of that pipe to. - Of course close the ends of the pipe the child and grandchild won't be needing. - Exec the checkpassword program in the grandchild and have the child write the string into the pipe and wait for the grandchild to exit - The child returns the grandchild's exit status as its own exit status - The parent now has the result we need. This is almost as kludgey as using /bin/sh for redirection or wrapping python in some sort of environment where FD#3 is already open, but at least it can be done purely in python :) Jim