Make F_RDLCK/F_WRLCK atomic
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Mon, 16 Jan 2017 17:43:37 +0000 (17:43 +0000)
committerAurelien Jarno <aurel32@debian.org>
Mon, 16 Jan 2017 17:43:37 +0000 (17:43 +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/fcntl.c

index 133e969dfca3fe4295ddb3ba263a8eefd057de4c..cd2a6410fcc59b7e9ad1359e0fc141a57a82be1e 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 2898ebbb1483b2394cc28c48d281e86706799b0e..73737fdbf369a8cd42d2213226062b081c950ced 100644 (file)
@@ -150,8 +150,8 @@ __libc_fcntl (int fd, int cmd, ...)
          }
        switch (fl->l_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;