* Contains more patches from Topi Miettinen.
* Fixed two mistakes from the most recent version * Fixed fd leak problem. Thanks to Topi for detecting it * Ouch! Looks like the released package again is broken. It worked locally.
This commit is contained in:
parent
2b70a699f1
commit
7d36dc9402
35
syslogd.c
35
syslogd.c
@ -780,6 +780,7 @@ int main(argc, argv)
|
|||||||
char line[MAXLINE +1];
|
char line[MAXLINE +1];
|
||||||
extern int optind;
|
extern int optind;
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
|
int maxfds;
|
||||||
|
|
||||||
#ifndef TESTING
|
#ifndef TESTING
|
||||||
chdir ("/");
|
chdir ("/");
|
||||||
@ -986,26 +987,26 @@ int main(argc, argv)
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
int nfds;
|
int nfds;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
#ifdef SYSLOG_UNIXAF
|
|
||||||
FD_ZERO(&readfds);
|
FD_ZERO(&readfds);
|
||||||
|
maxfds = 0;
|
||||||
|
#ifdef SYSLOG_UNIXAF
|
||||||
#ifndef TESTING
|
#ifndef TESTING
|
||||||
/*
|
/*
|
||||||
* Add the Unix Domain Sockets to the list of read
|
* Add the Unix Domain Sockets to the list of read
|
||||||
* descriptors.
|
* descriptors.
|
||||||
*/
|
*/
|
||||||
len = 0;
|
|
||||||
/* Copy master connections */
|
/* Copy master connections */
|
||||||
for (i = 0; i < nfunix; i++) {
|
for (i = 0; i < nfunix; i++) {
|
||||||
if (funix[i] != -1) {
|
if (funix[i] != -1) {
|
||||||
FD_SET(funix[i], &readfds);
|
FD_SET(funix[i], &readfds);
|
||||||
if (i>len) len=i;
|
if (funix[i]>maxfds) maxfds=funix[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Copy accepted connections */
|
/* Copy accepted connections */
|
||||||
for (nfds= 0; nfds < FD_SETSIZE; ++nfds)
|
for (nfds= 0; nfds < FD_SETSIZE; ++nfds)
|
||||||
if (FD_ISSET(nfds, &unixm)) {
|
if (FD_ISSET(nfds, &unixm)) {
|
||||||
FD_SET(nfds, &readfds);
|
FD_SET(nfds, &readfds);
|
||||||
if (i>nfds) len=nfds;
|
if (nfds>maxfds) maxfds=nfds;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -1017,24 +1018,27 @@ int main(argc, argv)
|
|||||||
*/
|
*/
|
||||||
if ( InetInuse && AcceptRemote ) {
|
if ( InetInuse && AcceptRemote ) {
|
||||||
FD_SET(inetm, &readfds);
|
FD_SET(inetm, &readfds);
|
||||||
|
if (inetm>maxfds) maxfds=inetm;
|
||||||
dprintf("Listening on syslog UDP port.\n");
|
dprintf("Listening on syslog UDP port.\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifdef TESTING
|
#ifdef TESTING
|
||||||
FD_SET(fileno(stdin), &readfds);
|
FD_SET(fileno(stdin), &readfds);
|
||||||
|
if (fileno(stdin) > maxfds) maxfds = fileno(stdin);
|
||||||
|
|
||||||
dprintf("Listening on stdin. Press Ctrl-C to interrupt.\n");
|
dprintf("Listening on stdin. Press Ctrl-C to interrupt.\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( debugging_on )
|
if ( debugging_on )
|
||||||
{
|
{
|
||||||
dprintf("Calling select, active file descriptors: ");
|
dprintf("Calling select, active file descriptors (max %d): ", maxfds);
|
||||||
for (nfds= 0; nfds < FD_SETSIZE; ++nfds)
|
for (nfds= 0; nfds <= maxfds; ++nfds)
|
||||||
if ( FD_ISSET(nfds, &readfds) )
|
if ( FD_ISSET(nfds, &readfds) )
|
||||||
dprintf("%d ", nfds);
|
dprintf("%d ", nfds);
|
||||||
dprintf("\n");
|
dprintf("\n");
|
||||||
}
|
}
|
||||||
nfds = select(len, (fd_set *) &readfds, (fd_set *) NULL,
|
nfds = select(maxfds+1, (fd_set *) &readfds, (fd_set *) NULL,
|
||||||
(fd_set *) NULL, (struct timeval *) NULL);
|
(fd_set *) NULL, (struct timeval *) NULL);
|
||||||
if ( restart )
|
if ( restart )
|
||||||
{
|
{
|
||||||
@ -1058,7 +1062,7 @@ int main(argc, argv)
|
|||||||
{
|
{
|
||||||
dprintf("\nSuccessful select, descriptor count = %d, " \
|
dprintf("\nSuccessful select, descriptor count = %d, " \
|
||||||
"Activity on: ", nfds);
|
"Activity on: ", nfds);
|
||||||
for (nfds= 0; nfds < FD_SETSIZE; ++nfds)
|
for (nfds= 0; nfds <= maxfds; ++nfds)
|
||||||
if ( FD_ISSET(nfds, &readfds) )
|
if ( FD_ISSET(nfds, &readfds) )
|
||||||
dprintf("%d ", nfds);
|
dprintf("%d ", nfds);
|
||||||
dprintf(("\n"));
|
dprintf(("\n"));
|
||||||
@ -1069,12 +1073,12 @@ int main(argc, argv)
|
|||||||
if ( debugging_on )
|
if ( debugging_on )
|
||||||
{
|
{
|
||||||
dprintf("Checking UNIX connections, active: ");
|
dprintf("Checking UNIX connections, active: ");
|
||||||
for (nfds= 0; nfds < FD_SETSIZE; ++nfds)
|
for (nfds= 0; nfds < maxfds; ++nfds)
|
||||||
if ( FD_ISSET(nfds, &unixm) )
|
if ( FD_ISSET(nfds, &unixm) )
|
||||||
dprintf("%d ", nfds);
|
dprintf("%d ", nfds);
|
||||||
dprintf("\n");
|
dprintf("\n");
|
||||||
}
|
}
|
||||||
for (fd= 0; fd < FD_SETSIZE; ++fd)
|
for (fd= 0; fd <= maxfds; ++fd)
|
||||||
if ( FD_ISSET(fd, &readfds) && FD_ISSET(fd, &unixm) ) {
|
if ( FD_ISSET(fd, &readfds) && FD_ISSET(fd, &unixm) ) {
|
||||||
dprintf("Message from UNIX socket #%d.\n", fd);
|
dprintf("Message from UNIX socket #%d.\n", fd);
|
||||||
memset(line, '\0', sizeof(line));
|
memset(line, '\0', sizeof(line));
|
||||||
@ -1095,9 +1099,13 @@ int main(argc, argv)
|
|||||||
strlen(parts[fd]) + 1, \
|
strlen(parts[fd]) + 1, \
|
||||||
fd);
|
fd);
|
||||||
}
|
}
|
||||||
|
/* reset it */
|
||||||
|
for (i = 1; i < nfunix; i++) {
|
||||||
|
if (funix[i] == fd)
|
||||||
|
funix[i] = -1;
|
||||||
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
FD_CLR(fd, &unixm);
|
FD_CLR(fd, &unixm);
|
||||||
FD_CLR(fd, &readfds);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Accept a new unix connection */
|
/* Accept a new unix connection */
|
||||||
@ -2312,9 +2320,12 @@ void init()
|
|||||||
(void) fclose(cf);
|
(void) fclose(cf);
|
||||||
|
|
||||||
#ifdef SYSLOG_UNIXAF
|
#ifdef SYSLOG_UNIXAF
|
||||||
for (i = 0; i < nfunix; i++)
|
for (i = 0; i < nfunix; i++) {
|
||||||
|
if (funix[i] != -1)
|
||||||
|
close(funix[i]);
|
||||||
if ((funix[i] = create_unix_socket(funixn[i])) != -1)
|
if ((funix[i] = create_unix_socket(funixn[i])) != -1)
|
||||||
dprintf("Opened UNIX socket `%s'.\n", funixn[i]);
|
dprintf("Opened UNIX socket `%s'.\n", funixn[i]);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SYSLOG_INET
|
#ifdef SYSLOG_INET
|
||||||
|
Loading…
Reference in New Issue
Block a user