diff --git a/toolbox/Android.mk b/toolbox/Android.mk index 75ce53f0a..c5890b2c8 100644 --- a/toolbox/Android.mk +++ b/toolbox/Android.mk @@ -69,7 +69,8 @@ TOOLS := \ swapon \ swapoff \ mkswap \ - readlink + readlink \ + nohup ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT))) TOOLS += r diff --git a/toolbox/nohup.c b/toolbox/nohup.c new file mode 100644 index 000000000..363999d0b --- /dev/null +++ b/toolbox/nohup.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +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; +}