From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6074 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: Add login_tty Date: Thu, 4 Sep 2014 23:22:00 +0200 Message-ID: <20140904212159.GG10361@port70.net> References: <20140825185756.GA6077@euler> <20140825224333.GX12888@brightrain.aerifal.cx> <20140826165627.GA1208@euler> 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 1409865739 7225 80.91.229.3 (4 Sep 2014 21:22:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 4 Sep 2014 21:22:19 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-6087-gllmg-musl=m.gmane.org@lists.openwall.com Thu Sep 04 23:22:14 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1XPeTs-0001Ay-Fw for gllmg-musl@plane.gmane.org; Thu, 04 Sep 2014 23:22:12 +0200 Original-Received: (qmail 21628 invoked by uid 550); 4 Sep 2014 21:22:12 -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 21620 invoked from network); 4 Sep 2014 21:22:11 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline In-Reply-To: <20140826165627.GA1208@euler> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:6074 Archived-At: * Felix Janda [2014-08-26 18:56:28 +0200]: > --- /dev/null > +++ b/src/misc/login_tty.c > @@ -0,0 +1,14 @@ > +#include > +#include > +#include > + > +int login_tty(int fd) > +{ > + setsid(); > + if (ioctl(fd, TIOCSCTTY, (char *)0)) return -1; > + dup2(fd, 0); > + dup2(fd, 1); > + dup2(fd, 2); > + if (fd>2) close(fd); > + return 0; > +} i recently came across this: http://lxr.free-electrons.com/source/fs/file.c#L751 so dup2 may spuriously fail with EBUSY on linux the current forkpty does not check dup2 either, but i wonder if it should be while(dup2(fd,0)==-1 && errno==EBUSY); instead