[PATCH] Reset the terminal state if we are killed by a fatal signal. | |
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] | |
---
disk-utils/fsck.minix.c | 38 ++++++++++++++++++++++++++++++++++----
1 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/disk-utils/fsck.minix.c b/disk-utils/fsck.minix.c
index 4953663..f800af4 100644
--- a/disk-utils/fsck.minix.c
+++ b/disk-utils/fsck.minix.c
@@ -65,6 +65,10 @@
* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@xxxxxxxxxx>
* - added Native Language Support
*
+ * 2008-04-06 James Youngman <jay@xxxxxxx>
+ * - Issue better error message if we fail to open the device.
+ * - Restore terminal state if we get a fatal signal.
+ *
*
* I've had no time to add comments - hopefully the function names
* are comments enough. As with all file system checkers, this assumes
@@ -96,6 +100,7 @@
#include <termios.h>
#include <mntent.h>
#include <sys/stat.h>
+#include <signal.h>
#include "minix.h"
#include "nls.h"
@@ -128,8 +133,8 @@ static int errors_uncorrected = 0; /* flag if some error was not corrected */
static int dirsize = 16;
static int namelen = 14;
static int version2 = 0;
-static struct termios termios;
-static int termios_set = 0;
+static volatile struct termios termios;
+static volatile sig_atomic_t termios_set = 0;
/* File-name data */
#define MAX_DEPTH 50
@@ -174,10 +179,28 @@ static void recursive_check2(unsigned int ino);
#define mark_zone(x) (setbit(zone_map,(x)-FIRSTZONE+1),changed=1)
#define unmark_zone(x) (clrbit(zone_map,(x)-FIRSTZONE+1),changed=1)
-static void
-leave(int status) {
+
+static void reset(void) {
if (termios_set)
tcsetattr(0, TCSANOW, &termios);
+}
+
+
+static void
+fatalsig(int sig) {
+ /* We received a fatal signal. Reset the terminal.
+ * Also reset the signal handler and re-send the signal,
+ * so that the parent process knows which signal actually
+ * caused our death.
+ */
+ signal(sig, SIG_DFL);
+ reset();
+ raise(sig);
+}
+
+static void
+leave(int status) {
+ reset();
exit(status);
}
@@ -1316,6 +1339,13 @@ main(int argc, char ** argv) {
read_tables();
+ /* Restore the terminal state on fatal signals.
+ * We don't do this for SIGALRM, SIGUSR1 or SIGUSR2.
+ */
+ signal(SIGINT, fatalsig);
+ signal(SIGQUIT, fatalsig);
+ signal(SIGTERM, fatalsig);
+
if (repair && !automatic) {
tcgetattr(0,&termios);
tmp = termios;
--
1.5.3.8
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
[Site Home] [Netdev] [Ethernet Bridging] [Linux Wireless] [Kernel Newbies] [Memory] [Security] [Linux for Hams] [Netfilter] [Bugtraq] [Rubini] [Photo] [Yosemite] [Yosemite News] [MIPS Linux] [ARM Linux] [Linux RAID] [Linux Admin] [Samba] [Video 4 Linux] [Linux Resources]