rt_sigaction keeps a signal pending that it now ignores where Linux drops it
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- c
調査の方向性
Start in signal_rt_sigaction in src/syscall/signal.c, where the new action is installed and nothing is dropped unless the signal is SIGCHLD. Read sigchld_flush_pending_locked from #538 and extend it to any signal the new action ignores, keeping the posix_timer_dequeued_locked settle. Run the probe in the issue with elfuse-probe-diff; done when the SIGUSR1, SIGWINCH and SIGURG cases report pending 0 after the ignoring action and the handler does not run.
索引モデルが issue の本文から書いたものです。
説明
What happens
When rt_sigaction installs an action that ignores a signal (SIG_IGN, or SIG_DFL for a signal whose default is to ignore it, such as SIGURG or SIGWINCH), signal_rt_sigaction in src/syscall/signal.c leaves a pending instance of that signal pending. When the program then installs a handler again and unblocks the signal, the handler runs. Linux's do_sigaction (kernel/signal.c) drops the pending signal from the shared set and from every thread's set when the new action ignores it (flush_sigqueue_mask), so the handler never runs. #538 adds that drop for SIGCHLD only.
Evidence
The probe below, run with elfuse-probe-diff. Each case blocks the signal, sends it to the process with kill, installs the ignoring action, then the handler again, and unblocks:
| case | elfuse, upstream/main c57282f and #538 at 850d08a | Linux 6.18.63 (QEMU) |
|---|---|---|
SIGUSR1, then SIG_IGN |
still pending after SIG_IGN; the handler runs |
dropped; the handler does not run |
SIGWINCH, then SIG_DFL |
still pending after SIG_DFL; the handler runs |
dropped; the handler does not run |
SIGURG, then SIG_DFL |
still pending after SIG_DFL; the handler runs |
dropped; the handler does not run |
Cause
Checked by reading: signal_rt_sigaction drops nothing for a signal other than SIGCHLD; the disposition is checked only at delivery, and by then the handler is back.
Reproduce
/* A signal pending while blocked; then an action that ignores it, the handler
* again, and an unblock. Linux's do_sigaction drops the pending signal. */
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static volatile sig_atomic_t runs;
static void on_sig(int sig) { (void) sig; runs++; }
static void check(int sig, void (*ignore)(int), const char *name)
{
struct sigaction catch, drop;
memset(&catch, 0, sizeof(catch));
sigemptyset(&catch.sa_mask);
catch.sa_handler = on_sig;
drop = catch;
drop.sa_handler = ignore;
sigset_t set, pending;
sigemptyset(&set);
sigaddset(&set, sig);
runs = 0;
sigaction(sig, &catch, NULL);
sigprocmask(SIG_BLOCK, &set, NULL);
kill(getpid(), sig);
sigpending(&pending);
int before = sigismember(&pending, sig);
sigaction(sig, &drop, NULL);
sigpending(&pending);
int after = sigismember(&pending, sig);
sigaction(sig, &catch, NULL);
sigprocmask(SIG_UNBLOCK, &set, NULL);
printf("%s: pending before %d, after %d, handler ran %s\n", name, before,
after, runs ? "yes" : "no");
}
int main(void)
{
check(SIGUSR1, SIG_IGN, "SIGUSR1, SIG_IGN");
check(SIGWINCH, SIG_DFL, "SIGWINCH, SIG_DFL");
check(SIGURG, SIG_DFL, "SIGURG, SIG_DFL");
return 0;
}
Possible fix
Extend sigchld_flush_pending_locked from #538 to any signal whose new action ignores it, keeping the POSIX timer settle it does on a drop (posix_timer_dequeued_locked), so a timer whose signal is dropped fires again.
Origin
Follow-up from #538 (https://github.com/sysprog21/elfuse/pull/538), which drops a pending SIGCHLD this way. Related: #515 (signal_queue keeps an ignored signal pending when it is generated, a different path).
- 主要言語
- C
- スター
- 287
- フォーク
- 33
- 平均マージ
- 2日 17時間
- マージ済み PR(30日)
- 18
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
sysprog21/elfuse のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 2 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
メンテナーはふだん 2 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 2 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 2 日以内に返信
sysprog21/elfuse の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
libreswan/libreswan#3185 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
category:port-update
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
llvm:instcombine
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
llvm/llvm-project#246503 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信