From f43143bd0fdd39a29f84f045c65f76a41dbe9c5c Mon Sep 17 00:00:00 2001 From: gardners Date: Mon, 19 Mar 2012 09:43:11 +1030 Subject: [PATCH] Added code to remove stale unix domain socket files on startup and shutdown. --- dna.c | 2 ++ overlay_mdp.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dna.c b/dna.c index 2aae81a0..01607f06 100644 --- a/dna.c +++ b/dna.c @@ -305,6 +305,8 @@ void servalShutdownCleanly() unlink(filename); snprintf(filename,1024,"%s/serval.pid",instancepath); unlink(filename); + snprintf(filename,1024,"%s/mdp.socket",instancepath); + unlink(filename); exit(0); } diff --git a/overlay_mdp.c b/overlay_mdp.c index d28fa149..694738e9 100644 --- a/overlay_mdp.c +++ b/overlay_mdp.c @@ -60,8 +60,10 @@ int overlay_mdp_setup_sockets() #endif if (mdp_named_socket==-1) { char *instancepath=serval_instancepath(); + if (strlen(instancepath)>85) return WHY("Instance path too long to allow construction of named unix domain socket."); snprintf(&name.sun_path[0],100,"%s/mdp.socket",instancepath); - len = 0+strlen(&name.sun_path[0]) + sizeof(name.sun_family); + unlink(&name.sun_path[0]); + len = 0+strlen(&name.sun_path[0]) + sizeof(name.sun_family)+1; mdp_named_socket = socket(AF_UNIX, SOCK_DGRAM, 0); if (mdp_named_socket>-1) { int dud=0;