From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4073 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: GLOB_BRACE Date: Thu, 26 Sep 2013 14:59:39 -0400 Message-ID: <20130926185938.GU20515@brightrain.aerifal.cx> References: <1379945328.1974.50@driftwood> <524051AD.8070008@gentoo.org> <20130923150323.GH20515@brightrain.aerifal.cx> <5243AB8E.1070706@gentoo.org> <20130926182309.GS20515@brightrain.aerifal.cx> <20130926183812.GT20515@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1380221991 27054 80.91.229.3 (26 Sep 2013 18:59:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 26 Sep 2013 18:59:51 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4077-gllmg-musl=m.gmane.org@lists.openwall.com Thu Sep 26 20:59:53 2013 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 1VPGn2-0003q7-9X for gllmg-musl@plane.gmane.org; Thu, 26 Sep 2013 20:59:52 +0200 Original-Received: (qmail 13349 invoked by uid 550); 26 Sep 2013 18:59:51 -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 13341 invoked from network); 26 Sep 2013 18:59:51 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:4073 Archived-At: On Thu, Sep 26, 2013 at 08:50:33PM +0200, Daniel Cegiełka wrote: > @Rich > > Referring to your description: > > http://www.openwall.com/lists/musl/2012/06/10/23 > > "I have > a 22-line (C) init program that does nothing but run the boot script > and reap orphaned zombies, and a 34-line (C) program that repeatedly > re-runs a program in a new session every time it exits. The latter, > combined with a 14-line (shell script) getty program, is sufficient to > handle all console logins. > " > > it's a bit more then 22 LOC :) Yeah, yours does a few more things, and does so somewhat less efficiently. > static void > sigchild(int sig) > { > while(waitpid(-1, NULL, WNOHANG) > 0); > } Not needed. > static void > openconsole(void) > { > int fd; > > if((fd = open("/dev/console", O_RDWR|O_NOCTTY)) >= 0){ > dup2(fd, 0); > dup2(fd, 1); > dup2(fd, 2); > if(fd > 2) > close(fd); > } > } Unclear what this is needed for. Normally init starts on the console anyway, and if it doesn't, why would you want to force it to use the console instead of whatever stdin/out/err it started with? > int > main(int argc, char **argv) > { > int i, fd, l; > struct sigaction sa; > pid_t t; > > if(getpid() != 1) > return 1; > for(i = 0, l = 0; i < argc; i++) > l = strlen(argv[i]) + 1; > if(l > 1){ > memset(argv[0], 0, l); > strncpy(argv[0], "init", l - 1); > } > for(i = 1; i < NSIG; i++) > if(i != SIGCHLD) > (void)signal(i, SIG_IGN); Why are you ignoring signals rather than blocking them? It's more work and harder to undo before running the rc script (and you don't seem to be undoing it). > reboot(RB_DISABLE_CAD); > if((fd = open("/dev/console", O_RDWR|O_NOCTTY)) >= 0){ > ioctl(fd, KDSIGACCEPT, SIGWINCH); What does this do? > if(!fork()){ > setsid(); > openconsole(); > tcsetpgrp(0, getpgrp()); > execl("/bin/sh", "sh", "/etc/rc", NULL); > while(waitpid(t, NULL, 0) != t); > } > sigemptyset(&sa.sa_mask); > sa.sa_sigaction = 0; > sa.sa_flags = SA_RESTART|SA_NOCLDSTOP; > sa.sa_handler = sigchild; > sigaction(SIGCHLD, &sa, 0); > for(;;) > pause(); Instead use: for (;;) wait(&status); and you don't have to handle SIGCHLD. Rich