`wait4` and `waitid` never return `EINTR` when a handled signal arrives
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 54/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- c
调研方向
Start in src/syscall/proc.c at the polling loops in sys_wait4 and sys_waitid, then compare how the poll, futex and pipe paths use signal_claim_interruption(). The issue describes the required behavior for handlers with and without SA_RESTART and provides a reproducer. Add regression coverage for wait4(pid), wait4(-1) and waitid, checking EINTR without SA_RESTART and successful reap with it.
由索引模型根据 Issue 内容生成。
描述
On Linux, a blocking wait4 or waitid sleeps in do_wait (kernel/exit.c) with TASK_INTERRUPTIBLE and leaves the loop with -ERESTARTSYS once a signal is pending. Signal delivery turns that into EINTR when the handler lacks SA_RESTART, and restarts the wait when it has it. Under elfuse the wait ignores the signal and returns only when the child exits: the polling loops in sys_wait4 and sys_waitid (src/syscall/proc.c) check thread_stop_requested() but never signal_claim_interruption(), which the poll, futex and pipe paths use for the same purpose.
Reproducer (the child signals the parent at 0.2 s and exits 1 s later; the handler has no SA_RESTART):
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
static void on_usr1(int sig)
{
(void) sig;
}
static double now(void)
{
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
return t.tv_sec + t.tv_nsec / 1e9;
}
static void run(const char *name, int mode)
{
pid_t child = fork();
if (child == 0) {
usleep(200000);
kill(getppid(), SIGUSR1);
sleep(1);
_exit(0);
}
double t0 = now();
int status;
siginfo_t si;
long ret;
if (mode == 0)
ret = waitpid(child, &status, 0);
else if (mode == 1)
ret = waitpid(-1, &status, 0);
else
ret = waitid(P_PID, child, &si, WEXITED);
int err = errno;
printf("%-10s ret=%ld %s after %.2fs\n", name, ret,
ret < 0 ? strerror(err) : "", now() - t0);
if (ret < 0)
waitpid(child, &status, 0);
}
int main(void)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = on_usr1;
sigaction(SIGUSR1, &sa, NULL);
run("wait4(pid)", 0);
run("wait4(-1)", 1);
run("waitid", 2);
return 0;
}
wait4(pid) |
wait4(-1) |
waitid |
|
|---|---|---|---|
elfuse c2785c7 |
child pid after 1.2 s | child pid after 1.2 s | 0 after 1.2 s |
| Linux 6.12 under qemu | -1, EINTR after 0.2 s |
-1, EINTR after 0.2 s |
-1, EINTR after 0.2 s |
The SA_RESTART half needs its own handling: elfuse has no general ERESTARTSYS path, so a loop that starts honoring the claimed signal has to keep waiting when that signal's handler has SA_RESTART. A regression test needs the child to stay alive until the handler releases it, and should cover EINTR without SA_RESTART and a successful reap with it, for wait4(pid), wait4(-1) and waitid.
Found by jserv in https://github.com/sysprog21/elfuse/pull/460#discussion_r4348510702: the race fixed there never showed under elfuse for this reason.
- 主要语言
- C
- 星标
- 275
- 派生
- 29
- 平均合并
- 2 天 22 小时
- 30 天内合并 PR
- 18
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
sysprog21/elfuse 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 3 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 3 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 3 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 3 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 55/100
维护者通常 3 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
MerginMaps/geodiff#272 ·
-
难度 2/5 1-3 小时 新手友好度 74/100
open-quantum-safe/liboqs#2644 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
espressif/esp-adf-libs#89 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 2 天内回复