Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 3 Nov 2014 19:29:54 +0100
From: Felix Janda <felix.janda@...teo.de>
To: musl@...ts.openwall.com
Subject: Re: Add login_tty

Thanks for the review. Below a new version.


#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);
		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);
	close(p[0]);
	if (pid > 0) {
		if (!ec) return pid;
		waitpid(pid, &(int){0}, 0);
	}
fail:
	close(*m);
	return -1;
}


--Felix

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.