- logMessage(0, "syslogd started: BusyBox v" BB_VER " (" BB_BT ")");
-
-
- while ((conn = accept(fd, (struct sockaddr *) &sunx,
- &addrLength)) >= 0) {
- while ((readSize = read(conn, buf, sizeof(buf))) > 0) {
- char line[1025];
- unsigned char c;
- int pri = (LOG_USER | LOG_NOTICE);
-
- memset(line, 0, sizeof(line));
- p = buf;
- q = line;
- while (p && (c = *p) && q < &line[sizeof(line) - 1]) {
- if (c == '<') {
- /* Parse the magic priority number */
- pri = 0;
- while (isdigit(*(++p))) {
- pri = 10 * pri + (*p - '0');
+ char lfile[BUFSIZ];
+
+ /* Set up signal handlers. */
+ signal (SIGINT, quit_signal);
+ signal (SIGTERM, quit_signal);
+ signal (SIGQUIT, quit_signal);
+ signal (SIGHUP, SIG_IGN);
+ signal (SIGCHLD, SIG_IGN);
+#ifdef SIGCLD
+ signal (SIGCLD, SIG_IGN);
+#endif
+ signal (SIGALRM, domark);
+ alarm (MarkInterval);
+
+ /* Create the syslog file so realpath() can work. */
+ close (open (_PATH_LOG, O_RDWR | O_CREAT, 0644));
+ if (realpath (_PATH_LOG, lfile) == NULL)
+ fatalError ("Could not resolve path to " _PATH_LOG ": %s\n", strerror (errno));
+
+ unlink (lfile);
+
+ memset (&sunx, 0, sizeof (sunx));
+ sunx.sun_family = AF_UNIX;
+ strncpy (sunx.sun_path, lfile, sizeof (sunx.sun_path));
+ if ((sock_fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
+ fatalError ("Couldn't obtain descriptor for socket " _PATH_LOG ": %s\n", strerror (errno));
+
+ addrLength = sizeof (sunx.sun_family) + strlen (sunx.sun_path);
+ if ((bind (sock_fd, (struct sockaddr *) &sunx, addrLength)) || (listen (sock_fd, 5)))
+ fatalError ("Could not connect to socket " _PATH_LOG ": %s\n", strerror (errno));
+
+ if (chmod (lfile, 0666) < 0)
+ fatalError ("Could not set permission on " _PATH_LOG ": %s\n", strerror (errno));
+
+ FD_ZERO (&fds);
+ FD_SET (sock_fd, &fds);
+
+ #ifdef BB_FEATURE_REMOTE_LOG
+ if (doRemoteLog == TRUE){
+ init_RemoteLog();
+ }
+ #endif
+
+ logMessage (0, "syslogd started: BusyBox v" BB_VER " (" BB_BT ")");
+
+ for (;;) {
+
+ fd_set readfds;
+ int n_ready;
+ int fd;
+
+ memcpy (&readfds, &fds, sizeof (fds));
+
+ if ((n_ready = select (FD_SETSIZE, &readfds, NULL, NULL, NULL)) < 0) {
+ if (errno == EINTR) continue; /* alarm may have happened. */
+ fatalError ("select error: %s\n", strerror (errno));
+ }
+
+ 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) {
+ fatalError ("accept error: %s\n", strerror (errno));
+ }
+
+ pid = fork();
+
+ if (pid < 0) {
+ perror ("syslogd: fork");
+ close (conn);
+ continue;
+ }
+
+ if (pid == 0) {
+ serveConnection (conn);
+ close (conn);
+ exit( TRUE);