diff options
author | Christian Pointner <equinox@anytun.org> | 2008-05-26 01:06:01 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2008-05-26 01:06:01 +0000 |
commit | 567bfa9fd44b45bf99b36fbc6153e31a26ff3803 (patch) | |
tree | efc6a6b59dfcd24c8ed06c17e6be3e43dab59b39 /src/anyrtpproxy/anyrtpproxy.cpp | |
parent | moved keyexchange to http://anytun.org/svn/keyexchange (diff) |
added pid-file option to anyrtpproxy
Diffstat (limited to 'src/anyrtpproxy/anyrtpproxy.cpp')
-rw-r--r-- | src/anyrtpproxy/anyrtpproxy.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/anyrtpproxy/anyrtpproxy.cpp b/src/anyrtpproxy/anyrtpproxy.cpp index d29e4d4..05cf738 100644 --- a/src/anyrtpproxy/anyrtpproxy.cpp +++ b/src/anyrtpproxy/anyrtpproxy.cpp @@ -57,7 +57,7 @@ #include "options.h" #include "portWindow.h" #include <map> - +#include <fstream> #define MAX_PACKET_SIZE 1500 @@ -276,10 +276,11 @@ void daemonize() pid = fork(); if(pid) exit(0); - std::cout << "running in background now..." << std::endl; +// std::cout << "running in background now..." << std::endl; int fd; - for (fd=getdtablesize();fd>=0;--fd) // close all file descriptors +// 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 @@ -324,20 +325,34 @@ void* syncListener(void* p ) int main(int argc, char* argv[]) { - std::cout << "anyrtpproxy" << std::endl; +// std::cout << "anyrtpproxy" << std::endl; if(!gOpt.parse(argc, argv)) { gOpt.printUsage(); exit(-1); } + cLog.setLogName("anyrtpproxy"); + cLog.msg(Log::PRIO_NOTICE) << "anyrtpproxy started..."; + + std::ofstream pidFile; + if(gOpt.getPidFile() != "") { + pidFile.open(gOpt.getPidFile().c_str()); + if(!pidFile.is_open()) { + std::cout << "can't open pid file" << std::endl; + } + } + if(gOpt.getChroot()) chrootAndDrop(gOpt.getChrootDir(), gOpt.getUsername()); if(gOpt.getDaemonize()) daemonize(); - cLog.setLogName("anyrtpproxy"); - cLog.msg(Log::PRIO_NOTICE) << "anyrtpproxy started..."; + if(pidFile.is_open()) { + pid_t pid = getpid(); + pidFile << pid; + pidFile.close(); + } SignalController sig; sig.init(); |