From 997686f42a47d910de4b247f97f6779583cfbb4f Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Sun, 3 Jan 2016 11:30:53 +0000 Subject: [PATCH] Minor re-organisation and logging improvements --- service.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/service.cc b/service.cc index bce32fa..13929f3 100644 --- a/service.cc +++ b/service.cc @@ -301,8 +301,6 @@ void ServiceRecord::allDepsStarted(bool has_console) noexcept waiting_for_deps = false; - if (has_console) log_to_console = false; - if (service_type == ServiceType::PROCESS || service_type == ServiceType::BGPROCESS || service_type == ServiceType::SCRIPTED) { bool start_success = start_ps_process(); @@ -323,6 +321,7 @@ void ServiceRecord::acquiredConsole() noexcept releaseConsole(); } else if (startCheckDependencies(false)) { + log_to_console = false; allDepsStarted(true); } else { @@ -342,8 +341,8 @@ void ServiceRecord::started() noexcept const char *pid_file_c = pid_file.c_str(); int fd = open(pid_file_c, O_CLOEXEC); if (fd != -1) { - char pidbuf[10]; - int r = read(fd, pidbuf, 9); + char pidbuf[21]; // just enought to hold any 64-bit integer + int r = read(fd, pidbuf, 20); if (r > 0) { pidbuf[r] = 0; // store nul terminator pid = std::atoi(pidbuf); @@ -353,7 +352,11 @@ void ServiceRecord::started() noexcept ev_child_start(ev_default_loop(EVFLAG_AUTO), &child_listener); } else { + log(LogLevel::ERROR, service_name, ": pid read from pidfile (", pid, ") is not valid"); pid = -1; + failed_to_start(); + close(fd); + return; } } close(fd); -- 2.25.1