Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140905172906.GN23797@brightrain.aerifal.cx>
Date: Fri, 5 Sep 2014 13:29:07 -0400
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: Add login_tty

On Fri, Sep 05, 2014 at 07:23:52PM +0200, Felix Janda wrote:
> Szabolcs Nagy wrote:
> > * Felix Janda <felix.janda@...teo.de> [2014-08-26 18:56:28 +0200]:
> > > --- /dev/null
> > > +++ b/src/misc/login_tty.c
> > > @@ -0,0 +1,14 @@
> > > +#include <utmp.h>
> > > +#include <sys/ioctl.h>
> > > +#include <unistd.h>
> > > +
> > > +int login_tty(int fd)
> > > +{
> > > +	setsid();
> > > +	if (ioctl(fd, TIOCSCTTY, (char *)0)) return -1;
> > > +	dup2(fd, 0);
> > > +	dup2(fd, 1);
> > > +	dup2(fd, 2);
> > > +	if (fd>2) close(fd);
> > > +	return 0;
> > > +}
> > 
> > i recently came across this:
> > http://lxr.free-electrons.com/source/fs/file.c#L751
> > 
> > so dup2 may spuriously fail with EBUSY on linux
> > 
> > the current forkpty does not check dup2 either, but i
> > wonder if it should be
> > 
> >  while(dup2(fd,0)==-1 && errno==EBUSY);
> > 
> > instead
> 
> The other possibility for dup2 to fail seems to be EINTR.
> (We already know that fd can't be invalid.)
> Should this also be checked?

Why would EINTR happen? dup2 does not involve any sleep much less
interruptible sleep/blocking.

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.