From 3792e2819d8b2f7fe96a0260a0f280712b225f74 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 11 Jul 2018 00:32:47 +0200 Subject: [PATCH] Use a process identifier for logging that contains the pid (#5359) --- src/App.php | 2 +- src/Core/System.php | 12 ++++++++++++ src/Core/Worker.php | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/App.php b/src/App.php index 097b5e541d..38b207c266 100644 --- a/src/App.php +++ b/src/App.php @@ -193,7 +193,7 @@ class App $this->query_string = ''; - $this->process_id = uniqid('log', true); + $this->process_id = System::processID('log'); set_time_limit(0); diff --git a/src/Core/System.php b/src/Core/System.php index 46d1b34e55..98ae3da2d9 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -203,6 +203,18 @@ EOT; } } + /** + * Generates a process identifier for the logging + * + * @param string $prefix A given prefix + * + * @return string a generated process identifier + */ + public static function processID($prefix) + { + return uniqid($prefix . ':' . str_pad(getmypid() . ':', 8, '0') . ':'); + } + /// @todo Move the following functions from boot.php /* function killme() diff --git a/src/Core/Worker.php b/src/Core/Worker.php index c4c91bbf8b..296d40b504 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -141,7 +141,7 @@ class Worker if (Config::get('system', 'worker_daemon_mode', false)) { self::IPCSetJobState(false); } - logger("Couldn't select a workerqueue entry, quitting.", LOGGER_DEBUG); + logger("Couldn't select a workerqueue entry, quitting process " . getmypid() . ".", LOGGER_DEBUG); } /** @@ -309,7 +309,7 @@ class Worker $argc = count($argv); - $new_process_id = uniqid("wrk", true); + $new_process_id = System::processID("wrk"); logger("Process ".$mypid." - Prio ".$queue["priority"]." - ID ".$queue["id"].": ".$funcname." ".$queue["parameter"]." - Process PID: ".$new_process_id); -- 2.39.5