signal handling issues

Liste des GroupesRevenir à cu programmer 
Sujet : signal handling issues
De : rweikusat (at) *nospam* talktalk.net (Rainer Weikusat)
Groupes : comp.unix.programmer
Date : 30. Jan 2025, 18:57:45
Autres entêtes
Message-ID : <874j1g18x2.fsf@doppelsaurus.mobileactivedefense.com>
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Up to and including The Open Group Base Specifications Issue 6, the
following program was a correct way of using signal handlers:

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

static void alarmed(int unused)
{
    puts("I was alarmed!");
    alarm(2);
}

static void interrupted(int unused)
{
    puts("I was interrupted!");
    exit(0);
}

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

    sigemptyset(&sa.sa_mask);
    sigaddset(&sa.sa_mask, SIGALRM);
    sigaddset(&sa.sa_mask, SIGINT);
    sa.sa_flags = 0;

    sigprocmask(SIG_BLOCK, &sa.sa_mask, &omask);

    sa.sa_handler = alarmed;
    sigaction(SIGALRM, &sa, NULL);

    sa.sa_handler = interrupted;
    sigaction(SIGINT, &sa, NULL);

    alarm(2);
    while (1) sigsuspend(&omask);

    return 0;
}
----

As the only requirement for functions not listed as async-signal-safe
was

In the presence of signals, all functions defined by this volume
of IEEE Std 1003.1-2001 shall behave as defined when called from
or interrupted by a signal-catching function, with a single
exception: when a signal interrupts an unsafe function and the
signal-catching function calls an unsafe function, the behavior
is undefined.

Since version 7, its behaviour is undefined because the following
requirement was added:

If the process is multi-threaded, or if the process is
single-threaded and a signal handler is executed other than as
the result of:
       

    The process calling abort(), raise(), kill(),
    pthread_kill(), or sigqueue() to generate a signal that is
    not blocked

    A pending signal being unblocked and being delivered before
    the call that unblocked it returns

the behavior is undefined if the signal handler
[...]
calls any function defined in this standard other than one of
the functions listed in the following table.

despite the statement from version 6 was retained as is. These two
requirements seem to contradict each other. It would also be
interesting to know what the point of this change was to begin with,
considering that it decreed that code whose behaviour had hitherto been
defined would now have undefined behaviour.

[I think this should be reported as a defect but there doesn't seem to
be a way to do that or at least no obvious way.]

Date Sujet#  Auteur
30 Jan 25 * signal handling issues14Rainer Weikusat
30 Jan 25 +- Re: signal handling issues1Rainer Weikusat
30 Jan 25 +* Re: signal handling issues4Kaz Kylheku
30 Jan 25 i`* Re: signal handling issues3Dan Cross
31 Jan 25 i `* Re: signal handling issues2Rainer Weikusat
31 Jan 25 i  `- Re: signal handling issues1Dan Cross
30 Jan 25 +* Re: signal handling issues5Kaz Kylheku
31 Jan 25 i`* Re: signal handling issues4Muttley
1 Feb 25 i `* Re: signal handling issues3Lawrence D'Oliveiro
2 Feb 25 i  `* Re: signal handling issues2Muttley
4 Feb 25 i   `- Re: signal handling issues1Rainer Weikusat
3 Feb 25 `* Re: signal handling issues3Geoff Clare
6 Feb 25  `* Re: signal handling issues2Geoff Clare
6 Feb 25   `- Re: signal handling issues1Rainer Weikusat

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal