1
0
mirror of https://github.com/lxc/go-lxc.git synced 2026-02-05 15:47:17 +01:00

introduce MayControl

This commit is contained in:
S.Çağlar Onur
2013-09-30 16:41:17 -04:00
parent 2a7698a413
commit d135b7dce3
4 changed files with 29 additions and 3 deletions

View File

@@ -90,6 +90,14 @@ func (lxc *Container) Running() bool {
return bool(C.lxc_container_running(lxc.container))
}
// MayControl returns whether the container is already running or not
func (lxc *Container) MayControl() bool {
lxc.RLock()
defer lxc.RUnlock()
return bool(C.lxc_container_may_control(lxc.container))
}
// State returns the container's state
func (lxc *Container) State() State {
lxc.RLock()

4
lxc.c
View File

@@ -239,3 +239,7 @@ int lxc_container_attach_run_wait(struct lxc_container *c, char **argv) {
return -1;
return ret;
}
bool lxc_container_may_control(struct lxc_container *c) {
return c->may_control(c);
}

2
lxc.h
View File

@@ -54,10 +54,10 @@ extern int lxc_container_console_getfd(struct lxc_container *, int);
extern pid_t lxc_container_init_pid(struct lxc_container *);
extern void lxc_container_want_daemonize(struct lxc_container *);
extern bool lxc_container_want_close_all_fds(struct lxc_container *);
extern bool lxc_container_may_control(struct lxc_container *);
//FIXME: Missing API functionality
// snapshot
// int (*snapshot)(struct lxc_container *c, char *commentfile);
// int (*snapshot_list)(struct lxc_container *, struct lxc_snapshot **);
// bool (*snapshot_restore)(struct lxc_container *c, char *snapname, char *newname);
//

View File

@@ -232,11 +232,25 @@ func TestStart(t *testing.T) {
z.Start(false)
z.Wait(lxc.RUNNING, 30)
if !z.Running() {
t.Errorf("Starting the container failed...")
}
func TestMayControl(t *testing.T) {
z := lxc.NewContainer(ContainerName)
defer lxc.PutContainer(z)
if !z.MayControl() {
t.Errorf("Controling the container failed...")
}
}
func TestRunning(t *testing.T) {
z := lxc.NewContainer(ContainerName)
defer lxc.PutContainer(z)
if !z.Running() {
t.Errorf("Checking the container failed...")
}
}
func TestSetDaemonize(t *testing.T) {
z := lxc.NewContainer(ContainerName)
defer lxc.PutContainer(z)