diff options
Diffstat (limited to 'src/anyrtpproxy')
-rw-r--r-- | src/anyrtpproxy/anyrtpproxy.cpp | 27 | ||||
-rw-r--r-- | src/anyrtpproxy/options.cpp | 10 | ||||
-rw-r--r-- | src/anyrtpproxy/options.h | 2 |
3 files changed, 33 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(); diff --git a/src/anyrtpproxy/options.cpp b/src/anyrtpproxy/options.cpp index ed01020..e6d95cf 100644 --- a/src/anyrtpproxy/options.cpp +++ b/src/anyrtpproxy/options.cpp @@ -57,6 +57,7 @@ Options::Options() : control_interface_("0.0.0.0", 22222) username_ = "nobody"; chroot_dir_ = "/var/run"; daemonize_ = true; + pid_file_ = ""; local_addr_ = ""; local_sync_port_ = 0; rtp_start_port_ = 34000; @@ -162,6 +163,7 @@ bool Options::parse(int argc, char* argv[]) PARSE_SCALAR_PARAM("-u","--user", username_) PARSE_SCALAR_PARAM("-c","--chroot-dir", chroot_dir_) PARSE_INVERSE_BOOL_PARAM("-d","--nodaemonize", daemonize_) + PARSE_SCALAR_PARAM("-P","--write-pid", pid_file_) PARSE_SCALAR_PARAM("-i","--interface", local_addr_) PARSE_STRING_PARAM("-s","--control", control_interface_) PARSE_SCALAR_PARAM2("-p","--port-range", rtp_start_port_, rtp_end_port_) @@ -200,6 +202,7 @@ void Options::printUsage() std::cout << " [-u|--username] <username> in case of chroot run as this user" << std::endl; std::cout << " [-c|--chroot-dir] <directory> directory to make a chroot to" << std::endl; std::cout << " [-d|--nodaemonize] don't run in background" << std::endl; + std::cout << " [-P|--write-pid] <path> write pid to this file" << std::endl; std::cout << " [-i|--interface] <ip-address> local ip address to listen to for RTP packets" << std::endl; std::cout << " [-s|--control] <addr[:port]> the address/port to listen on for control commands" << std::endl; std::cout << " [-p|--port-range] <start> <end> port range used to relay rtp connections" << std::endl; @@ -219,6 +222,7 @@ void Options::printOptions() std::cout << "username='" << username_ << "'" << std::endl; std::cout << "chroot-dir='" << chroot_dir_ << "'" << std::endl; std::cout << "daemonize='" << daemonize_ << "'" << std::endl; + std::cout << "pid_file='" << pid_file_ << "'" << std::endl; std::cout << "control-interface='" << control_interface_.toString() << "'" << std::endl; std::cout << "local_addr='" << local_addr_ << "'" << std::endl; } @@ -265,6 +269,12 @@ bool Options::getDaemonize() return daemonize_; } +std::string Options::getPidFile() +{ + Lock lock(mutex); + return pid_file_; +} + Host Options::getControlInterface() { Lock lock(mutex); diff --git a/src/anyrtpproxy/options.h b/src/anyrtpproxy/options.h index 1eb176d..3d924fd 100644 --- a/src/anyrtpproxy/options.h +++ b/src/anyrtpproxy/options.h @@ -81,6 +81,7 @@ public: bool getNoNatOnce(); std::string getUsername(); std::string getChrootDir(); + std::string getPidFile(); bool getDaemonize(); Host getControlInterface(); std::string getLocalAddr(); @@ -118,6 +119,7 @@ private: bool no_nat_once_; std::string username_; std::string chroot_dir_; + std::string pid_file_; bool daemonize_; u_int16_t local_sync_port_; std::string local_addr_; |