From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6428 Path: news.gmane.org!not-for-mail From: Felix Janda Newsgroups: gmane.linux.lib.musl.general Subject: Re: Add login_tty Date: Sun, 2 Nov 2014 19:56:38 +0100 Message-ID: <20141102185638.GA21712@euler> References: <20140826165627.GA1208@euler> <20141031161907.GD22465@brightrain.aerifal.cx> <20141101211523.GA13145@euler> <20141101214503.GK22465@brightrain.aerifal.cx> <20141101222729.GB5949@euler> <20141101224325.GM22465@brightrain.aerifal.cx> <20141101225643.GA8817@euler> <20141102000944.GN22465@brightrain.aerifal.cx> <20141102141912.GA3637@euler> <20141102162841.GP22465@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1414954638 32546 80.91.229.3 (2 Nov 2014 18:57:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 2 Nov 2014 18:57:18 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-6441-gllmg-musl=m.gmane.org@lists.openwall.com Sun Nov 02 19:57:12 2014 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Xl0Ks-0006Wb-Od for gllmg-musl@m.gmane.org; Sun, 02 Nov 2014 19:57:10 +0100 Original-Received: (qmail 17910 invoked by uid 550); 2 Nov 2014 18:57:09 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 17896 invoked from network); 2 Nov 2014 18:57:09 -0000 X-Virus-Scanned: amavisd-new at posteo.de Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline In-Reply-To: <20141102162841.GP22465@brightrain.aerifal.cx> User-Agent: Mutt/1.5.22 (2013-10-16) Xref: news.gmane.org gmane.linux.lib.musl.general:6428 Archived-At: Rich Felker wrote: [..] > There's an approach I use in posix_spawn that could be copied here. My > hope was to keep forkpty simpler but it's not too bad and it would > make it so we could handle other arbitrary errors in the child if we > ever need to, so maybe it's a good idea. So how about the following? (I'm not sure whether error checking is necessary for read.) #include #include #include int forkpty(int *m, char *name, const struct termios *tio, const struct winsize *ws) { int s, ec, p[2]; pid_t pid; if (pipe2(p, O_CLOEXEC)) return -1; if (openpty(m, &s, name, tio, ws) < 0) return -1; 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 || ec < 0) { close(*m); return -1; } return pid; } Felix