From c2c47d2e35405c455ef0e0be378552a29ac36d86 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Wed, 26 Jul 2017 11:52:46 -0500 Subject: [PATCH] libc: silence close() failure messages Return EBADF but do not log an error for invalid descriptors. Ref #2467 --- repos/libports/src/lib/libc/file_operations.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/repos/libports/src/lib/libc/file_operations.cc b/repos/libports/src/lib/libc/file_operations.cc index 745a943e2f..30f67dc41b 100644 --- a/repos/libports/src/lib/libc/file_operations.cc +++ b/repos/libports/src/lib/libc/file_operations.cc @@ -36,6 +36,7 @@ #include "libc_file.h" #include "libc_mem_alloc.h" #include "libc_mmap_registry.h" +#include "libc_errno.h" using namespace Libc; @@ -218,9 +219,16 @@ extern "C" int chdir(const char *path) } +/** + * Close is called incorrectly enough to justify a silent failure + */ extern "C" int _close(int libc_fd) { - FD_FUNC_WRAPPER(close, libc_fd); + Libc::File_descriptor *fd = + Libc::file_descriptor_allocator()->find_by_libc_fd(libc_fd); + return (!fd || !fd->plugin) + ? Libc::Errno(EBADF) + : fd->plugin->close(fd); }