From 6a7e3e5f92baae060dd577cafa3e3b35ae638d64 Mon Sep 17 00:00:00 2001 From: emaste Date: Wed, 4 Jul 2018 18:03:19 +0000 Subject: [PATCH] MFC r306098 (br): Use kqueue(2) instead of select(2). This helps to ensure we will not lose SIGINT sent by parent to child. PR: 212562, 228492 git-svn-id: svn://svn.freebsd.org/base/stable/10@335965 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- lib/libutil/tests/pidfile_test.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/libutil/tests/pidfile_test.c b/lib/libutil/tests/pidfile_test.c index 0b70bc801..42a7be4db 100644 --- a/lib/libutil/tests/pidfile_test.c +++ b/lib/libutil/tests/pidfile_test.c @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -43,8 +44,8 @@ __FBSDID("$FreeBSD$"); #include /* - * We need a signal handler so kill(2) will interrupt our child's - * select(2) instead of killing it. + * We need a signal handler so kill(2) will interrupt the child + * instead of killing it. */ static void signal_handler(int sig) @@ -129,7 +130,9 @@ common_test_pidfile_child(const char *fn, int parent_open) struct pidfh *pf = NULL; pid_t other = 0, pid = 0; int fd[2], serrno, status; + struct kevent event, ke; char ch; + int kq; unlink(fn); if (pipe(fd) != 0) @@ -166,10 +169,20 @@ common_test_pidfile_child(const char *fn, int parent_open) if (pf == NULL) _exit(1); if (pidfile_write(pf) != 0) - _exit(1); + _exit(2); + kq = kqueue(); + if (kq == -1) + _exit(3); + EV_SET(&ke, SIGINT, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL); + /* Attach event to the kqueue. */ + if (kevent(kq, &ke, 1, NULL, 0, NULL) != 0) + _exit(4); + /* Inform the parent we are ready to receive SIGINT */ if (write(fd[1], "*", 1) != 1) - _exit(1); - select(0, 0, 0, 0, 0); + _exit(5); + /* Wait for SIGINT received */ + if (kevent(kq, NULL, 0, &event, 1, NULL) != 1) + _exit(6); _exit(0); } // parent -- 2.42.0