This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/13385] New: request for an openpty variant that can atomically set FD_CLOEXEC


http://sourceware.org/bugzilla/show_bug.cgi?id=13385

             Bug #: 13385
           Summary: request for an openpty variant that can atomically set
                    FD_CLOEXEC
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: eblake@redhat.com
    Classification: Unclassified


Use of the POSIX-mandated posix_openpt()/grantpt()/unlockpt()/ptsname()/open()
is neither thread-safe (here's looking at you, ptsname()) nor portable (at
least Solaris and HP-UX _also_ require some STREAMS ioctl() on the slave side
before isatty() returns true on the slave side).  So any application trying to
create both master and slave pty is _already_ in the realm of non-portable code
(whether ptsname_r() or openpty()), at which point, we might as well make
openpty() nicer to use, as it is certainly less code for the application writer
to think about.

Unfortunately, openpty() has several flaws of its own: with posix_openpt(), it
is possible to atomically set FD_CLOEXEC (the next version of POSIX will be
standardizing that O_CLOEXEC is a valid flag:
http://austingroupbugs.net/view.php?id=411); furthermore, on at least Linux, it
is also already possible to set O_NONBLOCK in the flags (although POSIX is
silent on whether the master fd of a pty can operate in non-blocking mode). 
Furthermore, the only portable argument to pass for the name argument is NULL
(since there is no size argument).  Likewise, there is no portable way to
properly initialize a struct termios except via read-modify-write using
tcgetattr()/tcsetattr(), but until an fd is open, you have nothing to read in
order to do the modifications, so the only useful argument to pass for termios
is NULL.

I'm proposing that glibc add a nicer version of openpty() which adds a int
flags argument (valid flags must include O_CLOEXEC, and should also allow for
O_NONBLOCK), as well as adding at least a size_t name_length argument for
letting the user pass in the length of their non-NULL buffer (ERANGE failure if
buffer is non-NULL but name_length is too small).  I don't know whether we can
improve anything about the fact that the struct termios argument can't be
portable used, but we can't remove it since the goal would be that the old
interface can trivially wrap the new one.  Something like:

 int openpty(int *amaster, int *aslave, char *name,
                   const struct termios *termp,
                   const struct winsize *winp);
 int openpty2(int *amaster, int *aslave, int flags,
                   char *name, size_t name_len,
                   const struct termios *termp,
                   const struct winsize *winp);

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]