-
- /* Accepting new connections */
- client_socket = OS_AcceptTCP(logr.sock, srcip, IPSIZE);
- if(client_socket < 0)
- {
- st_errors++;
- }
-
- /* Checking if IP is allowed here */
- if(OS_IPNotAllowed(srcip))
- {
- merror(DENYIP_WARN,ARGV0,srcip);
- close(client_socket);
- }
-
-
- /* Forking to deal with new client */
- if(fork() == 0)
- {
- HandleClient(client_socket, srcip);
- exit(0);
- }
- else
- {
- childcount++;
-
- /* Closing client socket, since the child is handling it */
- close(client_socket);
- continue;
- }
-
- /* The parent process should not reach here */
- return;
- }
+ /* process connections through select() for multiple sockets */
+ fdwork = fdsave;
+ if (select (fdmax, &fdwork, NULL, NULL, NULL) < 0) {
+ ErrorExit("ERROR: Call to syslogtcp select() failed, errno %d - %s",
+ errno, strerror (errno));
+ }
+
+ /* read through socket list for active socket */
+ for (sock = 0; sock <= fdmax; sock++) {
+ if (FD_ISSET (sock, &fdwork)) {
+
+ /* Accept new connections */
+ int client_socket = OS_AcceptTCP(sock, srcip, IPSIZE);
+ if (client_socket < 0) {
+ merror("%s: WARN: Accepting tcp connection from client failed.", ARGV0);
+ continue;
+ }
+
+ /* Check if IP is allowed here */
+ if (OS_IPNotAllowed(srcip)) {
+ merror(DENYIP_WARN, ARGV0, srcip);
+ close(client_socket);
+ continue;
+ }
+
+ /* Fork to deal with new client */
+ if (fork() == 0) {
+ HandleClient(client_socket, srcip);
+ exit(0);
+ } else {
+ childcount++;
+
+ /* Close client socket, since the child is handling it */
+ close(client_socket);
+ continue;
+ }
+ } /* if socket active */
+ } /* for() loop on available sockets */
+ } /* while(1) loop for messages */