ubase

suckless linux base utils
git clone git://git.2f30.org/ubase.git
Log | Files | Refs | README | LICENSE

commit c4388962b063a8f3d428ac40a00cbde0bc0d137f
parent fa004f2961fb336e63cf724d7464acbf10e6e92d
Author: sin <sin@2f30.org>
Date:   Wed Nov 12 11:49:44 +0000

Rework tty setup in getty(8)

Diffstat:
getty.c | 29++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/getty.c b/getty.c @@ -63,32 +63,31 @@ main(int argc, char *argv[]) eprintf("open %s:", tty); if (isatty(fd) == 0) eprintf("%s is not a tty\n", tty); - if (ioctl(fd, TIOCSCTTY, (void *)1) == 0) - vhangup(); - else - weprintf("TIOCSCTTY: could not set controlling tty\n"); + /* steal the controlling terminal if necessary */ + if (ioctl(fd, TIOCSCTTY, (void *)1) != 0) + weprintf("TIOCSCTTY: could not set controlling tty\n"); + vhangup(); close(fd); + fd = open(tty, O_RDWR); if (fd < 0) eprintf("open %s:", tty); - if (dup2(fd, STDIN_FILENO) != STDIN_FILENO) - eprintf("dup2:"); - if (dup2(fd, STDOUT_FILENO) != STDOUT_FILENO) - eprintf("dup2:"); - if (dup2(fd, STDERR_FILENO) != STDERR_FILENO) - eprintf("dup2:"); + dup2(fd, STDIN_FILENO); + dup2(fd, STDOUT_FILENO); + dup2(fd, STDERR_FILENO); + if (fchown(fd, 0, 0) < 0) + weprintf("fchown %s:", tty); + if (fchmod(fd, 0600) < 0) + weprintf("fchmod %s:", tty); + if (fd > 2) + close(fd); sa.sa_handler = SIG_DFL; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sigaction(SIGHUP, &sa, NULL); - if (fchown(fd, 0, 0) < 0) - eprintf("fchown %s:", tty); - if (fchmod(fd, 0600) < 0) - eprintf("chmod %s:", tty); - /* Clear all utmp entries for this tty */ fp = fopen(UTMP_PATH, "r+"); if (fp) {