Back to index

glibc  2.9
Functions
login_tty.c File Reference
#include <errno.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <utmp.h>

Go to the source code of this file.

Functions

int login_tty (int fd)

Function Documentation

int login_tty ( int  fd)

Definition at line 42 of file login_tty.c.

{
       (void) setsid();
#ifdef TIOCSCTTY
       if (ioctl(fd, TIOCSCTTY, (char *)NULL) == -1)
              return (-1);
#else
       {
         /* This might work.  */
         char *fdname = ttyname (fd);
         int newfd;
         if (fdname)
           {
             if (fd != 0)
              (void) close (0);
             if (fd != 1)
              (void) close (1);
             if (fd != 2)
              (void) close (2);
             newfd = open (fdname, O_RDWR);
             (void) close (newfd);
           }
       }
#endif
       while (dup2(fd, 0) == -1 && errno == EBUSY)
         ;
       while (dup2(fd, 1) == -1 && errno == EBUSY)
         ;
       while (dup2(fd, 2) == -1 && errno == EBUSY)
         ;
       if (fd > 2)
              (void) close(fd);
       return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function: