Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin PR/42568: Pedro F. Giffuni: Better signal handling from...
details: https://anonhg.NetBSD.org/src/rev/76727c28937e
branches: trunk
changeset: 750560:76727c28937e
user: christos <christos%NetBSD.org@localhost>
date: Wed Jan 06 18:12:37 2010 +0000
description:
PR/42568: Pedro F. Giffuni: Better signal handling from OpenBSD, but simplified.
diffstat:
sbin/fsck_ext2fs/main.c | 6 +++---
sbin/fsck_ext2fs/utilities.c | 23 ++++++++++++++++-------
sbin/fsck_ffs/main.c | 6 +++---
sbin/fsck_ffs/utilities.c | 20 +++++++++++---------
sbin/fsck_lfs/main.c | 4 ++--
sbin/fsck_lfs/utilities.c | 15 +++++++++++----
6 files changed, 46 insertions(+), 28 deletions(-)
diffs (276 lines):
diff -r d83dc286d325 -r 76727c28937e sbin/fsck_ext2fs/main.c
--- a/sbin/fsck_ext2fs/main.c Wed Jan 06 16:19:07 2010 +0000
+++ b/sbin/fsck_ext2fs/main.c Wed Jan 06 18:12:37 2010 +0000
@@ -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);
diff -r d83dc286d325 -r 76727c28937e sbin/fsck_ext2fs/utilities.c
--- a/sbin/fsck_ext2fs/utilities.c Wed Jan 06 16:19:07 2010 +0000
+++ b/sbin/fsck_ext2fs/utilities.c Wed Jan 06 18:12:37 2010 +0000
@@ -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;
}
/*
diff -r d83dc286d325 -r 76727c28937e sbin/fsck_ffs/main.c
--- a/sbin/fsck_ffs/main.c Wed Jan 06 16:19:07 2010 +0000
+++ b/sbin/fsck_ffs/main.c Wed Jan 06 18:12:37 2010 +0000
@@ -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);
diff -r d83dc286d325 -r 76727c28937e sbin/fsck_ffs/utilities.c
--- a/sbin/fsck_ffs/utilities.c Wed Jan 06 16:19:07 2010 +0000
+++ b/sbin/fsck_ffs/utilities.c Wed Jan 06 18:12:37 2010 +0000
@@ -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;
}
/*
diff -r d83dc286d325 -r 76727c28937e sbin/fsck_lfs/main.c
--- a/sbin/fsck_lfs/main.c Wed Jan 06 16:19:07 2010 +0000
+++ b/sbin/fsck_lfs/main.c Wed Jan 06 18:12:37 2010 +0000
@@ -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);
diff -r d83dc286d325 -r 76727c28937e sbin/fsck_lfs/utilities.c
--- a/sbin/fsck_lfs/utilities.c Wed Jan 06 16:19:07 2010 +0000
+++ b/sbin/fsck_lfs/utilities.c Wed Jan 06 18:12:37 2010 +0000
@@ -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.
Home |
Main Index |
Thread Index |
Old Index