summaryrefslogtreecommitdiff
path: root/src/anyrtpproxy/anyrtpproxy.cpp
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2008-05-26 01:06:01 +0000
committerChristian Pointner <equinox@anytun.org>2008-05-26 01:06:01 +0000
commit567bfa9fd44b45bf99b36fbc6153e31a26ff3803 (patch)
treeefc6a6b59dfcd24c8ed06c17e6be3e43dab59b39 /src/anyrtpproxy/anyrtpproxy.cpp
parentmoved 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.cpp27
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();