On Thu, Mar 16, 2017 at 7:08 PM, Ronald Rojas <ronlad...@gmail.com> wrote: > Implement Golang enumeration of libxl_console_type > as ConsoleType > > Implement the following libxl functions: > - libxl_console_get_tty > - libxl_primary_console_get_tty > > Signed-off-by: Ronald Rojas <ronlad...@gmail.com> > --- > CC: xen-devel@lists.xen.org > CC: george.dun...@citrix.com > CC: ian.jack...@eu.citrix.com > CC: wei.l...@citrix.com > --- > --- > tools/golang/xenlight/xenlight.go | 57 > +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 57 insertions(+) > > diff --git a/tools/golang/xenlight/xenlight.go > b/tools/golang/xenlight/xenlight.go > index 61d7f8f..d520f74 100644 > --- a/tools/golang/xenlight/xenlight.go > +++ b/tools/golang/xenlight/xenlight.go > @@ -1080,3 +1080,60 @@ func (Ctx *Context) ListVcpu(id Domid) (glist > []Vcpuinfo) { > > return > } > + > +type ConsoleType int > + > +const ( > + ConsoleTypeUnknown = ConsoleType(C.LIBXL_CONSOLE_TYPE_UNKNOWN) > + ConsoleTypeSerial = ConsoleType(C.LIBXL_CONSOLE_TYPE_SERIAL) > + ConsoleTypePV = ConsoleType(C.LIBXL_CONSOLE_TYPE_PV) > +) > + > +func (ct ConsoleType) String() (str string) { > + cstr := C.libxl_console_type_to_string(C.libxl_console_type(ct)) > + str = C.GoString(cstr) > + > + return > +} > + > +//int libxl_console_get_tty(libxl_ctx *ctx, uint32_t domid, int cons_num, > +//libxl_console_type type, char **path); > +func (Ctx *Context) ConsoleGetTty(id Domid, consNum int, conType > ConsoleType) (path string, err error) { > + err = Ctx.CheckOpen() > + if err != nil { > + return > + } > + > + var cpath *C.char > + defer C.free(cpath) > + ret := C.libxl_console_get_tty(Ctx.ctx, C.uint32_t(id), > C.int(consNum), C.libxl_console_type(conType), &cpath) > + > + if ret != 0 { > + err = Error(-ret) > + return > + }
You can't call `defer C.free()` until you're certain that cpath will contain a non-NULL pointer (here and in PrimaryConsole...) Everything else looks fine. -George _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel