1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
From: Apollon Oikonomopoulos <apoikos@debian.org>
Date: Wed, 28 Feb 2018 11:22:43 +0200
Subject: utils.livelock: use portable struct flock type
From fcntl(2):
struct flock {
...
short l_type; /* Type of lock: F_RDLCK,
F_WRLCK, F_UNLCK */
short l_whence; /* How to interpret l_start:
SEEK_SET, SEEK_CUR, SEEK_END */
off_t l_start; /* Starting offset for lock */
off_t l_len; /* Number of bytes to lock */
pid_t l_pid; /* PID of process blocking our lock
(set by F_GETLK and F_OFD_GETLK) */
...
};
On 64-bit systems, off_t is always 64 bits long ("long"/"long long"). On
32-bit systems however, depending on whether large file support is
enabled or not, it may be 64 bits ("long long") or 32 bits ("long")
long.
The code in LiveLock.__init__ would always assume off_t to be "long",
breaking on 32-bit systems with LFS support. Fix this by picking the
correct type to use depending on the existence of os.O_LARGEFILE.
Note that LFS is enabled almost universally these days and it would be
safe to just use "long long" unconditionally, but it doesn't harm to
make the actual check.
Signed-off-by: Apollon Oikonomopoulos <apoikos@debian.org>
---
lib/utils/livelock.py | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/lib/utils/livelock.py b/lib/utils/livelock.py
index d20fd0f..4c9db8d 100644
--- a/lib/utils/livelock.py
+++ b/lib/utils/livelock.py
@@ -72,8 +72,16 @@ class LiveLock(object):
name = "%s_%d" % (name, int(time.time()))
fname = os.path.join(pathutils.LIVELOCK_DIR, name)
self.lockfile = open(fname, 'w')
+
+ # with LFS enabled, off_t is 64 bits even on 32-bit platforms
+ try:
+ os.O_LARGEFILE
+ struct_flock = 'hhqqhh'
+ except AttributeError:
+ struct_flock = 'hhllhh'
+
fcntl.fcntl(self.lockfile, fcntl.F_SETLKW,
- struct.pack('hhllhh', fcntl.F_WRLCK, 0, 0, 0, 0, 0))
+ struct.pack(struct_flock, fcntl.F_WRLCK, 0, 0, 0, 0, 0))
def GetPath(self):
return self.lockfile.name
|