Browse Source

restart even after normal termination

David Rose 23 years ago
parent
commit
999fc0c6b4
1 changed files with 8 additions and 3 deletions
  1. 8 3
      direct/src/autorestart/autorestart.c

+ 8 - 3
direct/src/autorestart/autorestart.c

@@ -38,6 +38,7 @@
 char **params = NULL;
 char **params = NULL;
 char *logfile_name = NULL;
 char *logfile_name = NULL;
 int logfile_fd = -1;
 int logfile_fd = -1;
+int stop_on_terminate = 0;
 
 
 pid_t child_pid = 0;
 pid_t child_pid = 0;
 
 
@@ -104,13 +105,13 @@ spawn_process() {
     fprintf(stderr, "\nprocess caught signal %d.\n\n", signal);
     fprintf(stderr, "\nprocess caught signal %d.\n\n", signal);
     /* A signal exit is a reason to respawn unless the signal is TERM
     /* A signal exit is a reason to respawn unless the signal is TERM
        or KILL. */
        or KILL. */
-    return (signal != SIGTERM && signal != SIGKILL);
+    return !stop_on_terminate || (signal != SIGTERM && signal != SIGKILL);
 
 
   } else {
   } else {
     int exit_status = WEXITSTATUS(status);
     int exit_status = WEXITSTATUS(status);
     fprintf(stderr, "\nprocess exited with status %d.\n\n", WEXITSTATUS(status));
     fprintf(stderr, "\nprocess exited with status %d.\n\n", WEXITSTATUS(status));
     /* Normal exit is a reason to respawn if the status indicates failure. */
     /* Normal exit is a reason to respawn if the status indicates failure. */
-    return (exit_status != 0);
+    return !stop_on_terminate || (exit_status != 0);
   }
   }
 }
 }
 
 
@@ -287,7 +288,7 @@ main(int argc, char *argv[]) {
   extern char *optarg;
   extern char *optarg;
   extern int optind;
   extern int optind;
   /* The initial '+' instructs GNU getopt not to reorder switches. */
   /* The initial '+' instructs GNU getopt not to reorder switches. */
-  static const char *optflags = "+l:h";
+  static const char *optflags = "+l:th";
   int flag;
   int flag;
 
 
   flag = getopt(argc, argv, optflags);
   flag = getopt(argc, argv, optflags);
@@ -297,6 +298,10 @@ main(int argc, char *argv[]) {
       logfile_name = optarg;
       logfile_name = optarg;
       break;
       break;
 
 
+    case 't':
+      stop_on_terminate = 1;
+      break;
+
     case 'h':
     case 'h':
       help();
       help();
       return 1;
       return 1;