Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

container: add SetTimeout #166

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ErrNotDefined
}

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
11 changes: 11 additions & 0 deletions lxc-binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ 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)
if (!c->set_timeout(c, timeout))
return ret_errno(EINVAL);

return 0;
#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
Loading