[BusyBox] Syslogd using select()

Gennady Feldman gena01 at cachier.com
Wed Mar 7 00:59:11 UTC 2001


TODO Items done so far (patch coming when I have a stable patch which
updates all the necessary files)
1. Klogd is now a separate applet. Removed all the ifdefs for KLOGD
support still doing cleanup of ifdefs and usage and other stuff.

2. added syslog_msg() and syslog_msg_with_name() to utility.c w/ IFDEF for
KLOGD and LOGGER.

3. Logger now uses syslog_msg_with_name(). Changed 3 lines into 1 line
actually.


Now... I started looking through doSyslogd() and I found something
interesting. Here is a snipet of code right after select() which is
already there. ServeConnection() has a single loop to do a read() and call
logmessage(). This call should NOT block, otherwise why would we be using
select to test if we can read? So my question is why do we use fork() and
will/should it work without fork()?
--------------------[Code snippet]-------------------------
for (fd = 0; (n_ready > 0) && (fd < FD_SETSIZE); fd++) {
			if (FD_ISSET (fd, &readfds)) {

				--n_ready;

				if (fd == sock_fd) {

					int   conn;
					pid_t pid;

					if ((conn = accept (sock_fd,
(struct sockaddr *) &sunx, &addrLength)) < 0) {
						perror_msg_and_die
("accept error");
					}

					pid = fork();

					if (pid < 0) {
						perror ("syslogd: fork");
						close (conn);
						continue;
					}

					if (pid == 0) {
						serveConnection (conn);
						close (conn);
						exit( TRUE);
					}
					close (conn);
				}
			}
-------------------------------------------------------------------------
---------------------[Proposed change]-----------------------------------
		for (fd = 0; (n_ready > 0) && (fd < FD_SETSIZE); fd++) {
			if (FD_ISSET (fd, &readfds)) {

				--n_ready;

				if (fd == sock_fd) {

					int   conn;
					pid_t pid;

					if ((conn = accept (sock_fd,
(struct sockaddr *) &sunx, &addrLength)) < 0) {
						perror_msg_and_die
("accept error");
					}


					serveConnection (conn);
					close (conn);
				}
			}
		}
-----------------------------------------------------------------------

G.F.






More information about the busybox mailing list