A host signal that ends elfuse leaves its temp-dir files instead of removing them

未关闭
#548 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
62/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c

调研方向

The cleanup is unlink_own_transport in src/syscall/proc.c, registered by proc_preempt_init through atexit; read it first and note the paths it builds. Add sigaction handlers for SIGTERM/SIGINT/SIGHUP that unlink those same precomputed paths, then re-raise under SIG_DFL. Reproduce with the fork-then-hang probe under gtimeout -s TERM 2, diffing ls $TMPDIR | grep '^elfuse-' before and after; tests/test-rosetta-audit.sh (tls0-known-hang, timeout 5) triggers it too. Done when a signalled run leaves no elfuse-* files and the exit status is unchanged.

由索引模型根据 Issue 内容生成。

描述

What happens

unlink_own_transport in src/syscall/proc.c removes a process's temp-dir files when it exits: its signal transport elfuse-sig-<pid> and, for the namespace owner, the registry files elfuse-procs-<ns>, elfuse-life-<ns> and elfuse-pidseq-<ns>. #538 adds the SIGCHLD flag file elfuse-sigchld-<pid> to the same function. It runs only through atexit, and elfuse installs no host handler for SIGTERM, SIGINT or SIGHUP. When timeout, Ctrl-C or a closed terminal ends elfuse, the host process dies without running it, and the files stay in the temp dir until the OS purges it. A run that exits normally removes all of them.

Evidence

The probe below (fork one child, wait for it, sleep), stopped after 2 s:

build stop exit status files left
upstream/main c57282f gtimeout -s TERM 2 124 elfuse-life-<ns>, elfuse-pidseq-<ns>, elfuse-procs-<ns>, elfuse-sig-<pid>
#538 head d823f7e gtimeout -s TERM 2 124 the same four, plus elfuse-sigchld-<pid>
#538 head d823f7e gtimeout -s INT 2 124 the same five

The same probe left nothing when it ran to the end. The tls0-known-hang case of tests/test-rosetta-audit.sh stops elfuse with timeout 5 on purpose, so every make test-matrix run adds files. One developer machine's temp dir held 1636 elfuse-pidseq-*, 287 elfuse-life-*, 216 elfuse-procs-* and 19 elfuse-sigchld-* files.

Cause

proc_preempt_init registers unlink_own_transport with atexit, and nothing else removes these files. A process that a signal ends does not run atexit handlers. Checked by reading and by the runs above.

Reproduce

#include <sys/wait.h>
#include <unistd.h>

int main(void)
{
    pid_t c = fork();
    if (c == 0)
        _exit(0);
    waitpid(c, NULL, 0);
    sleep(5);
    return 0;
}
T=$(getconf DARWIN_USER_TEMP_DIR)
ls "$T" | grep '^elfuse-' | sort > before.txt
gtimeout -s TERM 2 build/elfuse ./fork-then-hang
ls "$T" | grep '^elfuse-' | sort > after.txt
comm -13 before.txt after.txt

Possible fix

  1. Install host handlers for SIGTERM, SIGINT and SIGHUP that unlink this process's own files, from paths computed before the handler can run, and then re-raise the signal under SIG_DFL, so the parent still sees the same death. This does not cover SIGKILL or a crash.
  2. Have a new namespace owner remove elfuse-* files whose owning host process is gone. This covers SIGKILL too, but costs a directory scan at every root start.

Origin

Follow-up from #538 (https://github.com/sysprog21/elfuse/pull/538).

主要语言
C
星标
287
派生
33
平均合并
2 天 17 小时
30 天内合并 PR
18

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

sysprog21/elfuse 的其他 Issue

查看 sysprog21/elfuse 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。