Module Name: src
Committed By: christos
Date: Wed May 18 02:57:49 UTC 2011
Modified Files:
src/tests/syscall: Makefile
Added Files:
src/tests/syscall: t_pselect.c
Log Message:
Add a test for signal delivery during pselect, with temporary mask change.
To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/tests/syscall/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/syscall/t_pselect.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/syscall/Makefile
diff -u src/tests/syscall/Makefile:1.26 src/tests/syscall/Makefile:1.27
--- src/tests/syscall/Makefile:1.26 Mon May 2 13:26:23 2011
+++ src/tests/syscall/Makefile Tue May 17 22:57:48 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.26 2011/05/02 17:26:23 jruoho Exp $
+# $NetBSD: Makefile,v 1.27 2011/05/18 02:57:48 christos Exp $
.include <bsd.own.mk>
@@ -7,7 +7,7 @@
TESTS_C+= t_access t_cmsg t_dup t_fsync
TESTS_C+= t_getgroups t_getpid t_getrusage t_getsid t_gettimeofday
TESTS_C+= t_itimer t_kill t_mmap t_mprotect t_msync t_nanosleep
-TESTS_C+= t_setrlimit t_setuid t_timer t_umask
+TESTS_C+= t_pselect t_setrlimit t_setuid t_timer t_umask
LDADD.t_getpid+= -lpthread
LDADD.t_timer+= -lpthread
Added files:
Index: src/tests/syscall/t_pselect.c
diff -u /dev/null src/tests/syscall/t_pselect.c:1.1
--- /dev/null Tue May 17 22:57:49 2011
+++ src/tests/syscall/t_pselect.c Tue May 17 22:57:48 2011
@@ -0,0 +1,125 @@
+/* $NetBSD: t_pselect.c,v 1.1 2011/05/18 02:57:48 christos Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundatiom
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/select.h>
+#include <sys/wait.h>
+#include <err.h>
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include <atf-c.h>
+
+static sig_atomic_t keep_going = 1;
+
+static void
+sig_handler(int signum)
+{
+ keep_going = 0;
+}
+
+static void __attribute__((__noreturn__))
+child(void)
+{
+ struct sigaction sa;
+ sigset_t set;
+ int fd;
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = sig_handler;
+ if ((fd = open("/dev/null", O_RDONLY)) == -1)
+ err(1, "open");
+
+ if (sigaction(SIGTERM, &sa, NULL) == -1)
+ err(1, "sigaction");
+
+ sigfillset(&set);
+ if (sigprocmask(SIG_BLOCK, &set, NULL) == -1)
+ err(1, "procmask");
+
+ sigemptyset(&set);
+
+ for (;;) {
+ fd_set rset;
+ FD_ZERO(&rset);
+ FD_SET(fd, &rset);
+ if (pselect(1, &rset, NULL, NULL, NULL, &set) == -1) {
+ if(errno == EINTR) {
+ if (!keep_going)
+ exit(0);
+ }
+ }
+ }
+}
+
+ATF_TC(pselect_signal_mask);
+ATF_TC_HEAD(pselect_signal_mask, tc)
+{
+
+ /* Cf. PR lib/43625. */
+ atf_tc_set_md_var(tc, "descr",
+ "Checks pselect's temporary mask setting");
+ atf_tc_set_md_var(tc, "timeout", "2");
+}
+
+ATF_TC_BODY(pselect_signal_mask, tc)
+{
+ pid_t pid;
+ int status;
+
+ switch (pid = fork()) {
+ case 0:
+ child();
+ case -1:
+ err(1, "fork");
+ default:
+ usleep(500);
+ if (kill(pid, SIGTERM) == -1)
+ err(1, "kill");
+ if (waitpid(pid, &status, 0) == -1)
+ err(1, "wait");
+ break;
+ }
+}
+
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, pselect_signal_mask);
+
+ return atf_no_error();
+}