Browse Source

Fix konfd daemon behaviour. It remove its socket from filesystem.

git-svn-id: https://klish.googlecode.com/svn/trunk@260 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
aa35c4b919
1 changed files with 17 additions and 14 deletions
  1. 17 14
      bin/konfd.c

+ 17 - 14
bin/konfd.c

@@ -131,33 +131,32 @@ int main(int argc, char **argv)
 	sigaction(SIGINT, &sig_act, NULL);
 	sigaction(SIGQUIT, &sig_act, NULL);
 
-	/* Configuration tree */
-	conf = konf_tree_new("", 0);
-
-	/* Initialize the tree of buffers */
-	lub_bintree_init(&bufs,
-		konf_buf_bt_offset(),
-		konf_buf_bt_compare, konf_buf_bt_getkey);
-
 	/* Create listen socket */
 	if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
 		fprintf(stderr, "Cannot create socket: %s\n", strerror(errno));
-/*		syslog(LOG_ERR, "Cannot create socket: %s\n", strerror(errno));
-*/		return -1;
+/*		syslog(LOG_ERR, "Cannot create socket: %s\n", strerror(errno)); */
+		return -1;
 	}
 
-	unlink(socket_path);
 	laddr.sun_family = AF_UNIX;
 	strncpy(laddr.sun_path, socket_path, UNIX_PATH_MAX);
 	laddr.sun_path[UNIX_PATH_MAX - 1] = '\0';
 	if (bind(sock, (struct sockaddr *)&laddr, sizeof(laddr))) {
 		fprintf(stderr, "Can't bind()\n");
-/*		syslog(LOG_ERR, "Can't bind()\n");
-*/		return -1;
+/*		syslog(LOG_ERR, "Can't bind()\n"); */
+		close(sock);
+		return -1;
 	}
-
 	listen(sock, 5);
 
+	/* Create configuration tree */
+	conf = konf_tree_new("", 0);
+
+	/* Initialize the tree of buffers */
+	lub_bintree_init(&bufs,
+		konf_buf_bt_offset(),
+		konf_buf_bt_compare, konf_buf_bt_getkey);
+
 	/* Initialize the set of active sockets. */
 	FD_ZERO(&active_fd_set);
 	FD_SET(sock, &active_fd_set);
@@ -231,6 +230,10 @@ int main(int argc, char **argv)
 		konf_buf_delete(tbuf);
 	}
 
+	/* Close listen socket */
+	close(sock);
+	unlink(socket_path);
+
 	return retval;
 }