Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Feb 1997 14:23:19 +1100
From:      Bruce Evans <bde@zeta.org.au>
To:        bde@zeta.org.au, mpp@freefall.freebsd.org
Cc:        freebsd-hackers@freefall.freebsd.org
Subject:   Re: sig*set macros in <signal.h>
Message-ID:  <199702280323.OAA26377@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>I've got a PR I was fixing, and it says that POSIX requires that these
>functions check the value of the signal number that was passed in, and
>return -1 if it is out of range, and set errno to EINVAL.

If you fix this, then it is reasonable to remove the macros.

However, POSIX doesn't require that these functions detect errors,
and it only requires errno to be set if an error is detected.  It does
require that sigismember() returns the following values:

	-1: an error was detected
	0: the signal number is not in the set
	1: the signal number is in the set

The current implementation is broken here.  It returns 1 for some invalid
signal numbers.  Invalid signal number can reasonably be interpreted as
non-errors, but they can't reasonably be interpreted as being in the set.

I think POSIX also requires that invalid signal numbers don't cause
undefined behaviour.  Shifts of < 0 or >= the size of the scalar type
sigset_t cause undefined behaviour, but this doesn't matter because
the actual behaviour is harmless on all supported machines.

>Doing this in the macro versions now causes name space polution in signal.h,
>because they now depend on errno.h for EINVAL and errno.

I think the letter and even the spirit of POSIX would be satisfied if
you just changed sigemptyset() to return 0 for invalid signal numbers.
Something like:

	return ((signo) <= 0 || (signo) > NSIG ? 0 : same_value_as_now())

This needs more work:

1. NSIG pollutes the namespace.  Use a new identifier _NSIG.
2. signo is multiply evaluated.  I think it is impossible to write a
   correct macro for sigemptyset() in C :-(.  It is easy in GNU C
   using a statement expression :-).  Note that signo is usually a literal
   constant so gcc would not generate any code for the range checking.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199702280323.OAA26377>