summaryrefslogtreecommitdiffstats
path: root/toolbox/nohup.c
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2013-09-23 15:10:12 -0700
committerDmitry Shmidt <dimitrysh@google.com>2013-09-23 15:37:55 -0700
commit3707e7ff03a4240c8603f2d2e1d0b69fe7994cb9 (patch)
tree44ba8698d54a1203bd278fab8c1b721eebed55f0 /toolbox/nohup.c
parent4676550b5684da8355f9ee0b2db964005ce9ea4f (diff)
downloadsystem_core-3707e7ff03a4240c8603f2d2e1d0b69fe7994cb9.zip
system_core-3707e7ff03a4240c8603f2d2e1d0b69fe7994cb9.tar.gz
system_core-3707e7ff03a4240c8603f2d2e1d0b69fe7994cb9.tar.bz2
toolbox: Add nohup command
Change-Id: I2f7d9934b54d98886d7a6205ea122d9ce91066ec Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
Diffstat (limited to 'toolbox/nohup.c')
-rw-r--r--toolbox/nohup.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/toolbox/nohup.c b/toolbox/nohup.c
new file mode 100644
index 0000000..363999d
--- /dev/null
+++ b/toolbox/nohup.c
@@ -0,0 +1,26 @@
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int nohup_main(int argc, char *argv[])
+{
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s [-n] program args...\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+ signal(SIGHUP, SIG_IGN);
+ argv++;
+ if (strcmp(argv[0], "-n") == 0) {
+ argv++;
+ signal(SIGINT, SIG_IGN);
+ signal(SIGSTOP, SIG_IGN);
+ signal(SIGTTIN, SIG_IGN);
+ signal(SIGTTOU, SIG_IGN);
+ signal(SIGQUIT, SIG_IGN);
+ signal(SIGTERM, SIG_IGN);
+ }
+ execvp(argv[0], argv);
+ perror(argv[0]);
+ return EXIT_FAILURE;
+}