summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>1999-10-20 18:11:01 +0000
committerTheodore Ts'o <tytso@mit.edu>1999-10-20 18:11:01 +0000
commit7f4bb6c6e832b38b8e52b4bcc143f99a4059dcec (patch)
tree05a7f766273a4995c3044cce6b859d24c7985e03
parent7671433a9daad089af037f84b365d640e1adf252 (diff)
downloade2fsprogs-7f4bb6c6e832b38b8e52b4bcc143f99a4059dcec.tar.gz
ChangeLog, fsck.c, fsck.h:
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.
-rw-r--r--misc/ChangeLog9
-rw-r--r--misc/fsck.c76
-rw-r--r--misc/fsck.h1
3 files changed, 57 insertions, 29 deletions
diff --git a/misc/ChangeLog b/misc/ChangeLog
index 5bedb964..6a32f4ac 100644
--- a/misc/ChangeLog
+++ b/misc/ChangeLog
@@ -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.
diff --git a/misc/fsck.c b/misc/fsck.c
index bea2995a..fa1a3dad 100644
--- a/misc/fsck.c
+++ b/misc/fsck.c
@@ -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;
}
}
diff --git a/misc/fsck.h b/misc/fsck.h
index 3efd9541..693f9efd 100644
--- a/misc/fsck.h
+++ b/misc/fsck.h
@@ -49,6 +49,7 @@ struct fsck_instance {
int pid;
int flags;
int exit_status;
+ time_t start_time;
char * prog;
char * type;
char * device;