Cleanup of socket file

Johannes Wienke <[email protected]> Fri, 07 Feb 2014 12:11:55 +0100
Newsgroups gmane.network.spread.user
Message-ID <[email protected]>
Hi everyone,

we are working in a multiple user environment on Linux and constantly
had problems with left-over socket files in /tmp from spread. Once one
user has used spread and stopped the daemon another user on the same
machine is unable to start spread again on the same port because the
/tmp/4803 or whatever port file is still existing with permissions
preventing a deletion.

Attached is a prototypical patch against the current 4.4 beta release
that adds a signal handler to remove this file. I haven't tested this on
Windows and other esoteric platforms so it probably needs some fixes for
those. But it would be nice if this functionality could end up in the
final release.

Cheers,
Johannes

-- 
Johannes Wienke, Researcher at CoR-Lab / CITEC, Bielefeld University
Address: Inspiration 1, D-33619 Bielefeld, Germany (Room 1.307)
Phone: +49 521 106-67277

_______________________________________________
Spread-users mailing list
[email protected]
http://lists.spread.org/mailman/listinfo/spread-users
0001-Clean-up-socket-file-on-signals.patch (text/x-patch, 1.2 KB)
From 0ac64baace62a8052595b1745a2df6ead3d467a6 Mon Sep 17 00:00:00 2001
From: Johannes Wienke <[email protected]>
Date: Fri, 7 Feb 2014 11:43:15 +0100
Subject: [PATCH] Clean up socket file on signals

---
 daemon/spread.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/daemon/spread.c b/daemon/spread.c
index c5586ec..299aa2b 100644
--- a/daemon/spread.c
+++ b/daemon/spread.c
@@ -53,6 +53,7 @@
 #  include <unistd.h>
 #  include <sys/types.h>
 #  include <sys/stat.h>
+#  include <signal.h>
 #endif
 
 #ifdef	ARCH_PC_WIN95
@@ -77,6 +78,17 @@ void ip_init(void);
 /* acp-permit.c: */
 void permit_init(void);
 
+void Cleanup_Socket(int sig)
+{
+    proc My = Conf_my();
+    char name[80];
+    snprintf( name, sizeof(name), "%s/%hu", SP_UNIX_SOCKET, My.port );
+    printf( "Cleaning up socket file %s\n", name );
+    unlink( name );
+    signal ( sig, SIG_DFL );
+    raise( sig );
+}
+
 #ifdef USE_SPREAD_MAIN
 int SpreadMain(int argc, char *argv[])
 #else
@@ -219,6 +231,9 @@ int main(int argc, char *argv[])
 
 #endif	/* ARCH_PC_WIN95 */
 
+    signal( SIGTERM, Cleanup_Socket );
+    signal( SIGINT, Cleanup_Socket );
+
 	E_handle_events();
 
 	return 0;
-- 
1.7.9.5
signature.asc (application/pgp-signature, 901 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJS9L97AAoJED3ksIvvLnQsQIsP/RLZpU+vdM5YAUJhjSjs/buR
mrYKHnkj1hDOJGB+OGcYb8pJrt+7QFcCuUdKNxMkYwjkqcvJ0fsOR6T1uDHHGmOg
z6yu3IZ30VEb2KKiBGlRXVThwQomJ8dE2l2DbqVyZbr4Zkz+QAdOs06pajH1Qr3D
tQol2HNAPVNOmO54hKyFyYxnOM+w3yH9koxQ7GawPR2I1M4iV4r/kRzIm+mQG0L6
Nk1jIuoy7pLzwa7kFdb87bjePghRgZm5CwW/qwwsCDHJo5L+xTPItjq1rLeRnmp9
r2bw/1MDE6wyOvd1FixgYVzyAegOa+eWTCxDtxwSr/skbsfiGxZbJi6nqw4iksjS
k/52rb3Kb/KNaNASNRXps4kYbppXNEtip8jZgIBM8l424v4/ljNfmxsnNOJia67D
gd9zDLNphVfVMxjabeyQi8GEHfyTuI4fdt8awERc6aXAoYN5u22uImmTo+OPpuj1
RW/s1I1mPY8pPbcbYSB3pNJ1NwNb5y2dFqyi3Yrna3OD98vPGkDKphBVau+0eDt/
wMmFzPAwQA93q0mwAKf8VqY2oa2UD12ntJ8wNf9IwlGGlN45Q2znlo1ci9+vT3hM
CwLToBtGaTRuyNqcpGh2CNzSHcuvwkwZaJWl3F/C7+0PhzL4NZLf6jBe532fS/Rk
S6qpDVr6nJEtcYgCj1ZZ
=V6e1
-----END PGP SIGNATURE-----