Subject: fvwm 2.2, select() and autoconf

From: Chris Rankin <[email-masked]>
Date: Sun, 16 May 1999 18:43:37 +1000 (EST)

Hi,

I am tinkering with the select() function in FVWM 2.2 in order to
remove a small race-condition in the signal handling. Now in order to
make things nicely "autoconfy" I think I'm going to need a prototype
like this:

#ifdef  HAVE_SELECT
extern int fvwmSelect(SELECT_TYPE_ARG1   nfds,
                      SELECT_TYPE_ARG234 readfds,
                      SELECT_TYPE_ARG234 writefds,
                      SELECT_TYPE_ARG234 exceptfds,
                      SELECT_TYPE_ARG5   timeout);
#endif

This is currently impossible because SELECT_TYPE_ARG234 (e.g.) is
defined to be "(fd_set *)" on my system (Linux-2.2.9 and glibc-2.1);
basically the brackets cause trouble. Can the brackets be removed from
the autoconf-ing (and the typecasting changed accordingly, I presume)
or do they NEED to be there because of the way some C-preprocessors
work?

Cheers,
Chris.
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Steve Robbins <[email-masked]>
Date: Sun, 16 May 1999 09:17:56 -0400 (EDT)

> or do they NEED to be there because of the way some C-preprocessors

Yes, the brackets can be removed.  I have submitted the modifications to
the autoconf maintainer.  The originator of the autoconf-magic for
select() agreed that the changes were good, so I *think* this means the
new macro for select will show up in the next autoconf.

But we needn't wait for the next autoconf.  I will incorporate the new
macro into fvwm's acinclude.m4 and we will use it now.

The new select macro has the following behaviour:

1. a type called "fd_set_size_t" is defined
   this is the type for select's first argument

2. a type called "fd_set" is defined, if not already done in systems
   headers;  this is the type for arguments 2-4

3. argument five is always type "struct timeval *"

4. there are some weirdo systems (apparently) that define and use an
   "fd_set" type for FD_SET() macros, but their select() call is 
   prototyped with "int" in argument 2-4.  A special preprocessor
   symbol "SELECT_FD_SET_CAST" is defined.  Normally, it is blank,
   but on the weirdo systems, it will be something like "(int)".

The upshot of all of this is that you code using types fd_set_size_t,
fd_set, and "struct timeval", and use SELECT_FD_SET_CAST to cast function
calls.

#include "config.h"

#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>

#ifdef HAVE_SYS_SELECT_H
#  include <sys/select.h>
#endif

int main( int ac, char* av[] ) 
{
    fd_set read_fds;
    fd_set_size_t num_fds;
    struct timeval tv;
    int retval;

    /* Watch stdin (fd 0) to see when it has input. */
    FD_ZERO(&read_fds);
    FD_SET(0, &read_fds);
    num_fds = 1;

    /* Wait up to five seconds. */
    tv.tv_sec = 5;
    tv.tv_usec = 0;

    retval = select(num_fds, SELECT_FD_SET_CAST &read_fds, NULL, NULL, &tv);
    /* Don't rely on the value of tv now! */

    if (retval)
	printf("Data is available now.\n");
    /* FD_ISSET(0, &rfds) will be true. */
    else
	printf("No data within five seconds.\n");
    
    exit(0);
}

---

From: [email-masked] (Paul D. Smith)
Date: 16 May 1999 14:58:13 -0400

I also have this already done for GNU make, since the next version uses
POSIX wait*() etc. instead of buggy pre-POSIX signal handling.  So, if
you need the new autoconf macro let me know.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <[email-masked]>         Network Management Development
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
   These are my opinions---Nortel Networks takes no responsibility for them.
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Steve Robbins <[email-masked]>
Date: Mon, 17 May 1999 08:45:37 -0400 (EDT)

>                       SELECT_TYPE_ARG5   timeout);

The new select macro is now in CVS, so this prototype would become:

extern int fvwmSelect(  fd_set_size_t nfds,
			fd_set* readfds,
			fd_set* writefds,
			fd_set* exceptfds,
			struct timeval* timeout );

---

From: Chris Rankin <[email-masked]>
Date: Mon, 17 May 1999 23:56:58 +1000 (EST)

> 			struct timeval* timeout );

Thanks guys; this makes my job a lot easier,
Cheers,
Chris.