-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.
#include <limits.h>
#include <stdio.h>
#include <string.h>
+#include <time.h>
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
{
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));
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;
}
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)) {
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;
}
}