Home | History | Annotate | Download | only in toolbox
      1 #include <signal.h>
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 #include <unistd.h>
      5 
      6 int nohup_main(int argc, char *argv[])
      7 {
      8     if (argc < 2) {
      9         fprintf(stderr, "Usage: %s [-n] program args...\n", argv[0]);
     10         return EXIT_FAILURE;
     11     }
     12     signal(SIGHUP, SIG_IGN);
     13     argv++;
     14     if (strcmp(argv[0], "-n") == 0) {
     15         argv++;
     16         signal(SIGINT, SIG_IGN);
     17         signal(SIGSTOP, SIG_IGN);
     18         signal(SIGTTIN, SIG_IGN);
     19         signal(SIGTTOU, SIG_IGN);
     20         signal(SIGQUIT, SIG_IGN);
     21         signal(SIGTERM, SIG_IGN);
     22     }
     23     execvp(argv[0], argv);
     24     perror(argv[0]);
     25     return EXIT_FAILURE;
     26 }
     27