From owner-svn-src-head@freebsd.org Wed Sep 21 11:59:54 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 46617BE3E40; Wed, 21 Sep 2016 11:59:54 +0000 (UTC) (envelope-from br@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id F010D278; Wed, 21 Sep 2016 11:59:53 +0000 (UTC) (envelope-from br@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u8LBxrGc031918; Wed, 21 Sep 2016 11:59:53 GMT (envelope-from br@FreeBSD.org) Received: (from br@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u8LBxrTT031917; Wed, 21 Sep 2016 11:59:53 GMT (envelope-from br@FreeBSD.org) Message-Id: <201609211159.u8LBxrTT031917@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: br set sender to br@FreeBSD.org using -f From: Ruslan Bukin Date: Wed, 21 Sep 2016 11:59:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r306098 - head/lib/libutil/tests X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Sep 2016 11:59:54 -0000 Author: br Date: Wed Sep 21 11:59:52 2016 New Revision: 306098 URL: https://svnweb.freebsd.org/changeset/base/306098 Log: Use kqueue(2) instead of select(2). This helps to ensure we will not lose SIGINT sent by parent to child. Reviewed by: sbruno, ngie Sponsored by: DARPA, AFRL Sponsored by: HEIF5 Differential Revision: https://reviews.freebsd.org/D7892 Modified: head/lib/libutil/tests/pidfile_test.c Modified: head/lib/libutil/tests/pidfile_test.c ============================================================================== --- head/lib/libutil/tests/pidfile_test.c Wed Sep 21 11:31:58 2016 (r306097) +++ head/lib/libutil/tests/pidfile_test.c Wed Sep 21 11:59:52 2016 (r306098) @@ -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 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 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