summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhsldymq <hsldymq@qq.com>2018-06-28 02:25:11 +0800
committerNikita Popov <nikita.ppv@gmail.com>2019-02-12 10:09:33 +0100
commitb5cb3ac8ecab71bfe1eb7d5b2d7a48970e11a5b4 (patch)
tree6c780c6aa918ebfc4d8fa21f52828c3f40279386
parenta109fddba4e3fbb6e3a2e008c0fa20a57f26103d (diff)
downloadphp-git-b5cb3ac8ecab71bfe1eb7d5b2d7a48970e11a5b4.tar.gz
Make pid & uid available while handling realtime signals
-rw-r--r--ext/pcntl/pcntl.c6
-rw-r--r--ext/pcntl/tests/pcntl_realtime_signal.phpt20
2 files changed, 26 insertions, 0 deletions
diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c
index 228111d351..36d2a672ab 100644
--- a/ext/pcntl/pcntl.c
+++ b/ext/pcntl/pcntl.c
@@ -1276,6 +1276,12 @@ static void pcntl_siginfo_to_zval(int signo, siginfo_t *siginfo, zval *user_sigi
break;
#endif
}
+#if defined(SIGRTMIN) && defined(SIGRTMAX)
+ if (SIGRTMIN <= signo && signo <= SIGRTMAX) {
+ add_assoc_long_ex(user_siginfo, "pid", sizeof("pid")-1, siginfo->si_pid);
+ add_assoc_long_ex(user_siginfo, "uid", sizeof("uid")-1, siginfo->si_uid);
+ }
+#endif
}
}
/* }}} */
diff --git a/ext/pcntl/tests/pcntl_realtime_signal.phpt b/ext/pcntl/tests/pcntl_realtime_signal.phpt
new file mode 100644
index 0000000000..212f15e03b
--- /dev/null
+++ b/ext/pcntl/tests/pcntl_realtime_signal.phpt
@@ -0,0 +1,20 @@
+--TEST--
+pcntl_signal() context of realtime signal
+--SKIPIF--
+<?php if (!defined('SIGRTMIN')) die("skip realtime signal not supported"); ?>
+<?php if (!extension_loaded("pcntl")) print "skip"; ?>
+<?php if (!extension_loaded("posix")) die("skip posix extension not available"); ?>
+--FILE--
+<?php
+
+pcntl_signal(SIGRTMIN, function ($signo, $siginfo) {
+ printf("got realtime signal from %s, ruid:%s\n", $siginfo['pid'] ?? '', $siginfo['uid'] ?? '');
+});
+posix_kill(posix_getpid(), SIGRTMIN);
+pcntl_signal_dispatch();
+
+echo "ok\n";
+?>
+--EXPECTF--
+%rgot realtime signal from \d+, ruid:\d+%r
+ok