Make pid & uid available while handling realtime signals

This commit is contained in:
hsldymq 2018-06-28 02:25:11 +08:00 committed by Nikita Popov
parent a109fddba4
commit b5cb3ac8ec
2 changed files with 26 additions and 0 deletions

View 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
}
}
/* }}} */

View File

@ -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