bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Console client, signal handeling patch


From: marco
Subject: Console client, signal handeling patch
Date: Thu, 1 May 2003 01:47:24 +0200 (CEST)

Hi,

This patch makes the console client handle signals like SIGTERM and
SIGSEGV. The signal handler calls console_exit to restore the previous
state, otherwise some hardware state won't be restored when it crashes or
is killed.

I also added a switch, --debug, to disable this handeling for signals that
make the console client coredump because it makes debugging with gdb
difficult. By default it is on (signal handling for those signals).

Can someone with experience with signal handling have a look at this patch
please?

Thanks,
Marco Gerards

2003-05-01  Marco Gerards  <metgerards@student.han.nl>
        * console.c (options): Added option to disable catching of signals
        that can cause a coredump...
        (parse_opt): ...and parse it here.
        (sighandler): New function.
        (handle_signal): New macro.
        (main): Handle signals.

--- console-client/console.c    2002-11-18 08:35:47.000000000 +0100
+++ console-client.mg/console.c 2003-05-01 02:04:00.000000000 +0200
@@ -1,5 +1,5 @@
 /* console.c -- A pluggable console client.
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
    Written by Marcus Brinkmann.

    This program is free software; you can redistribute it and/or
@@ -361,9 +361,14 @@ options[] =
   {
     {"driver-path", 'D', "PATH", 0, "Specify search path for driver
modules" },
     {"driver", 'd', "NAME", 0, "Add driver NAME to the console" },
+    {"debug", 'g', 0, 0, "Don't catch the signals that are used for "
+     "debugging."},
     {0}
   };

+/* Don't catch some signals because that will make debugging difficult.  */
+static int debugging = 0;
+
 /* Parse a command line option.  */
 static error_t
 parse_opt (int key, char *arg, struct argp_state *state)
@@ -409,6 +414,10 @@ parse_opt (int key, char *arg, struct ar
       devcount++;
       break;

+    case 'g':
+      debugging = 1;
+      break;
+
     case ARGP_KEY_SUCCESS:
       if (!devcount)
        {
@@ -429,6 +438,22 @@ static const struct argp_child startup_c
 static struct argp startup_argp = {options, parse_opt, 0,
                                   0, startup_children};

+/* Make sure the old hardware state is restored before the console
+   client is closed.  */
+void
+sighandler (int signal)
+{
+  console_exit ();
+}
+
+/* Catch signal s.  */
+#define handle_signal(sig)                             \
+  if (signal (sig, sighandler) == SIG_ERR)             \
+    {                                                  \
+      driver_fini ();                                  \
+      error (1, errno, "Couldn't set signal handler"); \
+    }
+
 int
 main (int argc, char *argv[])
 {
@@ -440,6 +465,26 @@ main (int argc, char *argv[])
   /* Parse our command line.  This shouldn't ever return an error.  */
   argp_parse (&startup_argp, argc, argv, 0, 0, 0);

+  /* Handle signals that will terminate the console client.  */
+  handle_signal (SIGINT);
+  handle_signal (SIGTERM);
+  handle_signal (SIGHUP);
+
+  /* Handle signals that will make the console client coredump.  */
+  if (!debugging)
+    {
+      handle_signal (SIGQUIT);
+      handle_signal (SIGSEGV);
+      handle_signal (SIGILL);
+      handle_signal (SIGABRT);
+      handle_signal (SIGFPE);
+      handle_signal (SIGSYS);
+      handle_signal (SIGTRAP);
+      handle_signal (SIGURG);
+      handle_signal (SIGXCPU);
+      handle_signal (SIGXFSZ);
+    }
+
   err = driver_start (&errname);
   if (err)
     error (1, err, "Starting driver %s failed", errname);







reply via email to

[Prev in Thread] Current Thread [Next in Thread]