[klibc] Signal masks are 1-based, not 0-based

Signal masks are apparently 1-based (signal 0 is not in the set.)
Fix that, and add test code for it in sigint.c.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
diff --git a/usr/include/signal.h b/usr/include/signal.h
index 4751b78..bb6b470 100644
--- a/usr/include/signal.h
+++ b/usr/include/signal.h
@@ -68,18 +68,21 @@
 static __inline__ int sigaddset(sigset_t * __set, int __signum)
 {
 	unsigned long *__lset = (unsigned long *)__set;
+	__signum--;		/* Signal 0 is not in the set */
 	__lset[__signum / LONG_BIT] |= 1UL << (__signum % LONG_BIT);
 	return 0;
 }
 static __inline__ int sigdelset(sigset_t * __set, int __signum)
 {
 	unsigned long *__lset = (unsigned long *)__set;
+	__signum--;		/* Signal 0 is not in the set */
 	__lset[__signum / LONG_BIT] &= ~(1UL << (__signum % LONG_BIT));
 	return 0;
 }
 static __inline__ int sigismember(sigset_t * __set, int __signum)
 {
 	unsigned long *__lset = (unsigned long *)__set;
+	__signum--;		/* Signal 0 is not in the set */
 	return (int)((__lset[__signum / LONG_BIT] >> (__signum % LONG_BIT)) &
 		     1);
 }
diff --git a/usr/klibc/tests/sigint.c b/usr/klibc/tests/sigint.c
index 55ed6ef..f11ae1f 100644
--- a/usr/klibc/tests/sigint.c
+++ b/usr/klibc/tests/sigint.c
@@ -19,6 +19,7 @@
 {
 	struct sigaction act, oact;
 	pid_t f;
+	sigset_t set;
 
 	(void)argc;
 
@@ -31,13 +32,23 @@
 	sigaction(SIGINT, &act, &oact);
 	sigaction(SIGTERM, &act, &oact);
 
+	sigemptyset(&set);
+	sigaddset(&set, SIGINT);
+	sigprocmask(SIG_BLOCK, &set, NULL);
+
 	f = fork();
 
 	if (f < 0) {
 		perror(argv[0]);
 		exit(255);
 	} else if (f > 0) {
-		sleep(5);
+		sleep(3);
+		if (counter) {
+			fprintf(stderr, "Signal received while masked!\n");
+			exit(1);
+		}
+		sigprocmask(SIG_UNBLOCK, &set, NULL);
+		sleep(3);
 		if (!counter) {
 			fprintf(stderr, "No signal received!\n");
 			exit(1);