about summary refs log tree commit diff
path: root/sysdeps/mach/hurd/fcntl.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2020-06-28 18:18:43 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2020-06-28 18:24:37 +0000
commit3c9f67e7a58487c084f3b657c1dfe490d1a318d5 (patch)
tree76a9c4d6d568112188144c85b10969727e5b2224 /sysdeps/mach/hurd/fcntl.c
parent09effdc9b04a3a04d4f128fd9e1fa360a251ed81 (diff)
downloadglibc-3c9f67e7a58487c084f3b657c1dfe490d1a318d5.tar.gz
glibc-3c9f67e7a58487c084f3b657c1dfe490d1a318d5.tar.xz
glibc-3c9f67e7a58487c084f3b657c1dfe490d1a318d5.zip
hurd: Make fcntl(F_SETLKW*) cancellation points
and add _nocancel variant.

* sysdeps/mach/hurd/Makefile [io] (sysdep_routines): Add fcntl_nocancel.
* sysdeps/mach/hurd/fcntl.c [NOCANCEL]: Include <not-cancel.h>.
[!NOCANCEL]: Include <sysdep-cancel.h>.
(__libc_fcntl) [!NOCANCEL]: Surround __file_record_lock call with enabling async cancel, and use HURD_FD_PORT_USE_CANCEL instead of HURD_FD_PORT_USE.
* sysdeps/mach/hurd/fcntl_nocancel.c: New file, defines __fcntl_nocancel by including fcntl.c.
* sysdeps/mach/hurd/not-cancel.h (__fcntl64_nocancel): Replace macro with
    __fcntl_nocancel declaration with hidden proto, and make
    __fcntl64_nocancel call __fcntl_nocancel.
Diffstat (limited to 'sysdeps/mach/hurd/fcntl.c')
-rw-r--r--sysdeps/mach/hurd/fcntl.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/sysdeps/mach/hurd/fcntl.c b/sysdeps/mach/hurd/fcntl.c
index 95b0ebff0f..564d9dcd23 100644
--- a/sysdeps/mach/hurd/fcntl.c
+++ b/sysdeps/mach/hurd/fcntl.c
@@ -21,6 +21,11 @@
 #include <hurd/fd.h>
 #include <stdarg.h>
 #include <sys/file.h>		/* XXX for LOCK_* */
+#ifdef NOCANCEL
+#include <not-cancel.h>
+#else
+#include <sysdep-cancel.h>
+#endif
 #include "f_setlk.h"
 
 /* Perform file control operations on FD.  */
@@ -155,8 +160,19 @@ __libc_fcntl (int fd, int cmd, ...)
 	  .l_pid = fl->l_pid
 	};
 
-	err = HURD_FD_PORT_USE (d, __file_record_lock (port, cmd, &fl64,
-				MACH_PORT_NULL, MACH_MSG_TYPE_MAKE_SEND));
+#ifndef NOCANCEL
+	if (cmd == F_SETLKW64)
+	  {
+	    int cancel_oldtype = LIBC_CANCEL_ASYNC();
+	    err = HURD_FD_PORT_USE_CANCEL (d, __file_record_lock (port, cmd,
+					   &fl64, MACH_PORT_NULL,
+					   MACH_MSG_TYPE_MAKE_SEND));
+	    LIBC_CANCEL_RESET (cancel_oldtype);
+	  }
+	else
+#endif
+	  err = HURD_FD_PORT_USE (d, __file_record_lock (port, cmd, &fl64,
+				  MACH_PORT_NULL, MACH_MSG_TYPE_MAKE_SEND));
 
 	/* XXX: To remove once file_record_lock RPC is settled.  */
 	if (err == EMIG_BAD_ID || err == EOPNOTSUPP)
@@ -207,8 +223,19 @@ __libc_fcntl (int fd, int cmd, ...)
       {
 	struct flock64 *fl = va_arg (ap, struct flock64 *);
 
-	err = HURD_FD_PORT_USE (d, __file_record_lock (port, cmd, fl,
-				MACH_PORT_NULL, MACH_MSG_TYPE_MAKE_SEND));
+#ifndef NOCANCEL
+	if (cmd == F_SETLKW64)
+	  {
+	    int cancel_oldtype = LIBC_CANCEL_ASYNC();
+	    err = HURD_FD_PORT_USE_CANCEL (d, __file_record_lock (port, cmd,
+					   fl, MACH_PORT_NULL,
+					   MACH_MSG_TYPE_MAKE_SEND));
+	    LIBC_CANCEL_RESET (cancel_oldtype);
+	  }
+	else
+#endif
+	  err = HURD_FD_PORT_USE (d, __file_record_lock (port, cmd, fl,
+				  MACH_PORT_NULL, MACH_MSG_TYPE_MAKE_SEND));
 
 	/* XXX: To remove once file_record_lock RPC is settled.  */
 	if (err == EMIG_BAD_ID || err == EOPNOTSUPP)
@@ -263,6 +290,8 @@ __libc_fcntl (int fd, int cmd, ...)
   return result;
 }
 libc_hidden_def (__libc_fcntl)
+
+#ifndef NOCANCEL
 weak_alias (__libc_fcntl, __fcntl)
 libc_hidden_weak (__fcntl)
 weak_alias (__libc_fcntl, fcntl)
@@ -272,3 +301,4 @@ libc_hidden_def (__libc_fcntl64)
 weak_alias (__libc_fcntl64, __fcntl64)
 libc_hidden_weak (__fcntl64)
 weak_alias (__fcntl64, fcntl64)
+#endif