NetBSD Problem Report #51859

From www@NetBSD.org  Fri Jan 13 07:00:47 2017
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 678467A1AF
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 13 Jan 2017 07:00:47 +0000 (UTC)
Message-Id: <20170113070046.89AF17A264@mollari.NetBSD.org>
Date: Fri, 13 Jan 2017 07:00:46 +0000 (UTC)
From: yaneurabeya@gmail.com
Reply-To: yaneurabeya@gmail.com
To: gnats-bugs@NetBSD.org
Subject: [PATCH] tests/lib/libc/sys/t_pipe2: use closefrom/restore RLIMIT_NOFILE when done
X-Send-Pr-Version: www-1.0

>Number:         51859
>Category:       bin
>Synopsis:       [PATCH] tests/lib/libc/sys/t_pipe2: use closefrom/restore RLIMIT_NOFILE when done
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jan 13 07:05:00 +0000 2017
>Closed-Date:    Sun Jan 15 19:58:27 +0000 2017
>Last-Modified:  Sun Jan 15 19:58:27 +0000 2017
>Originator:     Ngie Cooper
>Release:        7.0.2
>Organization:
>Environment:
n/a
>Description:
- Using closefrom instead of fcntl(3, F_CLOSEM) is for portability.
- Resetting RLIMIT_NOFILE at the end is to ensure that the limit doesn't interfere with the tester process.
>How-To-Repeat:

>Fix:

>Release-Note:

>Audit-Trail:
From: "Ngie Cooper (yaneurabeya)" <yaneurabeya@gmail.com>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/51859: [PATCH] tests/lib/libc/sys/t_pipe2: use
 closefrom/restore RLIMIT_NOFILE when done
Date: Thu, 12 Jan 2017 23:08:09 -0800

 --Apple-Mail=_1195F07C-0104-4F72-BF77-F7F441BE7FC0
 Content-Disposition: attachment;
 	filename=t_pipe2-use-closefrom-and-restore-RLIMIT_NOFILE.patch
 Content-Type: application/octet-stream;
 	x-unix-mode=0644;
 	name="t_pipe2-use-closefrom-and-restore-RLIMIT_NOFILE.patch"
 Content-Transfer-Encoding: 7bit

 Index: lib/libc/sys/t_pipe2.c
 ===================================================================
 RCS file: /cvsroot/src/tests/lib/libc/sys/t_pipe2.c,v
 retrieving revision 1.8
 diff -u -r1.8 t_pipe2.c
 --- lib/libc/sys/t_pipe2.c	16 May 2012 13:54:28 -0000	1.8
 +++ lib/libc/sys/t_pipe2.c	13 Jan 2017 06:55:50 -0000
 @@ -53,7 +53,8 @@
  	while ((i = open("/", O_RDONLY)) < 3)
  		ATF_REQUIRE(i != -1);

 -	ATF_REQUIRE(fcntl(3, F_CLOSEM) != -1);
 +	ATF_REQUIRE_MSG(closefrom(3) != -1, "closefrom failed: %s",
 +	    strerror(errno));

  	ATF_REQUIRE(pipe2(fd, flags) == 0);

 @@ -110,9 +111,10 @@
  {
  	struct rlimit rl;
  	int err, filedes[2];
 +	int old;

 -	err = fcntl(4, F_CLOSEM);
 -	ATF_REQUIRE(err == 0);
 +	ATF_REQUIRE_MSG(closefrom(4) != -1, "closefrom failed: %s",
 +	    strerror(errno));

  	err = getrlimit(RLIMIT_NOFILE, &rl);
  	ATF_REQUIRE(err == 0);
 @@ -121,12 +123,15 @@
  	 * file descriptor limit in the middle of a pipe2() call - i.e.
  	 * before the call only a single descriptor may be openend.
  	 */
 +	old = rl.rlim_cur;
  	rl.rlim_cur = 4;
  	err = setrlimit(RLIMIT_NOFILE, &rl);
  	ATF_REQUIRE(err == 0);

  	err = pipe2(filedes, O_CLOEXEC);
  	ATF_REQUIRE(err == -1);
 +	rl.rlim_cur = old;
 +	err = setrlimit(RLIMIT_NOFILE, &rl);
  }

  ATF_TC(pipe2_nonblock);

 --Apple-Mail=_1195F07C-0104-4F72-BF77-F7F441BE7FC0
 Content-Transfer-Encoding: 7bit
 Content-Type: text/plain;
 	charset=us-ascii




 --Apple-Mail=_1195F07C-0104-4F72-BF77-F7F441BE7FC0--

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51859 CVS commit: src/tests/lib/libc/sys
Date: Fri, 13 Jan 2017 16:19:45 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Fri Jan 13 21:19:45 UTC 2017

 Modified Files:
 	src/tests/lib/libc/sys: t_pipe2.c

 Log Message:
 PR/51859: Ngie Cooper: use closefrom/restore RLIMIT_NOFILE when done


 To generate a diff of this commit:
 cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libc/sys/t_pipe2.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: snj@NetBSD.org
State-Changed-When: Sun, 15 Jan 2017 19:58:27 +0000
State-Changed-Why:
christos committed it. thanks!


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.