fixed windows endian include
[anytun.git] / src / sysexec.hpp
blob85efaa0baaa450565a4a67bf9ad450c5178f18a1
1 #ifndef _SYSEXEC_HPP
2 #define _SYSEXEC_HPP
3 #ifndef NOEXEC
5 int execScript(std::string const& script, std::string const& ifname)
7 pid_t pid;
8 pid = fork();
9 if(!pid) {
10 int fd;
11 for (fd=getdtablesize();fd>=0;--fd) // close all file descriptors
12 close(fd);
14 fd = open("/dev/null",O_RDWR); // stdin
15 if(fd == -1)
16 cLog.msg(Log::PRIO_WARNING) << "can't open stdin";
17 else {
18 if(dup(fd) == -1) // stdout
19 cLog.msg(Log::PRIO_WARNING) << "can't open stdout";
20 if(dup(fd) == -1) // stderr
21 cLog.msg(Log::PRIO_WARNING) << "can't open stderr";
23 return execl("/bin/sh", "/bin/sh", script.c_str(), ifname.c_str(), NULL);
25 int status = 0;
26 waitpid(pid, &status, 0);
27 return status;
31 #endif
32 #endif