diff options
Diffstat (limited to 'src/daemon.hpp')
-rw-r--r-- | src/daemon.hpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/daemon.hpp b/src/daemon.hpp index 9f1715d..d66549b 100644 --- a/src/daemon.hpp +++ b/src/daemon.hpp @@ -26,7 +26,11 @@ void chrootAndDrop(std::string const& chrootdir, std::string const& username) exit(-1); } cLog.msg(Log::PRIO_NOTICE) << "we are in chroot jail (" << chrootdir << ") now" << std::endl; - chdir("/"); + if(chdir("/")) + { + std::cerr << "can't change to /" << std::endl; + exit(-1); + } if (initgroups(pw->pw_name, pw->pw_gid) || setgid(pw->pw_gid) || setuid(pw->pw_uid)) { std::cerr << "can't drop to user " << username << " " << pw->pw_uid << ":" << pw->pw_gid << std::endl; @@ -57,9 +61,15 @@ void daemonize() // for (fd=getdtablesize();fd>=0;--fd) // close all file descriptors for (fd=0;fd<=2;fd++) // close all file descriptors close(fd); - fd=open("/dev/null",O_RDWR); // stdin - dup(fd); // stdout - dup(fd); // stderr + fd = open("/dev/null",O_RDWR); // stdin + if(fd == -1) + cLog.msg(Log::PRIO_WARNING) << "can't open stdin"; + else { + if(dup(fd) == -1) // stdout + cLog.msg(Log::PRIO_WARNING) << "can't open stdout"; + if(dup(fd) == -1) // stderr + cLog.msg(Log::PRIO_WARNING) << "can't open stderr"; + } umask(027); } #endif |