Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending a signal causes any previously pending signals to disappear #1232

Open
adamdebek opened this issue Nov 15, 2024 · 0 comments
Open

Sending a signal causes any previously pending signals to disappear #1232

adamdebek opened this issue Nov 15, 2024 · 0 comments
Labels
bug Something isn't working kernel

Comments

@adamdebek
Copy link
Contributor

Reproduction (ia32-generic-qemu):

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

volatile int sig_recvd;

void handler(int sig) {
    sig_recvd = sig;
}


int main(void) {
    sigset_t set;
    struct sigaction sa;

    sigemptyset(&set);
    sigaddset(&set, SIGHUP);
    sigaddset(&set, SIGPIPE);

    if (sigprocmask(SIG_SETMASK, &set, NULL) < 0) {
        perror("sigprocmask");
        exit(EXIT_FAILURE);
    }

    sa.sa_handler = handler;
    sa.sa_flags = 0;
    sigemptyset(&sa.sa_mask);

    if (sigaction(SIGHUP, &sa, NULL) < 0 || sigaction(SIGPIPE, &sa, NULL) < 0) {
        perror("sigaction");
        exit(EXIT_FAILURE);
    }

    if (kill(getpid(), SIGHUP) < 0 || kill(getpid(), SIGPIPE) < 0) {
        perror("kill");
        exit(EXIT_FAILURE);
    }

#if 1
    if (kill(getpid(), SIGCHLD) < 0) {
        perror("kill wtih sigchild");
        exit(EXIT_FAILURE);
    }
#endif

    if (sig_recvd == SIGHUP && sig_recvd == SIGPIPE) {
        printf("Error: Received on block\n");
        exit(EXIT_FAILURE);
    }

    sig_recvd = 0;

    sigemptyset(&set);
    sigaddset(&set, SIGHUP);
    sigaddset(&set, SIGPIPE);

    if (sigprocmask(SIG_UNBLOCK, &set, NULL) < 0) {
        perror("sigprocmask");
        exit(EXIT_FAILURE);
    }

    if (sig_recvd != SIGHUP && sig_recvd != SIGPIPE) {
        printf("Error: No signal after unblock\n");
        exit(EXIT_FAILURE);
    }
    else {
        printf("success\n");
        exit(EXIT_SUCCESS);
    }

    return 0;
}
@adamdebek adamdebek added the bug Something isn't working label Nov 15, 2024
@adamdebek adamdebek changed the title Sending signal make already pending signals to disappear Sending a signal causes any previously pending signals to disappear Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working kernel
Projects
None yet
Development

No branches or pull requests

2 participants