From 5f4d3f3670a0fd4be5c9538e812839ec510e08a9 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 14 Apr 2025 13:59:39 -0700 Subject: [PATCH] libct/apparmor: don't use vars for public functions Unfortunately, Go documentation formatter does a sloppy job formatting documentation for variables -- it is rendered as comments (see [1]). Switch to using wrapper functions, solely for the sake of better documentation formatting. [1]: https://pkg.go.dev/github.com/opencontainers/runc@v1.3.0-rc.2/libcontainer/apparmor Signed-off-by: Kir Kolyshkin --- libcontainer/apparmor/apparmor.go | 22 ++++++++++++---------- libcontainer/apparmor/apparmor_linux.go | 7 +++---- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/libcontainer/apparmor/apparmor.go b/libcontainer/apparmor/apparmor.go index 4b03d4c71..e2a26488e 100644 --- a/libcontainer/apparmor/apparmor.go +++ b/libcontainer/apparmor/apparmor.go @@ -2,15 +2,17 @@ package apparmor import "errors" -var ( - // IsEnabled returns true if apparmor is enabled for the host. - IsEnabled = isEnabled +// IsEnabled returns true if apparmor is enabled for the host. +func IsEnabled() bool { + return isEnabled() +} - // ApplyProfile will apply the profile with the specified name to the process after - // the next exec. It is only supported on Linux and produces an ErrApparmorNotEnabled - // on other platforms. - ApplyProfile = applyProfile +// ApplyProfile will apply the profile with the specified name to the process +// after the next exec. It is only supported on Linux and produces an +// [ErrApparmorNotEnabled] on other platforms. +func ApplyProfile(name string) error { + return applyProfile(name) +} - // ErrApparmorNotEnabled indicates that AppArmor is not enabled or not supported. - ErrApparmorNotEnabled = errors.New("apparmor: config provided but apparmor not supported") -) +// ErrApparmorNotEnabled indicates that AppArmor is not enabled or not supported. +var ErrApparmorNotEnabled = errors.New("apparmor: config provided but apparmor not supported") diff --git a/libcontainer/apparmor/apparmor_linux.go b/libcontainer/apparmor/apparmor_linux.go index 17d36ed15..10da91b3c 100644 --- a/libcontainer/apparmor/apparmor_linux.go +++ b/libcontainer/apparmor/apparmor_linux.go @@ -53,7 +53,7 @@ func setProcAttr(attr, value string) error { return err } -// changeOnExec reimplements aa_change_onexec from libapparmor in Go +// changeOnExec reimplements aa_change_onexec from libapparmor in Go. func changeOnExec(name string) error { if err := setProcAttr("exec", "exec "+name); err != nil { return fmt.Errorf("apparmor failed to apply profile: %w", err) @@ -61,9 +61,8 @@ func changeOnExec(name string) error { return nil } -// applyProfile will apply the profile with the specified name to the process after -// the next exec. It is only supported on Linux and produces an error on other -// platforms. +// applyProfile will apply the profile with the specified name to the process +// after the next exec. func applyProfile(name string) error { if name == "" { return nil