On Monday 12 December 2005 14:20, Blaisorblade wrote: > First, you can say con1=fd:0,fd:1 instead to redirect tty1 to stdin/out, > however you just need to add an entry in inittab for tty0 along with tty1 > and list tty0 in /etc/*securetty* (path varies) to allow root to login from > tty0. Don't use /dev/console as that is very different and has problems > (aka Ctrl-C, Ctrl-Z don't work, for instance).
It's a little more complicated than that. Signals are blocked for PID 1 so Ctrl-C and Ctrl-Z can't ever work for init=/bin/sh. Attached is a dumb little program I use to get around this. Rob -- Steve Ballmer: Innovation! Inigo Montoya: You keep using that word. I do not think it means what you think it means.
/* oneit.c, tiny one-process init replacement. * * Copyright 2005 by Rob Landley. Released under gpl v2. */ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <linux/reboot.h> // The minimum amount of work necessary to get ctrl-c and such to work is: // // - Fork a child (PID 1 is special: can't exit, has various signals blocked). // - Do a setsid() (so we have our own session). // - In the child, attach stdio to /dev/tty0 (/dev/console is special) // - Exec the rest of the command line. // // PID 1 then reaps zombies until the child process it spawned exits, at which // point it calls sync() and reboot(). I could stick a kill -1 in there. int main(int argc, char *argv[]) { int a; pid_t pid; // pid 1 just reaps zombies until it gets its child, then halts the system. pid=fork(); if(pid) { while(pid!=wait()); sync(); reboot(LINUX_REBOOT_CMD_HALT); } // Redirect stdio to /dev/tty0, with new session ID, so ctrl-c works. setsid(); for(a=0;a<3;a++) { close(a); open("/dev/tty0",O_RDWR); } execvp(argv[1],argv+1); dprintf(2,"oneit: Can't exec %s\n",argv[1]); }