Fix fcntl(F_[GS]ETNOSIGPIPE) semantics

The new semantics should match those of NetBSD and other systems.

Change-Id: Ic9ca9d6b8c3e42d2a2953d9feea5f6bacaceb43c
This commit is contained in:
David van Moolenbroek 2014-11-01 12:57:31 +00:00
parent 10b1b4ee12
commit 1f945e8080
3 changed files with 16 additions and 12 deletions

View file

@ -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:

View file

@ -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:
{

View file

@ -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