--- mcstrans-0.2.5/src/mcstransd.c.bak 2007-01-30 16:17:25.000000000 +0200 +++ mcstrans-0.2.5/src/mcstransd.c 2007-08-30 21:57:02.886539323 +0300 @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -574,6 +575,8 @@ void dropprivs(void) int main(int UNUSED(argc), char *argv[]) { + int fd; + #ifndef DEBUG /* Make sure we are root */ if (getuid() != 0) { @@ -590,9 +593,17 @@ main(int UNUSED(argc), char *argv[]) #ifndef DEBUG dropprivs(); - /* run in the background as a daemon */ - if (daemon(0, 0)) { - syslog(LOG_ERR, "daemon() failed: %m"); + if (chdir("/") == -1) { + syslog(LOG_ERR, "chdir failed: %m"); + exit(1); + } + fd = open("/dev/null", O_RDWR); + if (fd == -1) { + syslog(LOG_ERR, "opening /dev/null failed: %m"); + exit(1); + } + if ((dup2(fd, 0) == -1) || (dup2(fd, 1) == -1) || (dup2(fd, 2) == -1)) { + syslog(LOG_ERR, "dup2 failed: %m"); exit(1); } #endif