Skip to content

Commit b5cb3ac

Browse files
hsldymqnikic
authored andcommitted
Make pid & uid available while handling realtime signals
1 parent a109fdd commit b5cb3ac

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

ext/pcntl/pcntl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,12 @@ static void pcntl_siginfo_to_zval(int signo, siginfo_t *siginfo, zval *user_sigi
12761276
break;
12771277
#endif
12781278
}
1279+
#if defined(SIGRTMIN) && defined(SIGRTMAX)
1280+
if (SIGRTMIN <= signo && signo <= SIGRTMAX) {
1281+
add_assoc_long_ex(user_siginfo, "pid", sizeof("pid")-1, siginfo->si_pid);
1282+
add_assoc_long_ex(user_siginfo, "uid", sizeof("uid")-1, siginfo->si_uid);
1283+
}
1284+
#endif
12791285
}
12801286
}
12811287
/* }}} */
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
pcntl_signal() context of realtime signal
3+
--SKIPIF--
4+
<?php if (!defined('SIGRTMIN')) die("skip realtime signal not supported"); ?>
5+
<?php if (!extension_loaded("pcntl")) print "skip"; ?>
6+
<?php if (!extension_loaded("posix")) die("skip posix extension not available"); ?>
7+
--FILE--
8+
<?php
9+
10+
pcntl_signal(SIGRTMIN, function ($signo, $siginfo) {
11+
printf("got realtime signal from %s, ruid:%s\n", $siginfo['pid'] ?? '', $siginfo['uid'] ?? '');
12+
});
13+
posix_kill(posix_getpid(), SIGRTMIN);
14+
pcntl_signal_dispatch();
15+
16+
echo "ok\n";
17+
?>
18+
--EXPECTF--
19+
%rgot realtime signal from \d+, ruid:\d+%r
20+
ok

0 commit comments

Comments
 (0)