added compile time options NOCRYPT,NODAEMON,NOEXEC for easyier windows porting
[anytun.git] / src / sysexec.hpp
blob73a18bf46be75c805bea211289bed03fe8f7b9c3
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);
13 fd=open("/dev/null",O_RDWR); // stdin
14 dup(fd); // stdout
15 dup(fd); // stderr
16 return execl("/bin/sh", "/bin/sh", script.c_str(), ifname.c_str(), NULL);
18 int status = 0;
19 waitpid(pid, &status, 0);
20 return status;
24 #endif
25 #endif