Skip to content

Commit 4abf43e

Browse files
trace apparmor error (#33876)
1 parent bdb3b03 commit 4abf43e

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

pkg/fleet/installer/packages/app_armor.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func setupAppArmor(ctx context.Context) (err error) {
119119
return fmt.Errorf("failed validate %s contains an include to base.d: %w", appArmorBaseProfile, err)
120120
}
121121

122-
if err = reloadAppArmor(); err != nil {
122+
if err = reloadAppArmor(ctx); err != nil {
123123
if rollbackErr := os.Remove(appArmorInjectorProfilePath); rollbackErr != nil {
124124
log.Warnf("failed to remove apparmor profile: %v", rollbackErr)
125125
}
@@ -147,19 +147,20 @@ func removeAppArmor(ctx context.Context) (err error) {
147147
if err = os.Remove(appArmorInjectorProfilePath); err != nil {
148148
return err
149149
}
150-
return reloadAppArmor()
150+
_ = reloadAppArmor(ctx)
151+
return nil
151152
}
152153

153-
func reloadAppArmor() error {
154+
func reloadAppArmor(ctx context.Context) error {
154155
if !isAppArmorRunning() {
155156
return nil
156157
}
157158
if running, err := isSystemdRunning(); err != nil {
158159
return err
159160
} else if running {
160-
return exec.Command("systemctl", "reload", "apparmor").Run()
161+
return tracedCommand(ctx, "systemctl", "reload", "apparmor")
161162
}
162-
return exec.Command("service", "apparmor", "reload").Run()
163+
return tracedCommand(ctx, "service", "apparmor", "reload")
163164
}
164165

165166
func isAppArmorRunning() bool {
@@ -169,3 +170,12 @@ func isAppArmorRunning() bool {
169170
}
170171
return strings.TrimSpace(string(data)) == "Y"
171172
}
173+
174+
func tracedCommand(ctx context.Context, name string, arg ...string) (err error) {
175+
span, _ := telemetry.StartSpanFromContext(ctx, name)
176+
defer func() { span.Finish(err) }()
177+
178+
cmd := exec.Command(name, arg...)
179+
_, err = cmd.Output()
180+
return err
181+
}

0 commit comments

Comments
 (0)