Fix for GitHub issue #97
This commit is contained in:
parent
b7389995f4
commit
80fc584923
3 changed files with 43 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -58,6 +58,21 @@ namespace ZeroTier {
|
|||
class Utils
|
||||
{
|
||||
public:
|
||||
#ifdef __UNIX_LIKE__
|
||||
/**
|
||||
* Close STDOUT_FILENO and STDERR_FILENO and replace them with output to given path
|
||||
*
|
||||
* This can be called after fork() and prior to exec() to suppress output
|
||||
* from a subprocess, such as auto-update.
|
||||
*
|
||||
* @param stdoutPath Path to file to use for stdout
|
||||
* @param stderrPath Path to file to use for stderr, or NULL for same as stdout (default)
|
||||
* @return True on success
|
||||
*/
|
||||
static bool redirectUnixOutputs(const char *stdoutPath,const char *stderrPath = (const char *)0)
|
||||
throw();
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Perform a time-invariant binary comparison
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue