$OpenBSD$ --- fghack.c.orig Mon Mar 6 06:21:09 2000 +++ fghack.c Wed Feb 21 21:43:01 2001 @@ -5,9 +5,29 @@ #include "readwrite.h" #include "pathexec.h" #include "exit.h" +#include #define FATAL "fghack: fatal: " +int getpid(void) { + int fd, l; + char pid[16]; + + fd=open_read(getenv("PIDFILE")); + if (fd==-1) + strerr_die2sys(111,FATAL,"unable to open pid file"); + l=read(fd,pid,sizeof(pid)-1); + if (l==-1) + strerr_die2sys(111,FATAL,"unable to read pid file"); + close(fd); + pid[l]=0; + return atoi(pid); +} + +static void sighandler(int i) { + kill(getpid(),i); +} + main(int argc,char **argv,char **envp) { char ch; @@ -18,6 +38,16 @@ if (!argv[1]) strerr_die1x(100,"fghack: usage: fghack child"); + + if (getenv("PIDFILE")) { + signal(SIGTERM,sighandler); + signal(SIGINT,sighandler); + signal(SIGHUP,sighandler); + signal(SIGALRM,sighandler); + signal(SIGSTOP,sighandler); + signal(SIGCONT,sighandler); + signal(SIGKILL,sighandler); + } if (pipe(pi) == -1) strerr_die2sys(111,FATAL,"unable to create pipe: ");