changeset 1550:3a159d7e5098

remove ~/.dillo/dpid_comm_keys on exit of dpid This avoids that dillo instances connect to stale ports after dpid is no longer running (e.g. after a reboot). This is mainly a problem if the machine is configured to silently ignore connection attempts to unused ports (net.inet.tcp.blackhole=1 on *BSD). http://lists.auriga.wearlab.de/pipermail/dillo-dev/2010-January/007247.html
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Mon, 08 Feb 2010 12:24:39 +0100
parents d58d05e37264
children 3cc3dd19e50d
files dpid/dpid.c dpid/dpid.h dpid/main.c
diffstat 3 files changed, 23 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/dpid/dpid.c	Thu Feb 04 04:19:29 2010 +0000
+++ b/dpid/dpid.c	Mon Feb 08 12:24:39 2010 +0100
@@ -41,11 +41,16 @@
 volatile sig_atomic_t caught_sigchld = 0;
 char *SharedKey = NULL;
 
-/*! Remove UDS filenames 
+/*! Remove dpid_comm_keys file.
+ * This avoids that dillo instances connect to a stale port after dpid
+ * has exited (e.g. after a reboot).
  */
 void cleanup()
 {
-
+   char *fname;
+   fname = dStrconcat(dGethomedir(), "/", dotDILLO_DPID_COMM_KEYS, NULL);
+   unlink(fname);
+   dFree(fname);
 }
 
 /*! Free memory used to describe
@@ -94,34 +99,27 @@
    dList_free(s_list);
 }
 
-/*! \todo
- * Remove terminator and est_terminator unless we really want to clean up
- * on abnormal exit.
- */
-#if 0
 /*! Signal handler for SIGINT, SIGQUIT, and SIGTERM. Calls cleanup
+ * \todo what is the most portable way to ignore the signo argument of
+ *       without generating a warning? Is "int signo __unused" gcc specific?
  */
-void terminator(int sig)
+static void terminator()
 {
-   (void) signal(SIGCHLD, SIG_DFL);
    cleanup();
-   (void) signal(sig, SIG_DFL);
-   (void) raise(sig);
    _exit(0);
 }
 
 /*! Establish handler for termination signals
  * and register cleanup with atexit */
-void est_terminator(void)
+void est_dpi_terminator()
 {
    struct sigaction act;
    sigset_t block;
 
-   (void) sigemptyset(&block);
-   (void) sigaddset(&block, SIGINT);
-   (void) sigaddset(&block, SIGQUIT);
-   (void) sigaddset(&block, SIGTERM);
-   (void) sigaddset(&block, SIGSEGV);
+   sigemptyset(&block);
+   sigaddset(&block, SIGINT);
+   sigaddset(&block, SIGQUIT);
+   sigaddset(&block, SIGTERM);
 
    act.sa_handler = terminator;
    act.sa_mask = block;
@@ -129,18 +127,17 @@
 
    if (sigaction(SIGINT, &act, NULL) ||
        sigaction(SIGQUIT, &act, NULL) ||
-       sigaction(SIGTERM, &act, NULL) || sigaction(SIGSEGV, &act, NULL)) {
-      ERRMSG("est_terminator", "sigaction", errno);
+       sigaction(SIGTERM, &act, NULL)) {
+      ERRMSG("est_dpi_terminator", "sigaction", errno);
       exit(1);
    }
 
    if (atexit(cleanup) != 0) {
-      ERRMSG("est_terminator", "atexit", 0);
+      ERRMSG("est_dpi_terminator", "atexit", 0);
       MSG_ERR("Hey! atexit failed, how did that happen?\n");
       exit(1);
    }
 }
-#endif
 
 /*! Identify a given file
  * Currently there is only one file type associated with dpis.
@@ -587,8 +584,8 @@
  */
 int save_comm_keys(int srs_port)
 {
-   int fd;
-   char *fname, ret = -1, port_str[32];
+   int fd, ret = -1;
+   char *fname, port_str[32];
 
    fname = dStrconcat(dGethomedir(), "/", dotDILLO_DPID_COMM_KEYS, NULL);
    fd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
--- a/dpid/dpid.h	Thu Feb 04 04:19:29 2010 +0000
+++ b/dpid/dpid.h	Mon Feb 08 12:24:39 2010 +0100
@@ -98,6 +98,8 @@
 
 void est_dpi_sigchld(void);
 
+void est_dpi_terminator(void);
+
 void stop_active_dpis(struct dp *dpi_attr_list, int numdpis);
 
 void ignore_dpi_sockets(struct dp *dpi_attr_list, int numdpis);
--- a/dpid/main.c	Thu Feb 04 04:19:29 2010 +0000
+++ b/dpid/main.c	Mon Feb 08 12:24:39 2010 +0100
@@ -265,7 +265,7 @@
       }
    }
    numsocks = init_all_dpi_sockets(dpi_attr_list);
-   //est_terminator(); /* Do we still want to clean up on an abnormal exit? */
+   est_dpi_terminator();
    est_dpi_sigchld();
 
    (void) sigemptyset(&mask_sigchld);