From 4eb2dca5b9ae07228f542cd798b44cc44ea96c09 Mon Sep 17 00:00:00 2001 From: "Stephen D. Huston" Date: Tue, 7 Oct 2008 15:19:50 +0000 Subject: Abstract native file-locking and directory detection/creation to portable classes LockFile and FileSysDir; resolves QPID-1148 git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@702513 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/broker/Daemon.cpp | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) (limited to 'cpp/src/qpid/broker') diff --git a/cpp/src/qpid/broker/Daemon.cpp b/cpp/src/qpid/broker/Daemon.cpp index 1796c8db04..8790653c8d 100644 --- a/cpp/src/qpid/broker/Daemon.cpp +++ b/cpp/src/qpid/broker/Daemon.cpp @@ -167,23 +167,15 @@ void Daemon::ready(uint16_t port) { // child lockFile = pidFile(pidDir, port); LockFile lf(lockFile, true); - /* - * Rewritten using low-level IO, for compatibility - * with earlier Boost versions, i.e. 103200. - */ /* * Write the PID to the lockfile. */ - pid_t pid = getpid(); - int desired_write = sizeof(pid_t); - if ( desired_write > ::write(lf.fd, & pid, desired_write) ) { - throw Exception("Cannot write lock file "+lockFile); - } + lf.writePid(); /* * Write the port number to the parent. */ - desired_write = sizeof(uint16_t); + int desired_write = sizeof(uint16_t); if ( desired_write > ::write(pipeFds[1], & port, desired_write) ) { throw Exception("Error writing to parent." ); } @@ -198,16 +190,7 @@ void Daemon::ready(uint16_t port) { // child pid_t Daemon::getPid(string _pidDir, uint16_t port) { string name = pidFile(_pidDir, port); LockFile lf(name, false); - pid_t pid; - - /* - * Rewritten using low-level IO, for compatibility - * with earlier Boost versions, i.e. 103200. - */ - int desired_read = sizeof(pid_t); - if ( desired_read > ::read(lf.fd, & pid, desired_read) ) { - throw Exception("Cannot read lock file " + name); - } + pid_t pid = lf.readPid(); if (kill(pid, 0) < 0 && errno != EPERM) { unlink(name.c_str()); throw Exception("Removing stale lock file "+name); -- cgit v1.2.1