diff options
Diffstat (limited to 'dund')
-rw-r--r-- | dund/dun.c | 6 | ||||
-rw-r--r-- | dund/main.c | 15 |
2 files changed, 8 insertions, 13 deletions
@@ -98,7 +98,9 @@ static int uses_rfcomm(char *path, char *dev) dir = opendir(path); if (!dir) return 0; - chdir(path); + + if (chdir(path) < 0) + return 0; while ((de = readdir(dir)) != NULL) { char link[PATH_MAX + 1]; @@ -109,7 +111,9 @@ static int uses_rfcomm(char *path, char *dev) return 1; } } + closedir(dir); + return 0; } diff --git a/dund/main.c b/dund/main.c index 249d6d7c..bb96d639 100644 --- a/dund/main.c +++ b/dund/main.c @@ -598,18 +598,9 @@ int main(int argc, char *argv[]) sa.sa_handler = sig_hup; sigaction(SIGHUP, &sa, NULL); - if (detach) { - int fd; - - if (fork()) exit(0); - - /* Direct stdin,stdout,stderr to '/dev/null' */ - fd = open("/dev/null", O_RDWR); - dup2(fd, 0); dup2(fd, 1); dup2(fd, 2); - close(fd); - - setsid(); - chdir("/"); + if (detach && daemon(0, 0)) { + perror("Can't start daemon"); + exit(1); } openlog("dund", LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_DAEMON); |