NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/51859: [PATCH] tests/lib/libc/sys/t_pipe2: use closefrom/restore RLIMIT_NOFILE when done
The following reply was made to PR bin/51859; it has been noted by GNATS.
From: "Ngie Cooper (yaneurabeya)" <yaneurabeya%gmail.com@localhost>
To: gnats-bugs%NetBSD.org@localhost
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--
Home |
Main Index |
Thread Index |
Old Index