X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=sysklogd%2Fsyslogd.c;h=f27bd8379214c323a5bd8e32a65768d499f6a0ad;hb=339936be006c3695de5c93bc59707c3d853ae186;hp=6ecbd16f018c17498fbda581f365da5ae2d4de2f;hpb=5f1b149d541ebba7cab841cb647f113248f9fb8f;p=oweals%2Fbusybox.git diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 6ecbd16f0..f27bd8379 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c @@ -201,7 +201,7 @@ static void ipcsyslog_init(void) if (DEBUG) printf("shmget(%lx, %d,...)\n", KEY_ID, G.shm_size); - G.shmid = shmget(KEY_ID, G.shm_size, IPC_CREAT | 1023); + G.shmid = shmget(KEY_ID, G.shm_size, IPC_CREAT | 0644); if (G.shmid == -1) { bb_perror_msg_and_die("shmget"); } @@ -472,7 +472,6 @@ static void do_syslogd(void) { struct sockaddr_un sunx; int sock_fd; - fd_set fds; char *dev_log_name; /* Set up signal handlers */ @@ -526,40 +525,34 @@ static void do_syslogd(void) (char*)"syslogd started: BusyBox v" BB_VER, 0); for (;;) { - FD_ZERO(&fds); - FD_SET(sock_fd, &fds); + size_t sz; - if (select(sock_fd + 1, &fds, NULL, NULL, NULL) < 0) { - if (errno == EINTR) { - /* alarm may have happened */ + sz = read(sock_fd, G.recvbuf, MAX_READ - 1); + if (sz <= 0) { + if (sz == 0) + continue; /* EOF from unix socket??? */ + if (errno == EINTR) /* alarm may have happened */ continue; - } - bb_perror_msg_and_die("select"); + bb_perror_msg_and_die("read from /dev/log"); } - if (FD_ISSET(sock_fd, &fds)) { - int i; - i = recv(sock_fd, G.recvbuf, MAX_READ - 1, 0); - if (i <= 0) - bb_perror_msg_and_die("UNIX socket error"); - /* TODO: maybe suppress duplicates? */ + /* TODO: maybe suppress duplicates? */ #if ENABLE_FEATURE_REMOTE_LOG - /* We are not modifying log messages in any way before send */ - /* Remote site cannot trust _us_ anyway and need to do validation again */ - if (G.remoteAddr) { - if (-1 == G.remoteFD) { - G.remoteFD = socket(G.remoteAddr->sa.sa_family, SOCK_DGRAM, 0); - } - if (-1 != G.remoteFD) { - /* send message to remote logger, ignore possible error */ - sendto(G.remoteFD, G.recvbuf, i, MSG_DONTWAIT, - &G.remoteAddr->sa, G.remoteAddr->len); - } + /* We are not modifying log messages in any way before send */ + /* Remote site cannot trust _us_ anyway and need to do validation again */ + if (G.remoteAddr) { + if (-1 == G.remoteFD) { + G.remoteFD = socket(G.remoteAddr->sa.sa_family, SOCK_DGRAM, 0); } + if (-1 != G.remoteFD) { + /* send message to remote logger, ignore possible error */ + sendto(G.remoteFD, G.recvbuf, sz, MSG_DONTWAIT, + &G.remoteAddr->sa, G.remoteAddr->len); + } + } #endif - G.recvbuf[i] = '\0'; - split_escape_and_log(G.recvbuf, i); - } /* FD_ISSET() */ + G.recvbuf[sz] = '\0'; + split_escape_and_log(G.recvbuf, sz); } /* for */ } @@ -573,7 +566,7 @@ int syslogd_main(int argc, char **argv) /* do normal option parsing */ opt_complementary = "=0"; /* no non-option params */ - getopt32(argc, argv, OPTION_STR, OPTION_PARAM); + getopt32(argv, OPTION_STR, OPTION_PARAM); #ifdef SYSLOGD_MARK if (option_mask32 & OPT_mark) // -m G.markInterval = xatou_range(opt_m, 0, INT_MAX/60) * 60;