@@ -24,6 +24,9 @@
# signing.
# GPG_PATH
# Optional variable for specifying the gnupg "home" directory:
+# GPG_SIGN_SERIALIZE
+# Optional variable; "1" (default) serializes signing operations
+# that share a TMPDIR, "0" allows parallel signing.
#
IPK_SIGN_PACKAGES = '1'
@@ -27,6 +27,9 @@
# signing.
# GPG_PATH
# Optional variable for specifying the gnupg "home" directory:
+# GPG_SIGN_SERIALIZE
+# Optional variable; "1" (default) serializes signing operations
+# that share a TMPDIR, "0" allows parallel signing.
#
PACKAGE_FEED_SIGN = '1'
@@ -30,6 +30,9 @@
# invocation
# GPG_PATH
# Optional variable for specifying the gnupg "home" directory:
+# GPG_SIGN_SERIALIZE
+# Optional variable; "1" (default) serializes signing operations
+# that share a TMPDIR, "0" allows parallel signing.
RPM_SIGN_PACKAGES = '1'
RPM_SIGN_FILES ?= '0'
@@ -18,13 +18,13 @@ class LocalSigner(object):
self.gpg_bin = d.getVar('GPG_BIN') or \
bb.utils.which(os.getenv('PATH'), 'gpg')
self.gpg_cmd = [self.gpg_bin]
- self.gpg_agent_bin = bb.utils.which(os.getenv('PATH'), "gpg-agent")
- # Without this we see "Cannot allocate memory" errors when running processes in parallel
- # It needs to be set for any gpg command since any agent launched can stick around in memory
- # and this parameter must be set.
- if self.gpg_agent_bin:
- self.gpg_cmd += ["--agent-program=%s|--auto-expand-secmem" % (self.gpg_agent_bin)]
self.gpg_path = d.getVar('GPG_PATH')
+ # Concurrent signing can exhaust gpg-agent's secure memory unless it
+ # runs with auto-expand-secmem, so by default serialize signing
+ # operations that share a TMPDIR. (AI-generated: Kiro)
+ self.sign_lock = None
+ if bb.utils.to_boolean(d.getVar('GPG_SIGN_SERIALIZE'), True):
+ self.sign_lock = os.path.join(d.getVar('TMPDIR'), 'gpg-sign.lock')
self.rpm_bin = bb.utils.which(os.getenv('PATH'), "rpmsign")
self.gpg_version = self.get_gpg_version()
@@ -43,7 +43,7 @@ class LocalSigner(object):
"""Sign RPM files"""
cmd = self.rpm_bin + " --addsign --define '_gpg_name %s' " % keyid
- gpg_args = '--no-permission-warning --batch --passphrase=%s --agent-program=%s|--auto-expand-secmem' % (passphrase, self.gpg_agent_bin)
+ gpg_args = '--no-permission-warning --batch --passphrase=%s' % passphrase
if self.gpg_version > (2,1,):
gpg_args += ' --pinentry-mode=loopback'
cmd += "--define '_gpg_sign_cmd_extra_args %s' " % gpg_args
@@ -59,7 +59,8 @@ class LocalSigner(object):
# Sign in chunks
for i in range(0, len(files), sign_chunk):
- subprocess.check_output(shlex.split(cmd + ' '.join(files[i:i+sign_chunk])), stderr=subprocess.STDOUT)
+ with bb.utils.fileslocked([self.sign_lock]):
+ subprocess.check_output(shlex.split(cmd + ' '.join(files[i:i+sign_chunk])), stderr=subprocess.STDOUT)
def detach_sign(self, input_file, keyid, passphrase_file, passphrase=None, armor=True, output_suffix=None, use_sha256=False):
"""Create a detached signature of a file"""
@@ -96,8 +97,9 @@ class LocalSigner(object):
cmd += [input_file]
- job = subprocess.Popen(cmd, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
- (_, stderr) = job.communicate(passphrase.encode("utf-8"))
+ with bb.utils.fileslocked([self.sign_lock]):
+ job = subprocess.Popen(cmd, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
+ (_, stderr) = job.communicate(passphrase.encode("utf-8"))
if job.returncode:
bb.fatal("GPG exited with code %d: %s" % (job.returncode, stderr.decode("utf-8")))
The "--agent-program=gpg-agent|--auto-expand-secmem" syntax is what the gpg manual calls a regression test suite hack, and it has no effect on an agent that is already running, in which case parallel signing fails with "Cannot allocate memory". Instead, take a lock in TMPDIR around signing, which serializes OE signing operations that share a TMPDIR, including sstate signing. Set GPG_SIGN_SERIALIZE = "0" to opt out when the agent runs with auto-expand-secmem. In a signed core-image-minimal build with an already running agent, 138 of 141 do_package_write_rpm tasks failed without the lock and none with it, with no clear slowdown observed. The cost for sstate signing was not measured. Tested with oe-selftest -r signing, not with TMPDIR on a network file system. [YOCTO #16480] AI-Generated: Uses Kiro (claude-opus-5.5) Signed-off-by: Adarsh Jagadish Kamini <adarsh.jagadish.kamini@est.tech> --- meta/classes/sign_ipk.bbclass | 3 +++ meta/classes/sign_package_feed.bbclass | 3 +++ meta/classes/sign_rpm.bbclass | 3 +++ meta/lib/oe/gpg_sign.py | 22 ++++++++++++---------- 4 files changed, 21 insertions(+), 10 deletions(-)