Skip to content

Comments

fix: update systemd-cryptsetup path for snap environments#505

Open
gabelluardo wants to merge 2 commits intocanonical:masterfrom
gabelluardo:fix-cryptsetup-path
Open

fix: update systemd-cryptsetup path for snap environments#505
gabelluardo wants to merge 2 commits intocanonical:masterfrom
gabelluardo:fix-cryptsetup-path

Conversation

@gabelluardo
Copy link
Member

In snap-tpmctl, the application run within a strictly confined snap, making the hardcoded path to systemd-cryptsetup inaccessible. While this was previously addressed with a workaround, this PR implements a cleaner and more robust solution to resolve the binary path dinamically.

@gabelluardo gabelluardo marked this pull request as ready for review February 9, 2026 13:05
var (
systemdCryptsetupPath = "/lib/systemd/systemd-cryptsetup"
systemdCryptsetupPath string
once sync.Once

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename this once to link it to systemdCryptsetupPath, to show that both are related.

However, I would remove that until we have demonstrated that getting an environment has a high cost compared to fork/exec in a subprocess.

func MockSystemdCryptsetupPath(path string) (restore func()) {
origSystemdCryptsetupPath := systemdCryptsetupPath
systemdCryptsetupPath = path
origFn := getSystemdCryptsetupPath

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I would just use orig (you generally don’t suffix with the variable type name)

)

func defaultSystemdCryptsetupPath() string {
once.Do(func() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
once.Do(func() {
root := "/"
if p := os.Getenv("SNAP"); p != "" {
root = p
}
return filepath.Join(root, "lib", "systemd", "systemd-cryptsetup")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants