Make F_RDLCK/F_WRLCK atomic
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Wed, 5 Dec 2018 18:50:21 +0000 (18:50 +0000)
committerAurelien Jarno <aurel32@debian.org>
Wed, 5 Dec 2018 18:50:21 +0000 (18:50 +0000)
lockf(LOCK_EX) would for instance drop any existing shared lock before taking
the exclusive lock. F_RDLCK/F_WRLCK need atomic changes, so introduce and use
__LOCK_ATOM

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
* misc/sys/file.h (__LOCK_ATOMIC): New macro.
* sysdeps/mach/hurd/fcntl.c (__libc_fcntl): Use __LOCK_ATOMIC along LOCK_SH and
LOCK_EX.

Gbp-Pq: Topic hurd-i386
Gbp-Pq: Name tg-WRLCK-upgrade.diff

misc/sys/file.h
sysdeps/mach/hurd/f_setlk.c

index 86abfa18dec6965a7f0c809991fc11316ba120d5..e6494fa3337a7a7b32cdb52e462003ee470cceb7 100644 (file)
@@ -40,6 +40,7 @@ __BEGIN_DECLS
 #define        LOCK_SH 1       /* Shared lock.  */
 #define        LOCK_EX 2       /* Exclusive lock.  */
 #define        LOCK_UN 8       /* Unlock.  */
+#define        __LOCK_ATOMIC   16      /* Atomic update.  */
 
 /* Can be OR'd in to one of the above.  */
 #define        LOCK_NB 4       /* Don't block when locking.  */
index edfb292dbf1c1a9fd188bb7553e4cb90cb73e075..27f7d27297dfc48a38d693251fc5f595db637a4e 100644 (file)
@@ -35,8 +35,8 @@ __f_setlk (int fd, int type, int whence, __off64_t start, __off64_t len, int wai
 
   switch (type)
     {
-    case F_RDLCK: cmd = LOCK_SH; break;
-    case F_WRLCK: cmd = LOCK_EX; break;
+    case F_RDLCK: cmd = LOCK_SH | __LOCK_ATOMIC; break;
+    case F_WRLCK: cmd = LOCK_EX | __LOCK_ATOMIC; break;
     case F_UNLCK: cmd = LOCK_UN; break;
     default:
       errno = EINVAL;