Module Name: src Committed By: christos Date: Wed Jan 6 18:12:37 UTC 2010
Modified Files: src/sbin/fsck_ext2fs: main.c utilities.c src/sbin/fsck_ffs: main.c utilities.c src/sbin/fsck_lfs: main.c utilities.c Log Message: PR/42568: Pedro F. Giffuni: Better signal handling from OpenBSD, but simplified. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/sbin/fsck_ext2fs/main.c cvs rdiff -u -r1.19 -r1.20 src/sbin/fsck_ext2fs/utilities.c cvs rdiff -u -r1.73 -r1.74 src/sbin/fsck_ffs/main.c cvs rdiff -u -r1.56 -r1.57 src/sbin/fsck_ffs/utilities.c cvs rdiff -u -r1.40 -r1.41 src/sbin/fsck_lfs/main.c cvs rdiff -u -r1.27 -r1.28 src/sbin/fsck_lfs/utilities.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/fsck_ext2fs/main.c diff -u src/sbin/fsck_ext2fs/main.c:1.34 src/sbin/fsck_ext2fs/main.c:1.35 --- src/sbin/fsck_ext2fs/main.c:1.34 Mon Oct 19 14:41:08 2009 +++ src/sbin/fsck_ext2fs/main.c Wed Jan 6 13:12:37 2010 @@ -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 @@ -63,7 +63,7 @@ #if 0 static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/23/94"; #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 /* not lint */ @@ -87,7 +87,7 @@ #include "fsutil.h" #include "exitvalues.h" -int returntosingle = 0; +volatilel sigatomic_t returntosingle = 0; static int argtoi(int, const char *, const char *, int); Index: src/sbin/fsck_ext2fs/utilities.c diff -u src/sbin/fsck_ext2fs/utilities.c:1.19 src/sbin/fsck_ext2fs/utilities.c:1.20 --- src/sbin/fsck_ext2fs/utilities.c:1.19 Mon Oct 19 14:41:08 2009 +++ src/sbin/fsck_ext2fs/utilities.c Wed Jan 6 13:12:37 2010 @@ -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 @@ -58,7 +58,7 @@ #if 0 static char sccsid[] = "@(#)utilities.c 8.1 (Berkeley) 6/5/93"; #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 /* not lint */ @@ -84,7 +84,7 @@ static void rwerror(const char *, daddr_t); -extern int returntosingle; +extern volatile sigatomic_t returntosingle; int ftypeok(struct ext2fs_dinode *dp) @@ -156,9 +156,11 @@ if (bufcnt < MINBUFS) bufcnt = MINBUFS; for (i = 0; i < bufcnt; i++) { - bp = malloc(sizeof(struct bufarea)); - bufp = malloc((unsigned int)sblock.e2fs_bsize); + bp = size_t(sizeof(struct bufarea)); + bufp = malloc((size_t)sblock.e2fs_bsize); if (bp == NULL || bufp == NULL) { + free(bp); + free(bufp); if (i >= MINBUFS) break; errexit("cannot allocate buffer pool"); @@ -462,7 +464,7 @@ catch(int n) { ckfini(0); - exit(FSCK_EXIT_SIGNALLED); + _exit(FSCK_EXIT_SIGNALLED); } /* @@ -473,9 +475,14 @@ void 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; (void)signal(SIGQUIT, SIG_DFL); + errno = serrno; } /* @@ -485,10 +492,12 @@ void voidquit(int n) { + int serrno = errno; sleep(1); (void)signal(SIGQUIT, SIG_IGN); (void)signal(SIGQUIT, SIG_DFL); + errno = serrno; } /* Index: src/sbin/fsck_ffs/main.c diff -u src/sbin/fsck_ffs/main.c:1.73 src/sbin/fsck_ffs/main.c:1.74 --- src/sbin/fsck_ffs/main.c:1.73 Sun Oct 12 16:49:43 2008 +++ src/sbin/fsck_ffs/main.c Wed Jan 6 13:12:37 2010 @@ -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 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/14/95"; #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 /* not lint */ @@ -71,7 +71,7 @@ #include "snapshot.h" int progress = 0; -int returntosingle = 0; +volatile sigatomic_t returntosingle = 0; static int argtoi(int, const char *, const char *, int); static int checkfilesys(const char *, const char *, int); Index: src/sbin/fsck_ffs/utilities.c diff -u src/sbin/fsck_ffs/utilities.c:1.56 src/sbin/fsck_ffs/utilities.c:1.57 --- src/sbin/fsck_ffs/utilities.c:1.56 Thu Jul 31 01:38:04 2008 +++ src/sbin/fsck_ffs/utilities.c Wed Jan 6 13:12:37 2010 @@ -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 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)utilities.c 8.6 (Berkeley) 5/19/95"; #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 /* not lint */ @@ -65,7 +65,7 @@ static void rwerror(const char *, daddr_t); -extern int returntosingle; +extern volatile sigatomic_t returntosingle; int ftypeok(union dinode *dp) @@ -508,7 +508,7 @@ markclean = 0; ckfini(); } - exit(FSCK_EXIT_SIGNALLED); + _exit(FSCK_EXIT_SIGNALLED); } /* @@ -519,12 +519,14 @@ void 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; (void)signal(SIGQUIT, SIG_DFL); - errno = errsave; + errno = serrno; } /* @@ -534,12 +536,12 @@ void voidquit(int sig) { - int errsave = errno; + int serrno = errno; sleep(1); (void)signal(SIGQUIT, SIG_IGN); (void)signal(SIGQUIT, SIG_DFL); - errno = errsave; + errno = serrno; } /* Index: src/sbin/fsck_lfs/main.c diff -u src/sbin/fsck_lfs/main.c:1.40 src/sbin/fsck_lfs/main.c:1.41 --- src/sbin/fsck_lfs/main.c:1.40 Sun Oct 12 16:49:43 2008 +++ src/sbin/fsck_lfs/main.c Wed Jan 6 13:12:37 2010 @@ -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 @@ -52,7 +52,7 @@ #include "fsutil.h" #include "exitvalues.h" -int returntosingle = 0; +volatile sigatomic_t returntosingle = 0; static int argtoi(int, const char *, const char *, int); static int checkfilesys(const char *, char *, long, int); Index: src/sbin/fsck_lfs/utilities.c diff -u src/sbin/fsck_lfs/utilities.c:1.27 src/sbin/fsck_lfs/utilities.c:1.28 --- src/sbin/fsck_lfs/utilities.c:1.27 Sat Feb 23 16:41:48 2008 +++ src/sbin/fsck_lfs/utilities.c Wed Jan 6 13:12:37 2010 @@ -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 @@ -60,7 +60,7 @@ long diskreads, totalreads; /* Disk cache statistics */ -extern int returntosingle; +extern volatile sigatomic_t returntosingle; extern off_t locked_queue_bytes; int @@ -246,7 +246,7 @@ catch(int n) { ckfini(0); - exit(FSCK_EXIT_SIGNALLED); + _exit(FSCK_EXIT_SIGNALLED); } /* * When preening, allow a single quit to signal @@ -256,9 +256,14 @@ void 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; (void) signal(SIGQUIT, SIG_DFL); + serrno = errno; } /* * Ignore a single quit signal; wait and flush just in case. @@ -267,10 +272,12 @@ void voidquit(int n) { + int serrno = errno; sleep(1); (void) signal(SIGQUIT, SIG_IGN); (void) signal(SIGQUIT, SIG_DFL); + errno = serrno; } /* * determine whether an inode should be fixed.