nohup.c revision 59d85e2bb065a3bdc27868acb7a65f89d872c7fa
1/* nohup.c - run commandline with SIGHUP blocked. 2 * 3 * Copyright 2011 Rob Landley <rob@landley.net> 4 * 5 * See http://opengroup.org/onlinepubs/9699919799/utilities/nohup.html 6 7USE_NOHUP(NEWTOY(nohup, "<1", TOYFLAG_USR|TOYFLAG_BIN)) 8 9config NOHUP 10 bool "nohup" 11 default y 12 help 13 usage: nohup COMMAND [ARGS...] 14 15 Run a command that survives the end of its terminal. 16 If stdin is a tty, redirect from /dev/null 17 If stdout is a tty, redirect to file "nohup.out" 18*/ 19 20#include "toys.h" 21 22void nohup_main(void) 23{ 24 signal(SIGHUP, SIG_IGN); 25 if (isatty(1)) { 26 close(1); 27 if (-1 == open("nohup.out", O_CREAT|O_APPEND|O_WRONLY, 28 S_IRUSR|S_IWUSR )) 29 { 30 char *temp = getenv("HOME"); 31 temp = xmprintf("%s/%s", temp ? temp : "", "nohup.out"); 32 xcreate(temp, O_CREAT|O_APPEND|O_WRONLY, S_IRUSR|S_IWUSR); 33 } 34 } 35 if (isatty(0)) { 36 close(0); 37 open("/dev/null", O_RDONLY); 38 } 39 xexec_optargs(0); 40} 41