minit

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

commit 846d6fab1b58572eb32f6f944c55c312704b2ab0
parent 87a5da152561c040bbfe5fe9e71c0ab5865fcab2
Author: leitner <leitner>
Date:   Mon, 28 Apr 2003 11:19:44 +0000

add contributed killall5 and ctrlaltdel-run script

Diffstat:
MCHANGES | 5+++++
MMakefile | 7+++++--
Acontrib/ctrlaltdel-run | 30++++++++++++++++++++++++++++++
Akillall5.c | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 108 insertions(+), 2 deletions(-)

diff --git a/CHANGES b/CHANGES @@ -1,3 +1,8 @@ +0.10: + add sample script for /etc/minit/ctrlaltdel/run as + control/ctrlaltdel-run (Florian Westphal) + add killall5, needs /proc on Linux though (Florian Westphal) + 0.9.1: fix embarassing typo in msvc (Gelu G. Lupas) diff --git a/Makefile b/Makefile @@ -1,4 +1,4 @@ -all: minit msvc pidfilehack hard-reboot write_proc +all: minit msvc pidfilehack hard-reboot write_proc killall5 #CFLAGS=-pipe -march=i386 -fomit-frame-pointer -Os -I../dietlibc/include DIET=diet @@ -21,7 +21,7 @@ str_start.o $(DIET) $(CROSS)$(CC) $(CFLAGS) -c $^ clean: - rm -f *.o minit msvc pidfilehack hard-reboot write_proc + rm -f *.o minit msvc pidfilehack hard-reboot write_proc killall5 test: test.c gcc -nostdlib -o $@ $^ -I../dietlibc/include ../dietlibc/start.o ../dietlibc/dietlibc.a @@ -35,6 +35,9 @@ hard-reboot: hard-reboot.c write_proc: write_proc.c $(DIET) $(CROSS)$(CC) $(CFLAGS) -o $@ $^ +killall5: killall5.c + $(DIET) $(CROSS)$(CC) $(CFLAGS) -o $@ $^ + install-files: install minit pidfilehack $(DESTDIR)/sbin install write_proc hard-reboot $(DESTDIR)/sbin diff --git a/contrib/ctrlaltdel-run b/contrib/ctrlaltdel-run @@ -0,0 +1,30 @@ +#!/bin/sh + +# if umount -a fails give services additional time to shut down +fail(){ +echo umount failed, try again. +sleep 1 +sync +umount -a || sleep 3 +} + +# Shut down "respawn" services - except getty/1. +for i in `find /etc/minit -type f -name respawn | sed 's@/respawn$@@' | grep -v ^/etc/minit/getty/1$`;do + msvc -d "$i" +done + +#send sigterm to all processes. +/sbin/killall5 -15 + +#send sighup to all processes. +/sbin/killall5 -1 + +sync +# umount everything, mount "/" readonly +/bin/umount -a || fail +/sbin/swapoff -a + +# power down. +# params should contain one of "RESTART", "HALT" or "POWER_OFF" +exec /sbin/hard-reboot $1 + diff --git a/killall5.c b/killall5.c @@ -0,0 +1,68 @@ +/* + +killall5 -- send a signal to all processes. + +killall5 is the SystemV killall command. It sends a signal +to all processes except init(PID 1) and the processes in its +own session, so it won't kill the shell that is running the +script it was called from. Its primary (only) use is in the rc +scripts found in the /etc/init.d directory. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version +2 of the License, or (at your option) any later version. + +*/ + +#include <dirent.h> +#include <signal.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> + +#define USAGE "Usage: killall5 SIGNAL\n" +#define NOPROC "No processes found - /proc not mounted?\n" + +int main(int argc, char **argv) +{ + struct dirent *dir; + DIR *dirstream; + register pid_t pid, sid, mypid, mysid; + int signal=-1; + unsigned int sig_sent=0; + + if (argc == 2) { + if (argv[1][0] == '-') argv[1]++; + signal=atoi(argv[1]); + } + + if ( (signal < 1) || ( signal > 31) ) { write(2,USAGE,sizeof USAGE - 1); return 1; } + + + kill(-1,SIGSTOP); + + if ( (dirstream=opendir("/proc"))) { + + mypid=getpid(); + mysid=getsid(0); + + while ( (dir=readdir(dirstream))){ + pid=atoi(dir->d_name); + + if (pid > 1 ){ + sig_sent=1; + sid=getsid(pid); + if ( (pid != mypid) && + ( sid !=mysid)) kill(pid,signal); + } + } + } + + kill(-1,SIGCONT); + if (!sig_sent) { write(2,NOPROC, sizeof NOPROC -1); return 1; } + +return 0; +} +