From 567bfa9fd44b45bf99b36fbc6153e31a26ff3803 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 26 May 2008 01:06:01 +0000 Subject: added pid-file option to anyrtpproxy --- src/anyrtpproxy/anyrtpproxy.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/anyrtpproxy/anyrtpproxy.cpp') 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 - +#include #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(); -- cgit v1.2.3