Skip to content

Commit

Permalink
container: add SetTimeout
Browse files Browse the repository at this point in the history
Extend container API with a new method SetTimeout
which allows to set SO_RCVTIMEO for LXC client socket.

Issue #4257

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
  • Loading branch information
mihalicyn committed Aug 28, 2023
1 parent be98af2 commit 7504f02
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,23 @@ func (c *Container) SeccompNotifyFdActive() (*os.File, error) {
return os.NewFile(uintptr(notifyFd), "seccomp notify"), nil
}

// SetTimeout sets the response receive timeout for commands
func (c *Container) SetTimeout(timeout time.Duration) error {
c.mu.Lock()
defer c.mu.Unlock()

if c.container == nil {
return false
}

ret := int(C.go_lxc_set_timeout(c.container, C.int(timeout.Seconds())))
if ret < 0 {
return unix.Errno(-ret)
}

return nil
}

// Daemonize returns true if the container wished to be daemonized.
func (c *Container) Daemonize() bool {
c.mu.RLock()
Expand Down
8 changes: 8 additions & 0 deletions lxc-binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ int go_lxc_seccomp_notify_fd_active(struct lxc_container *c) {
#endif
}

int go_lxc_set_timeout(struct lxc_container *c, int timeout) {
#if VERSION_AT_LEAST(5, 0, 4)
return c->set_timeout(c, timeout);
#else
return ret_errno(ENOSYS);
#endif
}

int go_lxc_devpts_fd(struct lxc_container *c) {
#if VERSION_AT_LEAST(4, 0, 5)
return c->devpts_fd(c);
Expand Down
1 change: 1 addition & 0 deletions lxc-binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ extern int go_lxc_init_pidfd(struct lxc_container *c);
extern int go_lxc_devpts_fd(struct lxc_container *c);
extern int go_lxc_seccomp_notify_fd(struct lxc_container *c);
extern int go_lxc_seccomp_notify_fd_active(struct lxc_container *c);
extern int go_lxc_set_timeout(struct lxc_container *c, int timeout);
extern bool go_lxc_checkpoint(struct lxc_container *c, char *directory, bool stop, bool verbose);
extern bool go_lxc_restore(struct lxc_container *c, char *directory, bool verbose);
extern bool go_lxc_config_item_is_supported(const char *key);
Expand Down

0 comments on commit 7504f02

Please sign in to comment.