mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 10:32:56 +01:00
integrated improvements from 1.3.4 (NumberFormatter::append(), DateTimeFormatter::append()
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// ServerApplication.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Util/src/ServerApplication.cpp#2 $
|
||||
// $Id: //poco/Main/Util/src/ServerApplication.cpp#27 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Application
|
||||
@@ -43,11 +43,13 @@
|
||||
#include "Poco/NamedEvent.h"
|
||||
#include "Poco/Logger.h"
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
#include "Poco/TemporaryFile.h"
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fstream>
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "Poco/Util/WinService.h"
|
||||
#include "Poco/UnWindows.h"
|
||||
@@ -221,7 +223,7 @@ void ServerApplication::waitForTerminationRequest()
|
||||
{
|
||||
SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE);
|
||||
std::string evName("POCOTRM");
|
||||
evName.append(NumberFormatter::formatHex(Process::id(), 8));
|
||||
NumberFormatter::appendHex(evName, Process::id(), 8);
|
||||
NamedEvent ev(evName);
|
||||
ev.wait();
|
||||
_terminated.set();
|
||||
@@ -465,9 +467,14 @@ void ServerApplication::beDaemon()
|
||||
|
||||
setsid();
|
||||
umask(0);
|
||||
close(0);
|
||||
close(1);
|
||||
close(2);
|
||||
|
||||
// attach stdin, stdout, stderr to /dev/null
|
||||
// instead of just closing them. This avoids
|
||||
// issues with third party/legacy code writing
|
||||
// stuff to stdout/stderr.
|
||||
freopen("/dev/null", "r+", stdin);
|
||||
freopen("/dev/null", "r+", stdout);
|
||||
freopen("/dev/null", "r+", stderr);
|
||||
}
|
||||
|
||||
|
||||
@@ -479,6 +486,12 @@ void ServerApplication::defineOptions(OptionSet& options)
|
||||
Option("daemon", "", "run application as a daemon")
|
||||
.required(false)
|
||||
.repeatable(false));
|
||||
|
||||
options.addOption(
|
||||
Option("pidfile", "", "write PID to given file")
|
||||
.required(false)
|
||||
.repeatable(false)
|
||||
.argument("path"));
|
||||
}
|
||||
|
||||
|
||||
@@ -488,6 +501,15 @@ void ServerApplication::handleOption(const std::string& name, const std::string&
|
||||
{
|
||||
config().setBool("application.runAsDaemon", true);
|
||||
}
|
||||
else if (name == "pidfile")
|
||||
{
|
||||
std::ofstream ostr(value.c_str());
|
||||
if (ostr.good())
|
||||
ostr << Poco::Process::id() << std::endl;
|
||||
else
|
||||
throw Poco::CreateFileException("Cannot write PID to file", value);
|
||||
Poco::TemporaryFile::registerForDeletion(value);
|
||||
}
|
||||
else Application::handleOption(name, value);
|
||||
}
|
||||
|
||||
@@ -526,7 +548,7 @@ void ServerApplication::waitForTerminationRequest()
|
||||
sys$qiow(0, ioChan, IO$_SETMODE | IO$M_CTRLCAST, 0, 0, 0, terminate, 0, 0, 0, 0, 0);
|
||||
|
||||
std::string evName("POCOTRM");
|
||||
evName.append(NumberFormatter::formatHex(Process::id(), 8));
|
||||
NumberFormatter::appendHex(evName, Process::id(), 8);
|
||||
NamedEvent ev(evName);
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user