Skip to content

Commit

Permalink
Fix build failure on Podman vendor
Browse files Browse the repository at this point in the history
Basically Windows build is failing when hitting unix contants in
cgroups.

[NO NEW TESTS ADDED] Just shifting code around.

Added build-cross to cirrus tests, which looks like it was not being
run.

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Dec 14, 2021
1 parent 996e1c5 commit 5f1f1f6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 39 deletions.
39 changes: 0 additions & 39 deletions pkg/cgroups/cgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ import (
"path/filepath"
"strconv"
"strings"
"time"

"github.com/containers/storage/pkg/unshare"
systemdDbus "github.com/coreos/go-systemd/v22/dbus"
"github.com/godbus/dbus/v5"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)

var (
Expand Down Expand Up @@ -511,43 +509,6 @@ func (c *CgroupControl) Delete() error {
return c.DeleteByPath(c.path)
}

// rmDirRecursively delete recursively a cgroup directory.
// It differs from os.RemoveAll as it doesn't attempt to unlink files.
// On cgroupfs we are allowed only to rmdir empty directories.
func rmDirRecursively(path string) error {
if err := os.Remove(path); err == nil || os.IsNotExist(err) {
return nil
}
entries, err := ioutil.ReadDir(path)
if err != nil {
return err
}
for _, i := range entries {
if i.IsDir() {
if err := rmDirRecursively(filepath.Join(path, i.Name())); err != nil {
return err
}
}
}

attempts := 0
for {
err := os.Remove(path)
if err == nil || os.IsNotExist(err) {
return nil
}
if errors.Is(err, unix.EBUSY) {
// attempt up to 5 seconds if the cgroup is busy
if attempts < 500 {
time.Sleep(time.Millisecond * 10)
attempts++
continue
}
}
return errors.Wrapf(err, "remove %s", path)
}
}

// DeleteByPathConn deletes the specified cgroup path using the specified
// dbus connection if needed.
func (c *CgroupControl) DeleteByPathConn(path string, conn *systemdDbus.Conn) error {
Expand Down
39 changes: 39 additions & 0 deletions pkg/cgroups/cgroups_supported.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ package cgroups
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"sync"
"syscall"
"time"

"github.com/pkg/errors"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -88,3 +90,40 @@ func UserOwnsCurrentSystemdCgroup() (bool, error) {
}
return true, nil
}

// rmDirRecursively delete recursively a cgroup directory.
// It differs from os.RemoveAll as it doesn't attempt to unlink files.
// On cgroupfs we are allowed only to rmdir empty directories.
func rmDirRecursively(path string) error {
if err := os.Remove(path); err == nil || os.IsNotExist(err) {
return nil
}
entries, err := ioutil.ReadDir(path)
if err != nil {
return err
}
for _, i := range entries {
if i.IsDir() {
if err := rmDirRecursively(filepath.Join(path, i.Name())); err != nil {
return err
}
}
}

attempts := 0
for {
err := os.Remove(path)
if err == nil || os.IsNotExist(err) {
return nil
}
if errors.Is(err, unix.EBUSY) {
// attempt up to 5 seconds if the cgroup is busy
if attempts < 500 {
time.Sleep(time.Millisecond * 10)
attempts++
continue
}
}
return errors.Wrapf(err, "remove %s", path)
}
}
8 changes: 8 additions & 0 deletions pkg/cgroups/cgroups_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

package cgroups

import (
"os"
)

// IsCgroup2UnifiedMode returns whether we are running in cgroup 2 cgroup2 mode.
func IsCgroup2UnifiedMode() (bool, error) {
return false, nil
Expand All @@ -12,3 +16,7 @@ func IsCgroup2UnifiedMode() (bool, error) {
func UserOwnsCurrentSystemdCgroup() (bool, error) {
return false, nil
}

func rmDirRecursively(path string) error {
return os.RemoveAll(path)
}

0 comments on commit 5f1f1f6

Please sign in to comment.