Merge branch 'MDL-87079-401' of https://github.com/andrewnicols/moodle into MOODLE_401_STABLE

This commit is contained in:
Huong Nguyen
2025-11-06 15:38:23 +07:00
2 changed files with 23 additions and 2 deletions
+20 -2
View File
@@ -39,6 +39,9 @@ class core_shutdown_manager {
/** @var bool is this manager already registered? */
protected static $registered = false;
/** @var array A list of pcntl handlers */
protected static array $pcntlhandlers = [];
/**
* Register self as main shutdown handler.
*
@@ -58,8 +61,19 @@ class core_shutdown_manager {
if (CLI_SCRIPT && extension_loaded('pcntl') && function_exists('pcntl_async_signals')) {
// We capture and handle SIGINT (Ctrl+C) and SIGTERM (termination requested).
pcntl_async_signals(true);
pcntl_signal(SIGINT, ['core_shutdown_manager', 'signal_handler']);
pcntl_signal(SIGTERM, ['core_shutdown_manager', 'signal_handler']);
$signals = [SIGINT, SIGTERM];
foreach ($signals as $signal) {
if (function_exists('pcntl_signal_get_handler')) {
$handler = pcntl_signal_get_handler($signal);
if (is_callable($handler)) {
// We can restore the original handler later if needed.
self::$pcntlhandlers[$signal] = $handler;
}
}
pcntl_signal($signal, ['core_shutdown_manager', 'signal_handler']);
}
}
}
@@ -106,6 +120,10 @@ class core_shutdown_manager {
error_log('Exception ignored in signal function ' . get_callable_name($callback) . ': ' . $e->getMessage());
}
}
if (array_key_exists($signo, self::$pcntlhandlers)) {
$handler = self::$pcntlhandlers[$signo];
$handler($signo);
}
if ($shouldexit) {
exit ($exitcode);
+3
View File
@@ -1,6 +1,9 @@
This files describes API changes in core libraries and APIs,
information provided here is intended especially for developers.
=== 4.1.22 ===
* message: When responding to pcntl signals, call existing signal handlers.
=== 4.1.21 ===
* Moodle's Behat `::execute()` method now supports the use of array callable syntax for calling other steps.