• signalfd()

    From Muttley@DastardlyHQ.org@21:1/5 to All on Mon Feb 24 09:51:08 2025
    Hi

    I've been playing around with signalfd() on linux and it seems to work but there also seems to be zero information other than the signal number in the signalfd_siginfo structure returned from a read().

    Where I'd expect PID and UID to be set as in reception of a signal handler
    set using sigaction with the siginfo_t passed to the handler, the below code returns 0 for everything in the signalfd_siginfo structure.

    The relevant parts of the code are below. Have I done something wrong?

    struct signalfd_siginfo siginfo;
    :
    :
    sigemptyset(&sigset);
    sigaddset(&sigset,SIGINT); /* Control-C */
    sigaddset(&sigset,SIGTSTP); /* Control-Z */

    if (sigprocmask(SIG_BLOCK,&sigset,NULL) == -1)
    {
    perror("ERROR: sigprocmask()");
    return 1;
    }

    if ((fd = signalfd(-1,&sigset,0)) == -1)
    {
    perror("ERROR: signalfd()");
    return 1;
    }

    :
    :

    while(1)
    {
    FD_ZERO(&mask);
    FD_SET(fd,&mask);

    switch(select(FD_SETSIZE,&mask,0,0,NULL))
    :
    :


    if (FD_ISSET(fd,&mask))
    {
    len = read(fd,&siginfo,sizeof(siginfo));
    if (len == -1)
    {
    perror("ERROR: read(fd)");
    return 1;
    }
    if (len != sizeof(siginfo))
    {
    printf("WARNING: Expected %lu bytes, got %d\n",
    sizeof(siginfo),len);
    }
    printf("RX signal %d:\n",siginfo.ssi_signo);
    printf(" Error: %d\n",siginfo.ssi_errno);
    printf(" PID : %d\n",siginfo.ssi_pid);
    printf(" UID : %d\n",siginfo.ssi_uid);
    printf(" UTime: %lu\n",siginfo.ssi_utime);
    printf(" STime: %lu\n",siginfo.ssi_stime);
    }
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Muttley@DastardlyHQ.org on Mon Feb 24 14:18:44 2025
    Muttley@DastardlyHQ.org writes:
    Hi

    I've been playing around with signalfd() on linux and it seems to work but >there also seems to be zero information other than the signal number in the >signalfd_siginfo structure returned from a read().

    Where I'd expect PID and UID to be set as in reception of a signal handler >set using sigaction with the siginfo_t passed to the handler, the below code >returns 0 for everything in the signalfd_siginfo structure.

    I wonder if you still need to call sigaction with SA_SIGINFO before
    using signalfd?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rainer Weikusat@21:1/5 to Muttley@DastardlyHQ.org on Mon Feb 24 15:19:19 2025
    Muttley@DastardlyHQ.org writes:
    Hi

    I've been playing around with signalfd() on linux and it seems to work but there also seems to be zero information other than the signal number in the signalfd_siginfo structure returned from a read().

    Where I'd expect PID and UID to be set as in reception of a signal handler set using sigaction with the siginfo_t passed to the handler, the below code returns 0 for everything in the signalfd_siginfo structure.

    The relevant parts of the code are below. Have I done something wrong?

    struct signalfd_siginfo siginfo;
    :
    :
    sigemptyset(&sigset);
    sigaddset(&sigset,SIGINT); /* Control-C */
    sigaddset(&sigset,SIGTSTP); /* Control-Z */

    [...]

    sigaction(2) documents the details regarding which fields in a siginfo structure will be set under which conditions and if were using C-c and
    C-z to generate signals, the pid and uid values shouldn't be set. They
    should be set when using kill(2) or sigqueue(2) to send signals.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Muttley@DastardlyHQ.org@21:1/5 to All on Mon Feb 24 15:51:29 2025
    On Mon, 24 Feb 2025 14:18:44 GMT
    scott@slp53.sl.home (Scott Lurndal) wibbled:
    Muttley@DastardlyHQ.org writes:
    Hi

    I've been playing around with signalfd() on linux and it seems to work but >>there also seems to be zero information other than the signal number in the >>signalfd_siginfo structure returned from a read().

    Where I'd expect PID and UID to be set as in reception of a signal handler >>set using sigaction with the siginfo_t passed to the handler, the below code >>returns 0 for everything in the signalfd_siginfo structure.

    I wonder if you still need to call sigaction with SA_SIGINFO before
    using signalfd?

    Actually my mistake - the pid and uid are only zerop when it receives a signal from the terminal but when another process sends it it works ok. Thanks for
    the idea though.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Muttley on Mon Feb 24 20:27:27 2025
    On Mon, 24 Feb 2025 15:51:29 -0000 (UTC), Muttley wrote:

    ... the pid and uid are only zerop when it receives a
    signal from the terminal but when another process sends it it works ok.

    Just confirmed that with the following test program:

    import asyncio
    import linuxproc as lxp
    from linuxproc import \
    SIG, \
    SigProcMask, \
    SignalFile

    async def main() :
    to_block = SigProcMask({SIG.TERM, SIG.INT})
    notif = SignalFile.create(to_block)
    to_block.apply_replace()
    while True :
    evt = await notif.get_next_async(timeout = 1)
    print(evt)
    #end while
    #end main

    asyncio.run(main())

    using my Python wrappers at <https://gitlab.com/ldo/python_linuxfs>.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)