Whamcloud - gitweb
ChangeLog, fsck.c, fsck.h:
authorTheodore Ts'o <tytso@mit.edu>
Wed, 20 Oct 1999 18:11:01 +0000 (18:11 +0000)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 20 Oct 1999 18:11:01 +0000 (18:11 +0000)
  fsck.c (wait_one): If the fsck process just started, wait a second
   before sending a SIGUSR1, to give it a chance to set the signal
   handler; otherwise, fsck will die on an unhandled SIGUSR1.

misc/ChangeLog
misc/fsck.c
misc/fsck.h

index 5bedb96..6a32f4a 100644 (file)
@@ -1,4 +1,11 @@
-1999-09-15    <tytso@rsts-11.mit.edu>
+1999-10-14    <tytso@valinux.com>
+
+       * fsck.c (wait_one): If the fsck process just started, wait a
+               second before sending a SIGUSR1, to give it a chance
+               to set the signal handler; otherwise, fsck will die on an
+               unhandled SIGUSR1.
+
+1999-09-15    <tytso@valinux.com>
 
        * mke2fs.c (show_stats): Fix display bug when printing out the
                number of superblocks.  Suggested by Yann Dirson.
index bea2995..fa1a3da 100644 (file)
@@ -33,6 +33,7 @@
 #include <limits.h>
 #include <stdio.h>
 #include <string.h>
+#include <time.h>
 #if HAVE_STDLIB_H
 #include <stdlib.h>
 #endif
@@ -377,7 +378,7 @@ static int execute(char *type, char *device, char *mntpt, int interactive)
 {
        char *s, *argv[80], prog[80];
        int  argc, i;
-       struct fsck_instance *inst;
+       struct fsck_instance *inst, *p;
        pid_t   pid;
 
        inst = malloc(sizeof(struct fsck_instance));
@@ -433,8 +434,18 @@ static int execute(char *type, char *device, char *mntpt, int interactive)
        inst->prog = string_copy(prog);
        inst->type = string_copy(type);
        inst->device = string_copy(device);
-       inst->next = instance_list;
-       instance_list = inst;
+       inst->start_time = time(0);
+       inst->next = NULL;
+
+       /*
+        * Find the end of the list, so we add the instance on at the end.
+        */
+       for (p = instance_list; p && p->next; p = p->next);
+
+       if (p)
+               p->next = instance_list;
+       else
+               instance_list = inst;
        
        return 0;
 }
@@ -460,31 +471,28 @@ static struct fsck_instance *wait_one(NOARGS)
                return(inst);
        }
 
-retry:
-       pid = wait(&status);
-       if (pid < 0) {
-               if ((errno == EINTR) || (errno == EAGAIN))
-                       goto retry;
-               if (errno == ECHILD) {
-                       fprintf(stderr,
-                               "%s: wait: No more child process?!?\n",
-                               progname);
-                       return NULL;
+       do {
+               pid = wait(&status);
+               if (pid < 0) {
+                       if ((errno == EINTR) || (errno == EAGAIN))
+                               continue;
+                       if (errno == ECHILD) {
+                               fprintf(stderr,
+                                       "%s: wait: No more child process?!?\n",
+                                       progname);
+                               return NULL;
+                       }
+                       perror("wait");
+                       continue;
                }
-               perror("wait");
-               goto retry;
-       }
-       for (prev = 0, inst = instance_list;
-            inst;
-            prev = inst, inst = inst->next) {
-               if (inst->pid == pid)
-                       break;
-       }
-       if (!inst) {
-               printf("Unexpected child process %d, status = 0x%x\n",
-                      pid, status);
-               goto retry;
-       }
+               for (prev = 0, inst = instance_list;
+                    inst;
+                    prev = inst, inst = inst->next) {
+                       if (inst->pid == pid)
+                               break;
+               }
+       } while (!inst);
+
        if (WIFEXITED(status)) 
                status = WEXITSTATUS(status);
        else if (WIFSIGNALED(status)) {
@@ -514,7 +522,19 @@ retry:
                                continue;
                        if (strcmp(inst2->type, "ext2"))
                                continue;
-                       kill(inst2->pid, SIGUSR1);
+                       /*
+                        * If we've just started the fsck, wait a tiny
+                        * bit before sending the kill, to give it
+                        * time to set up the signal handler
+                        */
+                       if (inst2->start_time < time(0)+2) {
+                               if (fork() == 0) {
+                                       sleep(1);
+                                       kill(inst2->pid, SIGUSR1);
+                                       exit(0);
+                               }
+                       } else
+                               kill(inst2->pid, SIGUSR1);
                        break;
                }
        }
index 3efd954..693f9ef 100644 (file)
@@ -49,6 +49,7 @@ struct fsck_instance {
        int     pid;
        int     flags;
        int     exit_status;
+       time_t  start_time;
        char *  prog;
        char *  type;
        char *  device;