Skip to content

Commit 30cdf17

Browse files
refactor: cleanup code
1 parent 44b2590 commit 30cdf17

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

jail/linux.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -295,25 +295,15 @@ func (l *LinuxJail) configureIptables() error {
295295

296296
// cleanupNetworking removes networking configuration
297297
func (l *LinuxJail) cleanupNetworking() error {
298-
// Generate unique ID to match veth pair
299-
uniqueID := fmt.Sprintf("%d", time.Now().UnixNano()%10000000) // 7 digits max
300-
vethHost := fmt.Sprintf("veth_h_%s", uniqueID) // veth_h_1234567 = 14 chars
301-
302-
// Clean up networking
303-
cleanupCmds := []struct {
304-
description string
305-
command *exec.Cmd
306-
}{
298+
runner := newCommandRunner([]*command{
307299
{
308300
"delete veth pair",
309-
exec.Command("ip", "link", "del", vethHost),
301+
exec.Command("ip", "link", "del", l.vethHostName),
302+
[]uintptr{uintptr(unix.CAP_NET_ADMIN)},
310303
},
311-
}
312-
313-
for _, command := range cleanupCmds {
314-
if err := command.command.Run(); err != nil {
315-
l.logger.Error("failed to execute command", "command", command.description, "error", err)
316-
}
304+
})
305+
if err := runner.runIgnoreErrors(); err != nil {
306+
return err
317307
}
318308

319309
return nil

0 commit comments

Comments
 (0)