Thread: select/poll and Signal Safety

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    5

    select/poll and Signal Safety

    Hi

    I am struggling to understand why one should use pselect()/ppoll() instead of wrapping an ordinary select() or poll() call around sigprocmask(). The linux man page talks about “race conditions”, but how would such dangers occur?

    I plan to use poll() for an application (since ppoll() isn’t widely supported) but wish to know how (if possible) it can be made signal safe? please see preliminary code scenario below.

    Code:
    void foofunc() {
    	int retval;
    
    	sigprocmask(...); // block certain signals
    
    	...
    
    	while(1) {
    		sigprocmask(...); // set empty mask
    
    		// <- can something go wrong here?
    
    		retval = poll(...); // wait indefinitely
    
    		// <- and what about here?
    
    		sigprocmask(...); // restore old mask
    
    		if (retval != -1) {
    			... // handle file descriptor events
    		} else (errno == EINTR) {
    			// just signal interruptions, don't panic
    		} else {
    			... // handle error
    		}
    	}
    }
    Any help is greatly appreciated.
    Last edited by nopcoder; 01-27-2006 at 08:27 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-07-2009, 10:05 AM
  2. Signal and exception handling
    By nts in forum C++ Programming
    Replies: 23
    Last Post: 11-15-2007, 02:36 PM
  3. Signal question
    By fnoyan in forum Linux Programming
    Replies: 2
    Last Post: 06-01-2006, 05:46 AM
  4. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 10:56 AM
  5. signal handling
    By trekker in forum C Programming
    Replies: 2
    Last Post: 07-05-2002, 02:52 AM