Skip to content

Commit

Permalink
Merge pull request #170 from stgraber/v2
Browse files Browse the repository at this point in the history
container: Better handle lxc_start
  • Loading branch information
hallyn authored Jun 6, 2024
2 parents ccae595 + f0b2829 commit 27b3d11
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ jobs:
- name: Install dependencies
run: |
sudo add-apt-repository ppa:ubuntu-lxc/daily -y
sudo apt-get install -qq apparmor lxc lxc-dev pkg-config uidmap busybox libdbus-1-dev libseccomp-dev libcap-dev libselinux-dev
sudo apt-get install -qq apparmor lxc lxc-dev pkg-config uidmap busybox libdbus-1-dev libseccomp-dev libcap-dev libselinux-dev nftables iptables
- name: Reset all firewalling
run: |
sudo iptables -F
sudo iptables -P INPUT ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo nft flush ruleset
- name: Setup test environment
run: |
Expand Down
21 changes: 17 additions & 4 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,16 @@ func (c *Container) StartWithArgs(args []string) error {
return err
}

if !bool(C.go_lxc_start(c.container, 0, makeNullTerminatedArgs(args))) {
return ErrStartFailed
if args != nil {
if !bool(C.go_lxc_start(c.container, 0, makeNullTerminatedArgs(args))) {
return ErrStartFailed
}
} else {
if !bool(C.go_lxc_start(c.container, 0, nil)) {
return ErrStartFailed
}
}

return nil
}

Expand All @@ -667,8 +674,14 @@ func (c *Container) StartExecute(args []string) error {
return err
}

if !bool(C.go_lxc_start(c.container, 1, makeNullTerminatedArgs(args))) {
return ErrStartFailed
if args != nil {
if !bool(C.go_lxc_start(c.container, 1, makeNullTerminatedArgs(args))) {
return ErrStartFailed
}
} else {
if !bool(C.go_lxc_start(c.container, 1, nil)) {
return ErrStartFailed
}
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/lxc/go-lxc

go 1.20

require golang.org/x/sys v0.12.0
require golang.org/x/sys v0.21.0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
15 changes: 6 additions & 9 deletions lxc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ func unprivileged() bool {
return os.Geteuid() != 0
}

func travis() bool {
// https://docs.travis-ci.com/user/environment-variables/#default-environment-variables
return os.Getenv("TRAVIS") == "true"
}

func supported(moduleName string) bool {
if _, err := os.Stat("/sys/module/" + moduleName); err != nil {
return false
Expand Down Expand Up @@ -1411,22 +1406,24 @@ func TestIPv4Addresses(t *testing.T) {
}
defer c.Release()

// Wait for IP configuration.
time.Sleep(5 * time.Second)

if _, err := c.IPv4Addresses(); err != nil {
t.Errorf(err.Error())
}
}

func TestIPv6Addresses(t *testing.T) {
if !ipv6() {
t.Skip("skipping test since lxc bridge does not have ipv6 address")
}

c, err := NewContainer(ContainerName())
if err != nil {
t.Errorf(err.Error())
}
defer c.Release()

// Wait for IP configuration.
time.Sleep(5 * time.Second)

if _, err := c.IPv6Addresses(); err != nil {
t.Errorf(err.Error())
}
Expand Down

0 comments on commit 27b3d11

Please sign in to comment.