[projects/pld-builder.new] gpg: fail when signing fails
arekm
arekm at pld-linux.org
Mon Oct 26 17:15:35 CET 2026
commit 98856dbd2b5ef9a52bf271099b7827304338e0bd
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Sat Oct 24 11:04:52 2026 +0200
gpg: fail when signing fails
sign() ignored gpg's exit code, publishing an unsigned queue.gz and
empty notifications. srpm_builder now queues the src.rpm and bumps
max_req_no before signing; an unsignable notification is mailed to the
admin and dropped.
PLD_Builder/gpg.py | 4 +++-
PLD_Builder/notify.py | 15 ++++++++++++++-
PLD_Builder/srpm_builder.py | 12 +++++++++---
3 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/PLD_Builder/gpg.py b/PLD_Builder/gpg.py
index 667a15a..5cff0be 100644
--- a/PLD_Builder/gpg.py
+++ b/PLD_Builder/gpg.py
@@ -74,7 +74,6 @@ def sign(buf):
d_stdout = None
d_stderr = None
cmd = ['/usr/bin/gpg', '--batch', '--no-tty', '--clearsign']
- # TODO: check for gpg return code!
gpg_run = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
try:
d_stdout, d_stderr = gpg_run.communicate(util.to_bytes(buf))
@@ -93,5 +92,8 @@ def sign(buf):
except OSError as e:
log.error("gpgconf --kill all failed: %s" % e)
+ # callers publish what we return; never hand back an unsigned or empty body
+ if gpg_run.returncode != 0:
+ log.panic("gpg --clearsign failed with exit code %d" % gpg_run.returncode)
return d_stdout
diff --git a/PLD_Builder/notify.py b/PLD_Builder/notify.py
index ed8c4b3..bf08665 100644
--- a/PLD_Builder/notify.py
+++ b/PLD_Builder/notify.py
@@ -2,6 +2,8 @@
from io import StringIO
import gpg
+import log
+import mailer
import util
import notifyq
from config import config
@@ -16,7 +18,18 @@ class Notifier:
sio = StringIO()
self.xml.write("</notification>\n")
self.xml.seek(0)
- sio.write(util.to_str(gpg.sign(self.xml.read())))
+ try:
+ sio.write(util.to_str(gpg.sign(self.xml.read())))
+ except (log.Panic, OSError) as e:
+ # raising here would leave a finished build queued on a bin
+ # builder and rebuild it on every run until gpg works again
+ msg = f"notification for {r.id} not sent: signing failed: {e}"
+ log.alert(msg)
+ m = mailer.Message()
+ m.set_headers(to = config.admin_email, subject = f"[{config.builder}] notification not sent")
+ m.write_line(msg)
+ m.send()
+ return
self.xml = None
sio.seek(0)
notifyq.init(r)
diff --git a/PLD_Builder/srpm_builder.py b/PLD_Builder/srpm_builder.py
index b485c53..5c3e88b 100644
--- a/PLD_Builder/srpm_builder.py
+++ b/PLD_Builder/srpm_builder.py
@@ -51,9 +51,10 @@ def store_binary_request(r):
q.write()
q.dump(path.queue_stats_file)
q.dump_html(path.queue_html_stats_file)
- q.write_signed(path.req_queue_signed_file)
- q.unlock()
+ # bump the counter before signing: if gpg fails, the request waits in
+ # req_queue for the next signed queue.gz instead of the next request
+ # reusing its number
(fdno, tmpfname) = tempfile.mkstemp(dir=os.path.dirname(path.max_req_no_file))
cnt_f = os.fdopen(fdno, "w")
cnt_f.seek(0)
@@ -64,6 +65,9 @@ def store_binary_request(r):
os.chmod(tmpfname, 0o0644)
os.rename(tmpfname, path.max_req_no_file)
+ q.write_signed(path.req_queue_signed_file)
+ q.unlock()
+
def transfer_file(r, b):
local = path.srpms_dir + '/' + r.id + "/" + b.src_rpm
f = b.src_rpm_file
@@ -141,8 +145,10 @@ def handle_request(r):
build.build_all(r, build_srpm)
report.send_report(r, is_src = True)
report.send_cia_report(r, is_src = True)
- store_binary_request(r)
+ # before store_binary_request(), which raises when signing fails:
+ # the src.rpm must reach ftp either way
ftp.flush()
+ store_binary_request(r)
notify.send(r)
def main():
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/ce9feb3c796ed049b6dd260a50d94d80feb1656d
More information about the pld-cvs-commit
mailing list