[Rpm-maint] [PATCH 06/19] Add rpmpoltrans struct and helper functions
James Antill
james at fedoraproject.org
Fri Feb 12 23:54:33 UTC 2010
On Fri, 2010-02-12 at 15:31 -0500, Steve Lawrence wrote:
> On Fri, 2010-02-12 at 15:20 -0500, Steve Lawrence wrote:
> > On Fri, 2010-02-05 at 12:26 -0500, James Antill wrote:
> > > On Tue, 2010-02-02 at 15:25 -0500, Steve Lawrence wrote:
> > > > + case 0:
> > > > + if (!rpmIsDebug()) {
> > > > + freopen("/dev/null", "r", stdin);
> > > > + freopen("/dev/null", "w", stdout);
> > > > + freopen("/dev/null", "w", stderr);
> > > > + }
> > > > + execv(pt->semodulepath, pt->semodargs);
> > >
> > > Are you sure this is the same as the std. dup2() code? AFAICS freopen()
> > > does not guarantee to do that.
> >
> > I think close() should be enough. We're just trying to prevent semodule
> > from displaying messages when it's executed.
>
> Never mind about the close, I'm not sure what I was thinking. What is
> the problem with freopen that dup2 solves?
So what I'd have expected is:
fd = open("/dev/null", ...);
dup2(fd, STDIN_FILENO);
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
...this guarantees that write() to either STDOUT_FILENO or STDERR_FILENO
after this point goes to /dev/null (having read() on /dev/null return
nothing is a Linuxism, but is fine by me :).
Note that stdout is basically fdopen(STDOUT_FILENO), however freopen()
guarantees nothing about the underlying "fd". So after using
freopen(stdout) above, STDOUT_FILENO is closed (assuming success, and
that stdout is still using STDOUT_FILENO) but it is not pointing
at /dev/null.
I guess SELinux/glibc will guarantee that STDOUT_FILENO is pointing
"nowhere" by the time the process runs ... but it seems better to just
use dup2() in the first place.
More information about the Rpm-maint
mailing list