This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC][BZ #14627] Make linux close errno to EINPROGRESS when interrupted in signal.


Hi,

As was recently said
https://www.sourceware.org/ml/libc-alpha/2013-12/msg00086.html

linux when close is interrupted by signal closes file descriptor but
returns EINTR errno which lies application about restartability. As
kernel does not restart close on SA_RESTART only thing needed is to
return EINPROGRESS instead EINTR as specified by POSIX.

I do not have actual implementation ready as close is automatically
generated syscall wrapper.

Second concern is cancelability, there is a close_nocancel macro and
also in libc.so close is implemented as header before close_nocancel but
i couldn't find definition.

Could somebody clarify?

As actual implementation one could use something like this. As in fclose
we use noncancelable version should we also disable cancelability in
close?

diff --git a/sysdeps/unix/sysv/linux/close.c b/sysdeps/unix/sysv/linux/close.c
new file mode 100644
index 0000000..223d6ed
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/close.c
@@ -0,0 +1,44 @@
+/* Copyright (C) 2013 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <sysdep-cancel.h>
+
+int
+__libc_close (int fd)
+{
+  if (SINGLE_THREAD_P)
+    return INLINE_SYSCALL (close, 1, fd);
+
+  int oldtype = LIBC_CANCEL_ASYNC ();
+
+  int result = INLINE_SYSCALL (close, 1, fd);
+
+  if (errno == EINTR)
+    errno = EINPROGRESS;
+
+  LIBC_CANCEL_RESET (oldtype);
+
+  return result;
+}
+
+weak_alias (__libc_close, __close)
+libc_hidden_weak (__close)
+weak_alias (__libc_close, close)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]