Skip to content

Commit 421faf0

Browse files
tas50claude
andcommitted
🧹 Address review: use sync.Once, revert copyright, add spelling entries
- Replace double-checked locking with sync.Once for race-free fetching - Revert unintentional copyright header change in os.lr.versions - Add "efi" and "secureboot" to spell-check expect.txt Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5fd162c commit 421faf0

File tree

3 files changed

+19
-28
lines changed

3 files changed

+19
-28
lines changed

.github/actions/spelling/expect.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ draid
7474
dsse
7575
eas
7676
Ecmp
77+
efi
7778
eip
7879
ekm
7980
ekus
@@ -227,6 +228,7 @@ Sas
227228
sbom
228229
scim
229230
scm
231+
secureboot
230232
SECRETID
231233
secretmanager
232234
SECRETVALUE

providers/os/resources/os.lr.versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) Mondoo, Inc.
1+
# Copyright Mondoo, Inc. 2024, 2026
22
# SPDX-License-Identifier: BUSL-1.1
33

44
apache2 11.8.14

providers/os/resources/secureboot.go

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,35 @@ import (
1414
const efiGlobalVariable = "8be4df61-93ca-11d2-aa0d-00e098032b8c"
1515

1616
type mqlMachineSecurebootInternal struct {
17-
statusFetched bool
17+
once sync.Once
1818
cacheEfi bool
1919
cacheEnabled bool
2020
cacheSetupMode bool
21-
lock sync.Mutex
21+
fetchErr error
2222
}
2323

2424
func (s *mqlMachineSecureboot) id() (string, error) {
2525
return "machine.secureboot", nil
2626
}
2727

2828
// fetchStatus reads the EFI firmware variables once and caches the result.
29-
// Uses double-checked locking to avoid redundant filesystem reads.
3029
func (s *mqlMachineSecureboot) fetchStatus() error {
31-
if s.statusFetched {
32-
return nil
33-
}
34-
s.lock.Lock()
35-
defer s.lock.Unlock()
36-
if s.statusFetched {
37-
return nil
38-
}
39-
40-
conn := s.MqlRuntime.Connection.(shared.Connection)
41-
fs := conn.FileSystem()
42-
43-
// Check if the system is booted in EFI mode by looking for /sys/firmware/efi.
44-
_, err := fs.Stat("/sys/firmware/efi")
45-
if err != nil {
46-
// No EFI directory means legacy BIOS boot — no Secure Boot possible.
47-
s.statusFetched = true
48-
return nil
49-
}
50-
s.cacheEfi = true
30+
s.once.Do(func() {
31+
conn := s.MqlRuntime.Connection.(shared.Connection)
32+
fs := conn.FileSystem()
5133

52-
s.cacheEnabled = readEfiVarBool(fs, "SecureBoot-"+efiGlobalVariable)
53-
s.cacheSetupMode = readEfiVarBool(fs, "SetupMode-"+efiGlobalVariable)
34+
// Check if the system is booted in EFI mode by looking for /sys/firmware/efi.
35+
_, err := fs.Stat("/sys/firmware/efi")
36+
if err != nil {
37+
// No EFI directory means legacy BIOS boot — no Secure Boot possible.
38+
return
39+
}
40+
s.cacheEfi = true
5441

55-
s.statusFetched = true
56-
return nil
42+
s.cacheEnabled = readEfiVarBool(fs, "SecureBoot-"+efiGlobalVariable)
43+
s.cacheSetupMode = readEfiVarBool(fs, "SetupMode-"+efiGlobalVariable)
44+
})
45+
return s.fetchErr
5746
}
5847

5948
// readEfiVarBool reads an EFI variable from /sys/firmware/efi/efivars/ and

0 commit comments

Comments
 (0)