From 1f945e8080b22572da1cabae9b0f0cfb4718b620 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Sat, 1 Nov 2014 12:57:31 +0000 Subject: [PATCH] Fix fcntl(F_[GS]ETNOSIGPIPE) semantics The new semantics should match those of NetBSD and other systems. Change-Id: Ic9ca9d6b8c3e42d2a2953d9feea5f6bacaceb43c --- minix/lib/libc/sys/fcntl.c | 1 + minix/servers/vfs/misc.c | 11 +++++------ minix/tests/test68.c | 16 ++++++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/minix/lib/libc/sys/fcntl.c b/minix/lib/libc/sys/fcntl.c index 10b99058f..e6f4e6786 100644 --- a/minix/lib/libc/sys/fcntl.c +++ b/minix/lib/libc/sys/fcntl.c @@ -23,6 +23,7 @@ int fcntl(int fd, int cmd, ...) case F_DUPFD: case F_SETFD: case F_SETFL: + case F_SETNOSIGPIPE: m.m_lc_vfs_fcntl.arg_int = va_arg(argp, int); break; case F_GETLK: diff --git a/minix/servers/vfs/misc.c b/minix/servers/vfs/misc.c index 8652007ca..429244c0b 100644 --- a/minix/servers/vfs/misc.c +++ b/minix/servers/vfs/misc.c @@ -214,14 +214,13 @@ int do_fcntl(void) break; } case F_GETNOSIGPIPE: - /* POSIX: return value other than -1 is flag is set, else -1 */ - r = -1; - if (f->filp_flags & O_NOSIGPIPE) - r = 0; + r = !!(f->filp_flags & O_NOSIGPIPE); break; case F_SETNOSIGPIPE: - fl = (O_NOSIGPIPE); - f->filp_flags = (f->filp_flags & ~fl) | (fcntl_argx & fl); + if (fcntl_argx) + f->filp_flags |= O_NOSIGPIPE; + else + f->filp_flags &= ~O_NOSIGPIPE; break; case F_FLUSH_FS_CACHE: { diff --git a/minix/tests/test68.c b/minix/tests/test68.c index 273117bce..99581677d 100644 --- a/minix/tests/test68.c +++ b/minix/tests/test68.c @@ -267,8 +267,8 @@ test_pipe_flag_setting() if (fcntl(pipes[1], F_GETFD) != 0) e(3); if (fcntl(pipes[0], F_GETFL) & O_NONBLOCK) e(4); if (fcntl(pipes[1], F_GETFL) & O_NONBLOCK) e(5); - if (fcntl(pipes[0], F_GETNOSIGPIPE) != -1) e(6); - if (fcntl(pipes[1], F_GETNOSIGPIPE) != -1) e(7); + if (fcntl(pipes[0], F_GETNOSIGPIPE) != 0) e(6); + if (fcntl(pipes[1], F_GETNOSIGPIPE) != 0) e(7); if (close(pipes[0]) != 0) e(8); if (close(pipes[1]) != 0) e(9); @@ -278,10 +278,14 @@ test_pipe_flag_setting() if (fcntl(pipes[1], F_GETFD) != FD_CLOEXEC) e(12); if (!(fcntl(pipes[0], F_GETFL) & O_NONBLOCK)) e(13); if (!(fcntl(pipes[1], F_GETFL) & O_NONBLOCK)) e(14); - if (fcntl(pipes[0], F_GETNOSIGPIPE) == -1) e(15); - if (fcntl(pipes[1], F_GETNOSIGPIPE) == -1) e(16); - if (close(pipes[0]) != 0) e(17); - if (close(pipes[1]) != 0) e(18); + if (fcntl(pipes[0], F_GETNOSIGPIPE) == 0) e(15); + if (fcntl(pipes[1], F_GETNOSIGPIPE) == 0) e(16); + if (fcntl(pipes[0], F_SETNOSIGPIPE, 0) != 0) e(17); + if (fcntl(pipes[0], F_GETNOSIGPIPE) != 0) e(18); + if (fcntl(pipes[0], F_SETNOSIGPIPE, 1) != 0) e(19); + if (fcntl(pipes[0], F_GETNOSIGPIPE) == 0) e(20); + if (close(pipes[0]) != 0) e(21); + if (close(pipes[1]) != 0) e(22); } int