|
|
Message-ID: <20141221005821.GG4574@brightrain.aerifal.cx>
Date: Sat, 20 Dec 2014 19:58:21 -0500
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: Add login_tty
On Mon, Nov 03, 2014 at 07:29:54PM +0100, Felix Janda wrote:
> Thanks for the review. Below a new version.
Sorry I didn't get around to reviewing this right away.
> #include <pty.h>
> #include <utmp.h>
> #include <unistd.h>
>
> int forkpty(int *m, char *name, const struct termios *tio, const struct winsize *ws)
> {
> int s, ec, p[2];
> pid_t pid;
>
> if (openpty(m, &s, name, tio, ws) < 0) return -1;
> if (pipe2(p, O_CLOEXEC)) {
> close(s);
> goto fail;
> }
>
> pid = fork();
> if (!pid) {
> close(*m);
> close(p[0]);
> ec = login_tty(s);
login_tty could end up closing the pipe if stdin/out/err were
initially closed in the parent, since p[1] might be 0/1/2 in that
case. I think we need to check for this and move p[1] to a new fd in
that case (and fail if that fails) before calling login_tty.
> while (write(p[1], &ec, sizeof ec) < 0);
> if (ec) _exit(127);
> close(p[1]);
> return 0;
> }
> close(s);
> close(p[1]);
> if (pid > 0) read(p[0], &ec, sizeof ec);
This read probably needs to retry-loop, in case the parent has
interrupting signal handlers.
> close(p[0]);
> if (pid > 0) {
> if (!ec) return pid;
> waitpid(pid, &(int){0}, 0);
I think waitpid could in principle fail too, but it probably shouldn't
since the process is already dead at the time waitpid is called.
> }
> fail:
> close(*m);
> return -1;
> }
Otherwise it looks okay now.
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.