minit

A small yet feature-complete init (http://fefe.de/minit/)
Log | Files | Refs | README | LICENSE

commit b312feed09106e1d9b36555f1324ebe882c04253
parent 6859dc5cbfb546ab81b751883e3b1fdf63eb1602
Author: leitner <leitner>
Date:   Tue, 27 May 2003 10:57:14 +0000

opendevconsole

Diffstat:
MMakefile | 5+++--
Mminit.c | 12++----------
Aopendevconsole.c | 12++++++++++++
Mshutdown.c | 7++++++-
4 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/Makefile b/Makefile @@ -8,7 +8,7 @@ CROSS= #CROSS=arm-linux- LDFLAGS=-s -minit: minit.o split.o openreadclose.o fmt_ulong.o str_len.o +minit: minit.o split.o openreadclose.o fmt_ulong.o str_len.o opendevconsole.o $(DIET) $(CROSS)$(CC) $(LDFLAGS) -o minit $^ msvc: msvc.o fmt_ulong.o buffer_1.o buffer_2.o buffer_puts.o \ @@ -17,7 +17,7 @@ buffer_flush.o buffer_stubborn.o buffer_putflush.o str_len.o \ str_start.o $(DIET) $(CROSS)$(CC) $(LDFLAGS) -o msvc $^ -shutdown: shutdown.o split.o openreadclose.o +shutdown: shutdown.o split.o openreadclose.o opendevconsole.o $(DIET) $(CROSS)$(CC) $(LDFLAGS) -o shutdown $^ %.o: %.c @@ -86,3 +86,4 @@ str_len.o: str_len.c str.h str_start.o: str_start.c str.h t.o: t.c write_proc.o: write_proc.c +opendevconsole.o: opendevconsole.c diff --git a/minit.c b/minit.c @@ -24,6 +24,8 @@ #undef printf extern int printf(const char *format,...); +extern void opendevconsole(); + static int i_am_init; static int infd,outfd; @@ -164,16 +166,6 @@ void handlekilled(pid_t killed) { } } -void opendevconsole() { - 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); - } -} - /* called from inside the service directory, return the PID or 0 on error */ pid_t forkandexec(int pause,int service) { char **argv=0; diff --git a/opendevconsole.c b/opendevconsole.c @@ -0,0 +1,12 @@ +#include <fcntl.h> +#include <unistd.h> + +void opendevconsole() { + 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); + } +} diff --git a/shutdown.c b/shutdown.c @@ -41,6 +41,8 @@ static inline int __write2(const char*s) { return write(2,s,strlen(s)); } #define MINITROOT "/etc/minit" #endif +extern void opendevcolsone(); + extern char **environ; extern int openreadclose(char *fn, char **buf, unsigned long *len); extern char **split(char *buf,int c,int *len,int plus,int ofs); @@ -106,13 +108,14 @@ int minit_serviceDown(char *service) { } if (strcmp("reboot",service) && strcmp("halt",service) && pid > 1) { + int i; __write2("\t--> "); __write2(service); buf[0]='r'; // we want to disable respawning first strncpy(buf+1, service, 1400); buf[1400]=0; write(infd, buf, strlen(buf)); read(outfd, buf, 1500); - int i=kill(pid, SIGTERM); + i=kill(pid, SIGTERM); if (i == 0) __write2("\t\tdone\n"); else __write2("\t\tfailed\n"); } @@ -200,6 +203,8 @@ int main(int argc, char *const argv[]) { } } + opendevconsole(); + switch (cfg_downlevel) { case 0: wall("system is going down for reboot NOW\n");