summaryrefslogtreecommitdiff
path: root/dpid
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2010-02-08 12:24:39 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2010-02-08 12:24:39 +0100
commit21e6f39bdaea191e0aa043c4c4e09b12e5598a3d (patch)
tree8f237f70d8abcda868c81733841f481e3e9f4897 /dpid
parent3af2054b6397df4cf32042f7c4d57454164d4a4e (diff)
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
Diffstat (limited to 'dpid')
-rw-r--r--dpid/dpid.c43
-rw-r--r--dpid/dpid.h2
-rw-r--r--dpid/main.c2
3 files changed, 23 insertions, 24 deletions
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);
diff --git a/dpid/dpid.h b/dpid/dpid.h
index 0cf89406..8ef67dd5 100644
--- a/dpid/dpid.h
+++ b/dpid/dpid.h
@@ -98,6 +98,8 @@ void handle_sigchld(void);
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);
diff --git a/dpid/main.c b/dpid/main.c
index 494f9dbc..5f512245 100644
--- a/dpid/main.c
+++ b/dpid/main.c
@@ -265,7 +265,7 @@ int main(void)
}
}
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);