Skip to contentSkip to conversation

utils: Handle lockfile filenames that are too long for filesystems

PATCH In review Richard Purdie 2 participants 2 messages Nov 18, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils: Handle lockfile filenames that are too long for filesystems

The fetcher mirror code can go crazy creating lock filenames which exceed the filesystem limits. When this happens, the code will loop/hang.

Handle the filename too long exception correctly but also truncate lockfile lengths to under 256 since the worst case situation is lockfile overlap and lack of parallelism.

---
 lib/bb/utils.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/bb/utils.py +6 -1
index 70634910f7..23ff64df7a 100644
@@ -451,6 +451,11 @@ def lockfile(name, shared=False, retry=True, block=False):
     consider the possibility of sending a signal to the process to break
     out - at which point you want block=True rather than retry=True.
     """
+    if len(name) > 255:
+        components = name.rsplit(".", 1)
+        components[0] = components[0][:255 - len(components[1]) - 1]
+        name = ".".join(components)
+
     dirname = os.path.dirname(name)
     mkdirhier(dirname)
 
@@ -487,7 +492,7 @@ def lockfile(name, shared=False, retry=True, block=False):
                     return lf
             lf.close()
         except OSError as e:
-            if e.errno == errno.EACCES:
+            if e.errno == errno.EACCES or e.errno == errno.ENAMETOOLONG:
                 logger.error("Unable to acquire lock '%s', %s",
                              e.strerror, name)
                 sys.exit(1)
Signature · 1 line
2.32.0
#1 lore raw
Quoted 23 lines · Richard Purdie

The fetcher mirror code can go crazy creating lock filenames which exceed the
filesystem limits. When this happens, the code will loop/hang.

Handle the filename too long exception correctly but also truncate lockfile lengths to under 256 since the worst case situation is lockfile overlap and lack of parallelism.

---
 lib/bb/utils.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/bb/utils.py +0 -0
index 70634910f7..23ff64df7a 100644
@@ -451,6 +451,11 @@ def lockfile(name, shared=False, retry=True,

block=False):
consider the possibility of sending a signal to the process to break out - at which point you want block=True rather than retry=True. """

lib/bb/utils.py def lockfile(name, shared=False, retry=True, block=False): · line 457

Quoted 4 lines
lib/bb/utils.py +4 -0
+    if len(name) > 255:
+        components = name.rsplit(".", 1)
+        components[0] = components[0][:255 - len(components[1]) - 1]
+        name = ".".join(components)

I think this may be easier to read with separate variables and os.path.splitext:

root, ext = os.path.splitext(name)
name = root[:255 - len(ext) - 1] + ext

Signature · 4 lines
Christopher Larson
kergoth at gmail dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Senior Software Engineer, Mentor Graphics