signalfd()

Liste des GroupesRevenir à cu programmer 
Sujet : signalfd()
De : Muttley (at) *nospam* DastardlyHQ.org
Groupes : comp.unix.programmer
Date : 24. Feb 2025, 10:51:08
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vphfec$1158f$1@dont-email.me>
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);
                }
}



Date Sujet#  Auteur
24 Feb 25 * signalfd()4Muttley
24 Feb 25 +- Re: signalfd()1Rainer Weikusat
24 Feb 25 `* Re: signalfd()2Muttley
24 Feb 25  `- Re: signalfd()1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal