summaryrefslogtreecommitdiff
path: root/node/Utils.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2014-08-07 06:35:54 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2014-08-07 06:35:54 -0700
commit80fc5849233c63b60c91e3fc1bf106b810e45c36 (patch)
treea945eb80c628923fef41b1e06c37d07c4e990ff8 /node/Utils.cpp
parentb7389995f4003a2c1d1bb6b6ce9171be08565f6d (diff)
downloadinfinitytier-80fc5849233c63b60c91e3fc1bf106b810e45c36.tar.gz
infinitytier-80fc5849233c63b60c91e3fc1bf106b810e45c36.zip
Fix for GitHub issue #97
Diffstat (limited to 'node/Utils.cpp')
-rw-r--r--node/Utils.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/node/Utils.cpp b/node/Utils.cpp
index b1912198..e1dbedaa 100644
--- a/node/Utils.cpp
+++ b/node/Utils.cpp
@@ -38,6 +38,7 @@
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <sys/uio.h>
#include <dirent.h>
#endif
@@ -50,6 +51,28 @@ namespace ZeroTier {
const char Utils::HEXCHARS[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' };
+bool Utils::redirectUnixOutputs(const char *stdoutPath,const char *stderrPath)
+ throw()
+{
+ int fdout = ::open(stdoutPath,O_WRONLY|O_CREAT);
+ if (fdout > 0) {
+ int fderr;
+ if (stderrPath) {
+ fderr = ::open(stderrPath,O_WRONLY|O_CREAT);
+ if (fderr <= 0) {
+ ::close(fdout);
+ return false;
+ }
+ } else fderr = fdout;
+ ::close(STDOUT_FILENO);
+ ::close(STDERR_FILENO);
+ ::dup2(fdout,STDOUT_FILENO);
+ ::dup2(fderr,STDERR_FILENO);
+ return true;
+ }
+ return false;
+}
+
std::map<std::string,bool> Utils::listDirectory(const char *path)
{
std::map<std::string,bool> r;