]> granicus.if.org Git - php/commitdiff
Make pid & uid available while handling realtime signals
authorhsldymq <hsldymq@qq.com>
Wed, 27 Jun 2018 18:25:11 +0000 (02:25 +0800)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 12 Feb 2019 09:09:33 +0000 (10:09 +0100)
ext/pcntl/pcntl.c
ext/pcntl/tests/pcntl_realtime_signal.phpt [new file with mode: 0644]

index 228111d351c072d8ef0d6bfde9484e6fb9f106a2..36d2a672ab90f473db864155ba3c0b03ae4edb92 100644 (file)
@@ -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 (file)
index 0000000..212f15e
--- /dev/null
@@ -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