All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Kerrisk <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
To: Sebastian Kienzl <seb-O0gdCS+Gcp8@public.gmane.org>
Cc: linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: Bug in select_tut
Date: Sun, 25 Jan 2009 12:02:08 +0100	[thread overview]
Message-ID: <497C46B0.7050509@gmail.com> (raw)
In-Reply-To: <4971E510.9050301-O0gdCS+Gcp8@public.gmane.org>

Hello Sebastian,

Sebastian Kienzl wrote:
> Hello!
> 
> There's a bug in the select_tut man-page in the chapter "Combining
> Signal and Data Events", which should illustrate pselect()-usage.
> 
> See the attachments for detailed information, proof-code and a proposed
> fix.
> 
> Regards,
> Seb.

What do you think of the revised (but still incomplete)
program below?

Cheers,

Michael

       static volatile sig_atomic_t got_SIGCHILD = 0;

       void
       child_sig_handler(int sig)
       {
           got_SIGCHILD = 1;
       }

       int
       main(int argc, char *argv[])
       {
           sigset_t sigmask, empty_mask;
           struct sigaction sa;
           fd_set readfs, writefds, exceptfds;
           int r;

           sigemptyset(&sigmask);
           sigaddset(&sigmask, SIGCHLD);
           if (sigprocmask(SIG_BLOCK, &sigmask, NULL) == -1) {
               perror("sigprocmask");
               exit(EXIT_FAILURE);
           }

           sa.sa_flags = 0;
           sa.sa_handler = child_sig_handler;
           sigemptyset(&sa.sa_mask);
           if (sigaction(SIGCHILD, &sa, NULL) == -1) {
               perror("sigaction");
               exit(EXIT_FAILURE);
           }

           sigemptyset(empty_mask);

           for (;;) {          /* main loop */
               /* Initialize readfds, writefds, and exceptfds
                  before the pselect() call. (Code omitted.) */

               r = pselect(nfds, &readfs, &writefds, &exceptfd,
                           0, &empty_mask);
               if (r == -1 && errno != EINTR) {
                   /* Handle error */
               }

               if (got_SIGCHILD) {
                   got_SIGCHILD = 0;

                   /* Handle signalled event here; e.g., wait() for all
                      terminated children. (Code omitted.) */
               }

               /* main body of program */
           }
       }
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2009-01-25 11:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4971E510.9050301@riot.org>
     [not found] ` <4971E510.9050301-O0gdCS+Gcp8@public.gmane.org>
2009-01-25 10:37   ` Bug in select_tut Michael Kerrisk
2009-01-25 11:02   ` Michael Kerrisk [this message]
     [not found]     ` <497C46B0.7050509-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-01-26  2:08       ` Michael Kerrisk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=497C46B0.7050509@gmail.com \
    --to=mtk.manpages-gm/ye1e23mwn+bqq9rbeug@public.gmane.org \
    --cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=seb-O0gdCS+Gcp8@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.