From: "Daniel Cegiełka" <daniel.cegielka@gmail.com>
To: musl@lists.openwall.com
Subject: Re: GLOB_BRACE
Date: Thu, 26 Sep 2013 20:50:33 +0200 [thread overview]
Message-ID: <CAPLrYESKzgNP0dE7xJE+Wo4CYJVQnJxo3PKc2OGmV1NOXO79Lw@mail.gmail.com> (raw)
In-Reply-To: <20130926183812.GT20515@brightrain.aerifal.cx>
[-- Attachment #1: Type: text/plain, Size: 443 bytes --]
@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 :)
Daniel
[-- Attachment #2: init.c --]
[-- Type: text/x-csrc, Size: 1356 bytes --]
/*
* init.c version 20130705
* Daniel Cegielka
* Public domain.
*/
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/reboot.h>
#include <linux/kd.h>
static void
sigchild(int sig)
{
while(waitpid(-1, NULL, WNOHANG) > 0);
}
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);
}
}
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);
reboot(RB_DISABLE_CAD);
if((fd = open("/dev/console", O_RDWR|O_NOCTTY)) >= 0){
ioctl(fd, KDSIGACCEPT, SIGWINCH);
close(fd);
} else
ioctl(0, KDSIGACCEPT, SIGWINCH);
for(i = 0; i < 3; i++){
close(i);
open("/dev/null", O_RDWR, 0);
}
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();
}
next prev parent reply other threads:[~2013-09-26 18:50 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-15 20:57 GLOB_BRACE Paul Schutte
2013-09-16 12:50 ` GLOB_BRACE Rich Felker
2013-09-16 13:40 ` GLOB_BRACE Paul Schutte
2013-09-16 13:47 ` GLOB_BRACE Justin Cormack
2013-09-16 13:51 ` GLOB_BRACE Luca Barbato
2013-09-16 14:18 ` GLOB_BRACE Paul Schutte
2013-09-23 14:08 ` GLOB_BRACE Rob Landley
2013-09-23 14:35 ` GLOB_BRACE Luca Barbato
2013-09-23 15:03 ` GLOB_BRACE Rich Felker
2013-09-23 15:21 ` GLOB_BRACE Kurt H Maier
2013-09-23 15:27 ` GLOB_BRACE Luca Barbato
2013-09-25 22:46 ` GLOB_BRACE Paul Schutte
2013-09-26 0:02 ` GLOB_BRACE Rich Felker
2013-09-26 3:35 ` GLOB_BRACE Luca Barbato
2013-09-26 4:48 ` GLOB_BRACE Daniel Cegiełka
2013-09-26 18:23 ` GLOB_BRACE Rich Felker
2013-09-26 18:30 ` GLOB_BRACE Daniel Cegiełka
2013-09-26 18:38 ` GLOB_BRACE Rich Felker
2013-09-26 18:50 ` Daniel Cegiełka [this message]
2013-09-26 18:59 ` GLOB_BRACE Rich Felker
2013-09-26 19:10 ` GLOB_BRACE Daniel Cegiełka
2013-09-26 19:13 ` GLOB_BRACE Rich Felker
2013-09-26 19:24 ` GLOB_BRACE Daniel Cegiełka
2013-09-26 19:06 ` GLOB_BRACE John Spencer
2013-09-26 20:21 ` GLOB_BRACE Daniel Cegiełka
2013-09-26 20:41 ` GLOB_BRACE Daniel Cegiełka
2013-09-27 12:23 ` GLOB_BRACE Anthony G. Basile
2013-09-27 12:53 ` GLOB_BRACE Daniel Cegiełka
2013-09-27 13:06 ` GLOB_BRACE Daniel Cegiełka
2013-09-29 21:51 ` GLOB_BRACE Anthony G. Basile
2013-09-29 21:57 ` GLOB_BRACE Rich Felker
2013-09-26 19:16 ` GLOB_BRACE Christian Neukirchen
2013-09-23 15:18 ` GLOB_BRACE Rob Landley
2013-09-23 15:31 ` GLOB_BRACE Kurt H Maier
2013-09-23 15:54 ` GLOB_BRACE Rich Felker
2013-09-23 17:22 ` GLOB_BRACE Rob Landley
2013-09-23 19:55 ` GLOB_BRACE Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPLrYESKzgNP0dE7xJE+Wo4CYJVQnJxo3PKc2OGmV1NOXO79Lw@mail.gmail.com \
--to=daniel.cegielka@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).