1
0
Fork 0

added some error messages when using --pid-file

This commit is contained in:
Jan Steemann 2012-06-27 11:38:43 +02:00
parent ad456ded93
commit 5cbc0ad3c7
3 changed files with 24 additions and 2 deletions

View File

@ -359,6 +359,17 @@ namespace triagens {
} }
off_t size (string const& path) {
struct stat stbuf;
int res = stat(path.c_str(), &stbuf);
if (res != 0) {
return 0;
}
return stbuf.st_size;
}
string stripExtension (string const& path, string const& extension) { string stripExtension (string const& path, string const& extension) {
size_t pos = path.rfind(extension); size_t pos = path.rfind(extension);

View File

@ -130,6 +130,14 @@ namespace triagens {
bool exists (string const& path); bool exists (string const& path);
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the size of a file. will return 0 for non-existing files
///
/// the caller should check first if the file exists via the exists() method
////////////////////////////////////////////////////////////////////////////////
off_t size (string const& path);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief strip extension /// @brief strip extension
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -68,7 +68,7 @@ static void CheckPidFile (string const& pidFile) {
TRI_FlushLogging(); TRI_FlushLogging();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
else if (FileUtils::exists(pidFile)) { else if (FileUtils::exists(pidFile) && FileUtils::size(pidFile) > 0) {
LOGGER_INFO << "pid-file '" << pidFile << "' already exists, verifying pid"; LOGGER_INFO << "pid-file '" << pidFile << "' already exists, verifying pid";
ifstream f(pidFile.c_str()); ifstream f(pidFile.c_str());
@ -137,7 +137,7 @@ static void WritePidFile (string const& pidFile, int pid) {
ofstream out(pidFile.c_str(), ios::trunc); ofstream out(pidFile.c_str(), ios::trunc);
if (! out) { if (! out) {
cerr << "cannot write pid\n"; cerr << "cannot write pid-file \"" << pidFile << "\"\n";
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -159,6 +159,9 @@ static int forkProcess (string const& pidFile, string const& workingDirectory, s
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
// Upon successful completion, fork() shall return 0 to the child process and
// shall return the process ID of the child process to the parent process.
// if we got a good PID, then we can exit the parent process // if we got a good PID, then we can exit the parent process
if (pid > 0) { if (pid > 0) {
LOGGER_DEBUG << "started child process with pid " << pid; LOGGER_DEBUG << "started child process with pid " << pid;