server: unlink sock file if interrupted early

Signed-off-by: Jens Axboe <axboe@fb.com>
diff --git a/server.c b/server.c
index 0954d4c..d72835b 100644
--- a/server.c
+++ b/server.c
@@ -1339,7 +1339,6 @@
 	memset(&addr, 0, sizeof(addr));
 	addr.sun_family = AF_UNIX;
 	strcpy(addr.sun_path, bind_sock);
-	unlink(bind_sock);
 
 	len = sizeof(addr.sun_family) + strlen(bind_sock) + 1;
 
@@ -1567,6 +1566,22 @@
 	return ret;
 }
 
+static void sig_int(int sig)
+{
+	if (bind_sock)
+		unlink(bind_sock);
+}
+
+static void set_sig_handlers(void)
+{
+	struct sigaction act;
+
+	memset(&act, 0, sizeof(act));
+	act.sa_handler = sig_int;
+	act.sa_flags = SA_RESTART;
+	sigaction(SIGINT, &act, NULL);
+}
+
 static int fio_server(void)
 {
 	int sk, ret;
@@ -1580,6 +1595,8 @@
 	if (sk < 0)
 		return -1;
 
+	set_sig_handlers();
+
 	ret = accept_loop(sk);
 
 	close(sk);