libc: support F_SETFD && FD_CLOEXEC ioctl

Issue #1308
This commit is contained in:
Alexander Boettcher 2014-11-28 16:37:13 +01:00 committed by Christian Helmuth
parent f9422b241f
commit f970e4a71b
3 changed files with 36 additions and 9 deletions

View File

@ -818,7 +818,7 @@ int Libc::Vfs_plugin::fcntl(Libc::File_descriptor *fd, int cmd, long arg)
break;
}
PERR("fcntl(): command %d not supported", cmd);
PERR("fcntl(): command %d not supported - vfs", cmd);
errno = EINVAL;
return -1;
}

View File

@ -232,12 +232,25 @@ namespace {
int Plugin::fcntl(Libc::File_descriptor *pipefdo, int cmd, long arg)
{
switch (cmd) {
case F_GETFL:
if (is_write_end(pipefdo))
return O_WRONLY;
else
return O_RDONLY;
default: PERR("fcntl(): command %d not supported", cmd); return -1;
case F_GETFL:
if (is_write_end(pipefdo))
return O_WRONLY;
else
return O_RDONLY;
case F_SETFD:
{
const long supported_flags = FD_CLOEXEC;
/* if unsupported flags are used, fall through with error */
if (!(arg & ~supported_flags)) {
/* close fd if exec is called - no exec support -> ignore */
if (arg & FD_CLOEXEC)
return 0;
}
}
default:
PERR("fcntl(): command %d arg %ld not supported - pipe",
cmd, arg);
return -1;
}
}
@ -287,6 +300,7 @@ namespace {
FD_ZERO(readfds);
in_writefds = *writefds;
FD_ZERO(writefds);
FD_ZERO(exceptfds);
for (int libc_fd = 0; libc_fd < nfds; libc_fd++) {
fdo = Libc::file_descriptor_allocator()->find_by_libc_fd(libc_fd);

View File

@ -297,8 +297,21 @@ namespace {
int fcntl(Libc::File_descriptor *fd, int cmd, long arg)
{
switch (cmd) {
case F_GETFL: return context(fd)->status_flags();
default: PERR("fcntl(): command %d not supported", cmd); return -1;
case F_GETFL: return context(fd)->status_flags();
case F_SETFD:
{
const long supported_flags = FD_CLOEXEC;
/* if unsupported flags are used, fall through with error */
if (!(arg & ~supported_flags)) {
/* close fd if exec is called - no exec support -> ignore */
if (arg & FD_CLOEXEC)
return 0;
}
}
default:
PERR("fcntl(): command %d args %ld not supported - terminal",
cmd, arg);
return -1;
}
}