Browse Source

A little code simplify

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

+ 34 - 40
bin/konfd.c

@@ -244,44 +244,42 @@ int main(int argc, char **argv)
 
 		/* Service all the sockets with input pending. */
 		for (i = 0; i < FD_SETSIZE; ++i) {
-			if (FD_ISSET(i, &read_fd_set)) {
-				if (i == sock) {
-					/* Connection request on original socket. */
-					int new;
-					socklen_t size;
-					
-					size = sizeof(raddr);
-					new = accept(sock, (struct sockaddr *)
-						     &raddr, &size);
-					if (new < 0) {
-						fprintf(stderr, "accept");
-						continue;
-					}
+			if (!FD_ISSET(i, &read_fd_set))
+				continue;
+			if (i == sock) {
+				/* Connection request on listen socket. */
+				int new;
+				socklen_t size = sizeof(raddr);
+				new = accept(sock,
+					(struct sockaddr *)&raddr, &size);
+				if (new < 0) {
+					fprintf(stderr, "accept");
+					continue;
+				}
 #ifdef DEBUG
-					fprintf(stderr, "Connection established %u\n", new);
+				fprintf(stderr, "Connection established %u\n", new);
 #endif
-					konf_buftree_remove(&bufs, new);
-					tbuf = konf_buf_new(new);
-					/* insert it into the binary tree for this conf */
-					lub_bintree_insert(&bufs, tbuf);
-					FD_SET(new, &active_fd_set);
-				} else {
-					int nbytes;
-					/* Data arriving on an already-connected socket. */
-					if ((nbytes = konf_buftree_read(&bufs, i)) <= 0) {
-						close(i);
-						FD_CLR(i, &active_fd_set);
-						konf_buftree_remove(&bufs, i);
-						continue;
-					}
-					while ((str = konf_buftree_parse(&bufs, i))) {
-						char *answer;
-						if (!(answer = process_query(i, conf, str)))
-							answer = lub_string_dup("-e");
-						lub_string_free(str);
-						answer_send(i, answer);
-						lub_string_free(answer);
-					}
+				konf_buftree_remove(&bufs, new);
+				tbuf = konf_buf_new(new);
+				/* insert it into the binary tree for this conf */
+				lub_bintree_insert(&bufs, tbuf);
+				FD_SET(new, &active_fd_set);
+			} else {
+				int nbytes;
+				/* Data arriving on an already-connected socket. */
+				if ((nbytes = konf_buftree_read(&bufs, i)) <= 0) {
+					close(i);
+					FD_CLR(i, &active_fd_set);
+					konf_buftree_remove(&bufs, i);
+					continue;
+				}
+				while ((str = konf_buftree_parse(&bufs, i))) {
+					char *answer;
+					if (!(answer = process_query(i, conf, str)))
+						answer = lub_string_dup("-e");
+					lub_string_free(str);
+					answer_send(i, answer);
+					lub_string_free(answer);
 				}
 			}
 		}
@@ -306,10 +304,6 @@ err:
 		unlink(opts->socket_path);
 	}
 
-	/* Restore original EUID for cleanup */
-/*	if (getuid() != geteuid())
-		seteuid(getuid());
-*/
 	/* Remove pidfile */
 	if (pidfd >= 0) {
 		if (unlink(opts->pidfile) < 0) {