aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2011-11-20 21:13:47 -0600
committerRob Landley <rob@landley.net>2011-11-20 21:13:47 -0600
commit1418fa7b91ec7c4b2ff337541f057f7672f334d5 (patch)
tree5385a5fb43e50d739158bf3822cbc035e65bc3f3
parentc157b4cc656aa938961e03580eec4cfcfc0717a3 (diff)
downloadtoybox-1418fa7b91ec7c4b2ff337541f057f7672f334d5.tar.gz
Implement nohup.
-rw-r--r--toys/nohup.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/toys/nohup.c b/toys/nohup.c
new file mode 100644
index 00000000..ab59c1e2
--- /dev/null
+++ b/toys/nohup.c
@@ -0,0 +1,42 @@
+/* vi: set sw=4 ts=4:
+ *
+ * nohup.c - run commandline with SIGHUP blocked.
+ *
+ * Copyright 2011 Rob Landley <rob@landley.net>
+ *
+ * See http://opengroup.org/onlinepubs/9699919799/utilities/nohup.html
+
+USE_NOHUP(NEWTOY(nohup, "<1", TOYFLAG_USR|TOYFLAG_BIN))
+
+config NOHUP
+ bool "nohup"
+ default y
+ help
+ usage: nohup COMMAND [ARGS...]
+
+ Run a command that survives the end of its terminal.
+ If stdin is a tty, redirect from /dev/null
+ If stdout is a tty, redirect to file "nohup.out"
+*/
+
+#include "toys.h"
+
+void nohup_main(void)
+{
+ signal(SIGHUP, SIG_IGN);
+ if (ttyname(1)) {
+ close(1);
+ if (-1 == open("nohup.out", O_CREAT|O_APPEND|O_WRONLY,
+ S_IRUSR|S_IWUSR ))
+ {
+ char *temp = getenv("HOME");
+ temp = xmsprintf("%s/%s", temp ? temp : "", "nohup.out");
+ xcreate(temp, O_CREAT|O_APPEND|O_WRONLY, S_IRUSR|S_IWUSR);
+ }
+ }
+ if (ttyname(0)) {
+ close(0);
+ open("/dev/null", O_RDONLY);
+ }
+ xexec(toys.optargs);
+}