PR/42568: Pedro F. Giffuni: Better signal handling from OpenBSD, but simplified.

This commit is contained in:
christos 2010-01-06 18:12:37 +00:00
parent 1b91b7e11c
commit 87e82597b6
6 changed files with 46 additions and 28 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.34 2009/10/19 18:41:08 bouyer Exp $ */ /* $NetBSD: main.c,v 1.35 2010/01/06 18:12:37 christos Exp $ */
/* /*
* Copyright (c) 1980, 1986, 1993 * Copyright (c) 1980, 1986, 1993
@ -63,7 +63,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1993\
#if 0 #if 0
static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/23/94"; static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/23/94";
#else #else
__RCSID("$NetBSD: main.c,v 1.34 2009/10/19 18:41:08 bouyer Exp $"); __RCSID("$NetBSD: main.c,v 1.35 2010/01/06 18:12:37 christos Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -87,7 +87,7 @@ __RCSID("$NetBSD: main.c,v 1.34 2009/10/19 18:41:08 bouyer Exp $");
#include "fsutil.h" #include "fsutil.h"
#include "exitvalues.h" #include "exitvalues.h"
int returntosingle = 0; volatilel sigatomic_t returntosingle = 0;
static int argtoi(int, const char *, const char *, int); static int argtoi(int, const char *, const char *, int);

View File

@ -1,4 +1,4 @@
/* $NetBSD: utilities.c,v 1.19 2009/10/19 18:41:08 bouyer Exp $ */ /* $NetBSD: utilities.c,v 1.20 2010/01/06 18:12:37 christos Exp $ */
/* /*
* Copyright (c) 1980, 1986, 1993 * Copyright (c) 1980, 1986, 1993
@ -58,7 +58,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)utilities.c 8.1 (Berkeley) 6/5/93"; static char sccsid[] = "@(#)utilities.c 8.1 (Berkeley) 6/5/93";
#else #else
__RCSID("$NetBSD: utilities.c,v 1.19 2009/10/19 18:41:08 bouyer Exp $"); __RCSID("$NetBSD: utilities.c,v 1.20 2010/01/06 18:12:37 christos Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -84,7 +84,7 @@ long diskreads, totalreads; /* Disk cache statistics */
static void rwerror(const char *, daddr_t); static void rwerror(const char *, daddr_t);
extern int returntosingle; extern volatile sigatomic_t returntosingle;
int int
ftypeok(struct ext2fs_dinode *dp) ftypeok(struct ext2fs_dinode *dp)
@ -156,9 +156,11 @@ bufinit(void)
if (bufcnt < MINBUFS) if (bufcnt < MINBUFS)
bufcnt = MINBUFS; bufcnt = MINBUFS;
for (i = 0; i < bufcnt; i++) { for (i = 0; i < bufcnt; i++) {
bp = malloc(sizeof(struct bufarea)); bp = size_t(sizeof(struct bufarea));
bufp = malloc((unsigned int)sblock.e2fs_bsize); bufp = malloc((size_t)sblock.e2fs_bsize);
if (bp == NULL || bufp == NULL) { if (bp == NULL || bufp == NULL) {
free(bp);
free(bufp);
if (i >= MINBUFS) if (i >= MINBUFS)
break; break;
errexit("cannot allocate buffer pool"); errexit("cannot allocate buffer pool");
@ -462,7 +464,7 @@ void
catch(int n) catch(int n)
{ {
ckfini(0); ckfini(0);
exit(FSCK_EXIT_SIGNALLED); _exit(FSCK_EXIT_SIGNALLED);
} }
/* /*
@ -473,9 +475,14 @@ catch(int n)
void void
catchquit(int n) catchquit(int n)
{ {
printf("returning to single-user after filesystem check\n"); static const char msg[] =
"returning to single-user after filesystem check\n";
int serrno = errno;
(void)write(STDOUT_FILENO, msg, sizeof(msg) - 1);
returntosingle = 1; returntosingle = 1;
(void)signal(SIGQUIT, SIG_DFL); (void)signal(SIGQUIT, SIG_DFL);
errno = serrno;
} }
/* /*
@ -485,10 +492,12 @@ catchquit(int n)
void void
voidquit(int n) voidquit(int n)
{ {
int serrno = errno;
sleep(1); sleep(1);
(void)signal(SIGQUIT, SIG_IGN); (void)signal(SIGQUIT, SIG_IGN);
(void)signal(SIGQUIT, SIG_DFL); (void)signal(SIGQUIT, SIG_DFL);
errno = serrno;
} }
/* /*

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.73 2008/10/12 20:49:43 wiz Exp $ */ /* $NetBSD: main.c,v 1.74 2010/01/06 18:12:37 christos Exp $ */
/* /*
* Copyright (c) 1980, 1986, 1993 * Copyright (c) 1980, 1986, 1993
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1993\
#if 0 #if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/14/95"; static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/14/95";
#else #else
__RCSID("$NetBSD: main.c,v 1.73 2008/10/12 20:49:43 wiz Exp $"); __RCSID("$NetBSD: main.c,v 1.74 2010/01/06 18:12:37 christos Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -71,7 +71,7 @@ __RCSID("$NetBSD: main.c,v 1.73 2008/10/12 20:49:43 wiz Exp $");
#include "snapshot.h" #include "snapshot.h"
int progress = 0; int progress = 0;
int returntosingle = 0; volatile sigatomic_t returntosingle = 0;
static int argtoi(int, const char *, const char *, int); static int argtoi(int, const char *, const char *, int);
static int checkfilesys(const char *, const char *, int); static int checkfilesys(const char *, const char *, int);

View File

@ -1,4 +1,4 @@
/* $NetBSD: utilities.c,v 1.56 2008/07/31 05:38:04 simonb Exp $ */ /* $NetBSD: utilities.c,v 1.57 2010/01/06 18:12:37 christos Exp $ */
/* /*
* Copyright (c) 1980, 1986, 1993 * Copyright (c) 1980, 1986, 1993
@ -34,7 +34,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)utilities.c 8.6 (Berkeley) 5/19/95"; static char sccsid[] = "@(#)utilities.c 8.6 (Berkeley) 5/19/95";
#else #else
__RCSID("$NetBSD: utilities.c,v 1.56 2008/07/31 05:38:04 simonb Exp $"); __RCSID("$NetBSD: utilities.c,v 1.57 2010/01/06 18:12:37 christos Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -65,7 +65,7 @@ long diskreads, totalreads; /* Disk cache statistics */
static void rwerror(const char *, daddr_t); static void rwerror(const char *, daddr_t);
extern int returntosingle; extern volatile sigatomic_t returntosingle;
int int
ftypeok(union dinode *dp) ftypeok(union dinode *dp)
@ -508,7 +508,7 @@ catch(int sig)
markclean = 0; markclean = 0;
ckfini(); ckfini();
} }
exit(FSCK_EXIT_SIGNALLED); _exit(FSCK_EXIT_SIGNALLED);
} }
/* /*
@ -519,12 +519,14 @@ catch(int sig)
void void
catchquit(int sig) catchquit(int sig)
{ {
int errsave = errno; static const char msg[] =
"returning to single-user after file system check\n";
int serrno = errno;
printf("returning to single-user after file system check\n"); (void)write(STDOUT_FILENO, msg, sizeof(msg) - 1);
returntosingle = 1; returntosingle = 1;
(void)signal(SIGQUIT, SIG_DFL); (void)signal(SIGQUIT, SIG_DFL);
errno = errsave; errno = serrno;
} }
/* /*
@ -534,12 +536,12 @@ catchquit(int sig)
void void
voidquit(int sig) voidquit(int sig)
{ {
int errsave = errno; int serrno = errno;
sleep(1); sleep(1);
(void)signal(SIGQUIT, SIG_IGN); (void)signal(SIGQUIT, SIG_IGN);
(void)signal(SIGQUIT, SIG_DFL); (void)signal(SIGQUIT, SIG_DFL);
errno = errsave; errno = serrno;
} }
/* /*

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.40 2008/10/12 20:49:43 wiz Exp $ */ /* $NetBSD: main.c,v 1.41 2010/01/06 18:12:37 christos Exp $ */
/* /*
* Copyright (c) 1980, 1986, 1993 * Copyright (c) 1980, 1986, 1993
@ -52,7 +52,7 @@
#include "fsutil.h" #include "fsutil.h"
#include "exitvalues.h" #include "exitvalues.h"
int returntosingle = 0; volatile sigatomic_t returntosingle = 0;
static int argtoi(int, const char *, const char *, int); static int argtoi(int, const char *, const char *, int);
static int checkfilesys(const char *, char *, long, int); static int checkfilesys(const char *, char *, long, int);

View File

@ -1,4 +1,4 @@
/* $NetBSD: utilities.c,v 1.27 2008/02/23 21:41:48 christos Exp $ */ /* $NetBSD: utilities.c,v 1.28 2010/01/06 18:12:37 christos Exp $ */
/* /*
* Copyright (c) 1980, 1986, 1993 * Copyright (c) 1980, 1986, 1993
@ -60,7 +60,7 @@
long diskreads, totalreads; /* Disk cache statistics */ long diskreads, totalreads; /* Disk cache statistics */
extern int returntosingle; extern volatile sigatomic_t returntosingle;
extern off_t locked_queue_bytes; extern off_t locked_queue_bytes;
int int
@ -246,7 +246,7 @@ void
catch(int n) catch(int n)
{ {
ckfini(0); ckfini(0);
exit(FSCK_EXIT_SIGNALLED); _exit(FSCK_EXIT_SIGNALLED);
} }
/* /*
* When preening, allow a single quit to signal * When preening, allow a single quit to signal
@ -256,9 +256,14 @@ catch(int n)
void void
catchquit(int n) catchquit(int n)
{ {
printf("returning to single-user after filesystem check\n"); static const char msg[] =
"returning to single-user after filesystem check\n";
int serrno = errno;
(void)write(STDOUT_FILENO, msg, sizeof(msg) - 1);
returntosingle = 1; returntosingle = 1;
(void) signal(SIGQUIT, SIG_DFL); (void) signal(SIGQUIT, SIG_DFL);
serrno = errno;
} }
/* /*
* Ignore a single quit signal; wait and flush just in case. * Ignore a single quit signal; wait and flush just in case.
@ -267,10 +272,12 @@ catchquit(int n)
void void
voidquit(int n) voidquit(int n)
{ {
int serrno = errno;
sleep(1); sleep(1);
(void) signal(SIGQUIT, SIG_IGN); (void) signal(SIGQUIT, SIG_IGN);
(void) signal(SIGQUIT, SIG_DFL); (void) signal(SIGQUIT, SIG_DFL);
errno = serrno;
} }
/* /*
* determine whether an inode should be fixed. * determine whether an inode should be fixed.