From 21e6f39bdaea191e0aa043c4c4e09b12e5598a3d Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 8 Feb 2010 12:24:39 +0100 Subject: 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 --- dpid/dpid.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'dpid/dpid.c') diff --git a/dpid/dpid.c b/dpid/dpid.c index 33c6c31c..b0ca8420 100644 --- a/dpid/dpid.c +++ b/dpid/dpid.c @@ -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 @@ void free_services_list(Dlist *s_list) 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 @@ void est_terminator(void) 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 bind_socket_fd(int base_port, int *p_port) */ 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); -- cgit v1.2.3