** Extensive rewriting by G. Falzoni <gfalzoni@inwind.it> for porting to Minix
**
** $Log$
+** Revision 1.2 2006/04/04 14:18:16 beng
+** Make syslogd work, even if it can only open klog and not udp or vice versa
+** (but not neither)
+**
** Revision 1.1 2006/04/03 13:07:42 beng
** Kick out usyslogd in favour of syslogd Giovanni's syslogd port
**
alarm(TIMERINTVL);
/* Open UDP device */
- if ((nfd = open(udpdev, O_NONBLOCK | O_RDONLY)) < 0) {
- logerror("UDP device not open");
- return EXIT_FAILURE;
- }
+ nfd = open(udpdev, O_NONBLOCK | O_RDONLY);
/* Configures the UDP device */
udpopt.nwuo_flags = NWUO_SHARED | NWUO_LP_SET | NWUO_EN_LOC |
port == 0 ? sp->s_port : htons(port);
udpopt.nwuo_remaddr = udpopt.nwuo_locaddr = htonl(0x7F000001L);
- while (ioctl(nfd, NWIOSUDPOPT, &udpopt) < 0 ||
+ while (nfd >= 0 && ioctl(nfd, NWIOSUDPOPT, &udpopt) < 0 ||
ioctl(nfd, NWIOGUDPOPT, &udpopt) < 0) {
if (errno == EAGAIN) {
sleep(1);
}
/* Open kernel log device */
- if ((kfd = open("/dev/klog", O_NONBLOCK | O_RDONLY)) < 0) {
- logerror("Open /dev/klog failed");
+ kfd = open("/dev/klog", O_NONBLOCK | O_RDONLY);
+
+ if(kfd < 0 && nfd < 0) {
+ logerror("open /dev/klog and udp device failed - can't log anything");
return EXIT_FAILURE;
}
for (;;) { /* Main loop */
FD_ZERO(&fdset); /* Setup descriptors for select */
- FD_SET(nfd, &fdset);
- FD_SET(kfd, &fdset);
+ if(nfd >= 0) FD_SET(nfd, &fdset);
+ if(kfd >= 0) FD_SET(kfd, &fdset);
if (select(fdmax, &fdset, NULL, NULL, NULL) <= 0) {
sleep(1);
continue;
}
- if (FD_ISSET(nfd, &fdset)) {
+ if (nfd >= 0 && FD_ISSET(nfd, &fdset)) {
/* Read a message from application programs */
len = read(nfd, line, MAXLINE);
die(-1);
}
}
- if (FD_ISSET(kfd, &fdset)) {
+ if (kfd >= 0 && FD_ISSET(kfd, &fdset)) {
static char linebuf[5*1024];
/* Read a message from kernel (klog) */