Improve output after waiting for package db lock
authorafresh1 <afresh1@openbsd.org>
Wed, 15 Nov 2023 02:03:49 +0000 (02:03 +0000)
committerafresh1 <afresh1@openbsd.org>
Wed, 15 Nov 2023 02:03:49 +0000 (02:03 +0000)
OpenBSD::PackageInfo::lock_db will send messages to STDERR if we ended up
waiting for a lock, if that happens, it stomped over the "fw_update:" prefix on
the status line so tidy up and print it out again.

usr.sbin/fw_update/fw_update.sh

index 38a6538..408f8ac 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/ksh
-#      $OpenBSD: fw_update.sh,v 1.53 2023/11/15 02:00:02 afresh1 Exp $
+#      $OpenBSD: fw_update.sh,v 1.54 2023/11/15 02:03:49 afresh1 Exp $
 #
 # Copyright (c) 2021,2023 Andrew Hewus Fresh <afresh1@openbsd.org>
 #
@@ -278,6 +278,7 @@ firmware_devicename() {
 }
 
 lock_db() {
+       local _waited
        [ "${LOCKPID:-}" ] && return 0
 
        # The installer doesn't have perl, so we can't lock there
@@ -292,9 +293,22 @@ lock_db() {
                $|=1;
 
                $0 = "fw_update: lock_db";
-               lock_db(0);
+               my $waited = 0;
+               package OpenBSD::FwUpdateState {
+                       use parent 'OpenBSD::BaseState';
+                       sub errprint ($self, @p) {
+                               if ($p[0] && $p[0] =~ /already locked/) {
+                                       $waited++;
+                                       $p[0] = " " . $p[0]
+                                           if !$ENV{VERBOSE};
+                               }
+                               $self->SUPER::errprint(@p);
+                       }
+
+               }
+               lock_db(0, 'OpenBSD::FwUpdateState');
 
-               say $$;
+               say "$$ $waited";
 
                # Wait for STDOUT to be readable, which won't happen
                # but if our parent exits unexpectedly it will close.
@@ -304,7 +318,11 @@ lock_db() {
 EOL
        set +o monitor
 
-       read -rp LOCKPID
+       read -rp LOCKPID _waited
+
+       if ((_waited)); then
+               ! ((VERBOSE)) && status "${0##*/}:"
+       fi
 
        return 0
 }