diff -uprk.orig sysklogd-1.4.1.orig/klogd.c sysklogd-1.4.1/klogd.c --- sysklogd-1.4.1.orig/klogd.c 2001-03-11 22:40:10 +0300 +++ sysklogd-1.4.1/klogd.c 2004-02-07 23:06:23 +0300 @@ -275,6 +275,10 @@ _syscall3(int,ksyslog,int, type, char *, #define ksyslog klogctl #endif +#ifndef _PATH_DEVNULL +#define _PATH_DEVNULL "/dev/null" +#endif + #define LOG_BUFFER_SIZE 4096 #define LOG_LINE_LENGTH 1000 @@ -1070,13 +1074,29 @@ int main(argc, argv) { if (!check_pid(PidFile)) { - if ( fork() == 0 ) + pid_t pid; + int fl; + + if ((fl = open(_PATH_DEVNULL, O_RDWR)) < 0) + { + fprintf (stderr, "klogd: %s: %s\n", + _PATH_DEVNULL, strerror(errno)); + exit(1); + } + + if ((pid = fork()) == -1) + { + fputs("klogd: fork failed.\n", stderr); + exit(1); + } else if (pid == 0) { - auto int fl; int num_fds = getdtablesize(); /* This is the child closing its file descriptors. */ - for (fl= 0; fl <= num_fds; ++fl) + dup2(fl, 0); + dup2(fl, 1); + dup2(fl, 2); + for (fl= 3; fl <= num_fds; ++fl) { if ( fileno(stdout) == fl && use_output ) if ( strcmp(output, "-") == 0 ) diff -uprk.orig sysklogd-1.4.1.orig/syslogd.c sysklogd-1.4.1/syslogd.c --- sysklogd-1.4.1.orig/syslogd.c 2004-02-07 22:14:27 +0300 +++ sysklogd-1.4.1/syslogd.c 2004-02-07 22:55:16 +0300 @@ -554,6 +554,10 @@ static char sccsid[] = "@(#)syslogd.c 5. #define _PATH_LOG "/dev/log" #endif +#ifndef _PATH_DEVNULL +#define _PATH_DEVNULL "/dev/null" +#endif + char *ConfFile = _PATH_LOGCONF; char *PidFile = _PATH_LOGPID; char ctty[] = _PATH_CONSOLE; @@ -895,8 +899,20 @@ int main(argc, argv) dprintf("Checking pidfile.\n"); if (!check_pid(PidFile)) { + pid_t pid; + + if ((fd = open(_PATH_DEVNULL, O_RDWR)) < 0) { + fprintf (stderr, "syslogd: %s: %s\n", + _PATH_DEVNULL, strerror(errno)); + exit(1); + } + signal (SIGTERM, doexit); - if (fork()) { + if ((pid = fork()) == -1) + { + fputs("syslogd: fork failed.\n", stderr); + exit(1); + } else if (pid) { /* * Parent process */ @@ -912,7 +928,10 @@ int main(argc, argv) exit(1); } num_fds = getdtablesize(); - for (i= 0; i < num_fds; i++) + (void) dup2(fd, 0); + (void) dup2(fd, 1); + (void) dup2(fd, 2); + for (i= 3; i < num_fds; i++) (void) close(i); untty(); }