libuv / libuv/libuv

macos: restoring signal disposition doesn't work as flags are not propagated

Open
#4,299 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
27.2k
Forks
3.9k
Avg merge
2d 16h
Merged PRs (30d)
17

Description

Take this very basic example:

#include <stdio.h>
#include <signal.h>
#include <stdlib.h>

void handler(int signum) {
    printf("Signal handler called with signal %d\n", signum);
}

int main() {
    struct sigaction sa, old_sa;

    // Set a signal handler with SA_RESETHAND flag
    sa.sa_handler = handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_RESETHAND;
    if (sigaction(SIGINT, &sa, NULL) == -1) {
        perror("sigaction");
        exit(1);
    }

    // Set a second signal handler without SA_RESETHAND flag
    sa.sa_flags = 0;
    if (sigaction(SIGINT, &sa, &old_sa) == -1) {
        perror("sigaction");
        exit(1);
    }

    // Check whether the SA_RESETHAND flag is actually propagated
    if (old_sa.sa_flags & SA_RESETHAND) {
        printf("SA_RESETHAND was set in the old signal handler\n");
    } else {
        printf("SA_RESETHAND was not set in the old signal handler\n");
    }

    return 0;
}

Running this on linux produces the correct output:

$ SA_RESETHAND was set in the old signal handler

Whereas on macos (arm64) it doesn't:

$ SA_RESETHAND was not set in the old signal handler

I observed this while running current v1.x with the node.js test suite and caused some signal tests to fail. They started failing after https://github.com/libuv/libuv/commit/b9421d70665352138557d2d2338656a38ac70691, though I don't know if there's much we can do from the libuv side as it seems a macos issue. Thoughts?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the C reproducer in the issue and compare macOS and Linux sigaction behavior, then review the libuv change referenced by commit b9421d70665352138557d2d2338656a38ac70691. The issue names no repository file or test path; done means determining whether libuv can work around the macOS flag behavior or documenting that it cannot, with the Node.js signal failures understood.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, macos
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.