From: Samuel Thibault Date: Tue, 23 Apr 2024 16:23:00 +0000 (+0300) Subject: [PATCH] Make F_RDLCK/F_WRLCK atomic X-Git-Tag: archive/raspbian/2.28-10+rpi1+deb10u3^2~75 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c87967c0148458199e00cb266f3cea0ff452950f;p=glibc.git [PATCH] Make F_RDLCK/F_WRLCK atomic 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 * misc/sys/file.h (__LOCK_ATOMIC): New macro. * sysdeps/mach/hurd/fcntl.c (__libc_fcntl): Use __LOCK_ATOMIC along LOCK_SH and LOCK_EX. XXX: Adding to misc/sys/file.h is questionable Gbp-Pq: Topic hurd-i386 Gbp-Pq: Name tg-WRLCK-upgrade.diff --- diff --git a/misc/sys/file.h b/misc/sys/file.h index 86abfa18d..e6494fa33 100644 --- a/misc/sys/file.h +++ b/misc/sys/file.h @@ -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. */ diff --git a/sysdeps/mach/hurd/f_setlk.c b/sysdeps/mach/hurd/f_setlk.c index edfb292db..27f7d2729 100644 --- a/sysdeps/mach/hurd/f_setlk.c +++ b/sysdeps/mach/hurd/f_setlk.c @@ -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;