func (route *NetRoute) AddNextHop() (*NetRouteNextHop, error) { nh := C.libct_net_route_add_nh(route.route) if C.libct_handle_is_err(unsafe.Pointer(nh)) != 0 { return nil, LibctError{int(C.libct_handle_to_err(unsafe.Pointer(nh)))} } return &NetRouteNextHop{nh}, nil }
func (s *Session) ProcessCreateDesc() (*ProcessDesc, error) { p := C.libct_process_desc_create(s.s) if C.libct_handle_is_err(unsafe.Pointer(p)) != 0 { return nil, LibctError{int(C.libct_handle_to_err(unsafe.Pointer(p)))} } return &ProcessDesc{desc: p}, nil }
func (ct *Container) AddRoute() (*NetRoute, error) { r := C.libct_net_route_add(ct.ct) if C.libct_handle_is_err(unsafe.Pointer(r)) != 0 { return nil, LibctError{int(C.libct_handle_to_err(unsafe.Pointer(r)))} } return &NetRoute{r}, nil }
func (nd *NetDev) GetPeer() (*NetDev, error) { dev := C.libct_net_dev_get_peer(nd.dev) if C.libct_handle_is_err(unsafe.Pointer(dev)) != 0 { return nil, LibctError{int(C.libct_handle_to_err(unsafe.Pointer(dev)))} } return &NetDev{dev}, nil }
func (s *Session) OpenLocal() error { h := C.libct_session_open_local() if C.libct_handle_is_err(unsafe.Pointer(h)) != 0 { return LibctError{int(C.libct_handle_to_err(unsafe.Pointer(h)))} } s.s = h return nil }
func (s *Session) ContainerCreate(name string) (*Container, error) { cname := C.CString(name) defer C.free(unsafe.Pointer(cname)) ct := C.libct_container_create(s.s, cname) if C.libct_handle_is_err(unsafe.Pointer(ct)) != 0 { return nil, LibctError{int(C.libct_handle_to_err(unsafe.Pointer(ct)))} } return &Container{ct}, nil }
func (ct *Container) Load(p *ProcessDesc, pid int) error { h := C.libct_container_load(ct.ct, C.pid_t(pid)) if C.libct_handle_is_err(unsafe.Pointer(h)) != 0 { p.closeDescriptors(p.closeAfterStart) p.closeDescriptors(p.closeAfterWait) return LibctError{int(C.libct_handle_to_err(unsafe.Pointer(h)))} } p.handle = h return nil }
func (ct *Container) Processes() ([]int, error) { ctasks := C.libct_container_processes(ct.ct) if C.libct_handle_is_err(unsafe.Pointer(ctasks)) != 0 { return nil, LibctError{int(C.libct_handle_to_err(unsafe.Pointer(ctasks)))} } defer C.libct_processes_free(ctasks) tasks := make([]int, int(ctasks.nproc)) for i := 0; i < int(ctasks.nproc); i++ { tasks[i] = int(C.libct_processes_get(ctasks, C.int(i))) } return tasks, nil }
func (ct *Container) AddNetVeth(host_name string, ct_name string) (*NetDev, error) { var args C.struct_ct_net_veth_arg chost_name := C.CString(host_name) defer C.free(unsafe.Pointer(chost_name)) cct_name := C.CString(ct_name) defer C.free(unsafe.Pointer(cct_name)) args.host_name = chost_name args.ct_name = cct_name dev := C.libct_net_add(ct.ct, C.CT_NET_VETH, unsafe.Pointer(&args)) if C.libct_handle_is_err(unsafe.Pointer(dev)) != 0 { return nil, LibctError{int(C.libct_handle_to_err(unsafe.Pointer(dev)))} } return &NetDev{dev}, nil }
func (ct *Container) execve(p *ProcessDesc, path string, argv []string, env []string, spawn bool) error { var ( h C.ct_process_t i int = 0 ) type F func(*ProcessDesc) (file, error) for _, setupFd := range []F{(*ProcessDesc).stdin, (*ProcessDesc).stdout, (*ProcessDesc).stderr} { fd, err := setupFd(p) if err != nil { p.closeDescriptors(p.closeAfterStart) p.closeDescriptors(p.closeAfterWait) return err } p.childFiles = append(p.childFiles, fd) i = i + 1 } freeStrings := func(array []*C.char) { for _, item := range array { if item != nil { C.free(unsafe.Pointer(item)) } } } p.childFiles = append(p.childFiles, p.ExtraFiles...) cargv := make([]*C.char, len(argv)+1) defer freeStrings(cargv) for i, arg := range argv { cargv[i] = C.CString(arg) } var penv **C.char if env == nil { penv = nil } else { cenv := make([]*C.char, len(env)+1) defer freeStrings(cenv) for i, e := range env { cenv[i] = C.CString(e) } penv = &cenv[0] } cfds := make([]C.int, len(p.childFiles)) for i, fd := range p.childFiles { cfds[i] = C.int(getFd(fd)) } C.libct_process_desc_set_fds(p.desc, &cfds[0], C.int(len(p.childFiles))) cpath := C.CString(path) defer C.free(unsafe.Pointer(cpath)) if spawn { h = C.libct_container_spawn_execve(ct.ct, p.desc, cpath, &cargv[0], penv) } else { h = C.libct_container_enter_execve(ct.ct, p.desc, cpath, &cargv[0], penv) } if C.libct_handle_is_err(unsafe.Pointer(h)) != 0 { p.closeDescriptors(p.closeAfterStart) p.closeDescriptors(p.closeAfterWait) return LibctError{int(C.libct_handle_to_err(unsafe.Pointer(h)))} } p.closeDescriptors(p.closeAfterStart) p.errch = make(chan error, len(p.goroutine)) for _, fn := range p.goroutine { go func(fn func() error) { p.errch <- fn() }(fn) } p.handle = h return nil }