Skip to content
Open
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
9 changes: 9 additions & 0 deletions src/control/cmd/ddb/commands_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ func freeString(s *C.char) {
C.free(unsafe.Pointer(s))
}

func SetCString(out **C.char, s string) func() {
cstr := C.CString(s)
*out = cstr

return func() {
C.free(unsafe.Pointer(cstr))
}
}

// InitDdb initializes the ddb context and returns a closure to finalize it.
func InitDdb(log *logging.LeveledLogger) (*DdbContext, func(), error) {
// Must lock to OS thread because vos init/fini uses ABT init and finalize which must be called on the same thread
Expand Down
4 changes: 4 additions & 0 deletions src/control/cmd/ddb/ddb_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ pool shard. Part of the path is used to determine what the pool uuid is.`,
a.String("path", "Path to the vos file to open.")
},
Run: func(c *grumble.Context) error {
if c.Flags.String("db_path") != "" {
cleanup := SetCString(&ctx.ctx.dc_db_path, c.Flags.String("db_path"))
defer cleanup()
}
return ddbOpen(ctx, c.Args.String("path"), c.Flags.Bool("write_mode"))
},
Completer: openCompleter,
Expand Down
14 changes: 4 additions & 10 deletions src/control/cmd/ddb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"path/filepath"
"runtime/debug"
"strings"
"unsafe"

"github.com/desertbit/columnize"
"github.com/desertbit/go-shlex"
Expand All @@ -31,11 +30,6 @@ import (
"github.com/daos-stack/daos/src/control/server/engine"
)

/*
#include <stdlib.h>
*/
import "C"

func exitWithError(err error) {
cmdName := path.Base(os.Args[0])
fmt.Fprintf(os.Stderr, "ERROR: %s: %v\n", cmdName, err)
Expand Down Expand Up @@ -307,13 +301,13 @@ func parseOpts(args []string, opts *cliOptions) error {
app := createGrumbleApp(ctx)

if opts.SysdbPath != "" {
ctx.ctx.dc_db_path = C.CString(string(opts.SysdbPath))
defer C.free(unsafe.Pointer(ctx.ctx.dc_db_path))
cleanup := SetCString(&ctx.ctx.dc_db_path, string(opts.SysdbPath))
defer cleanup()
}

if opts.VosPath != "" {
ctx.ctx.dc_pool_path = C.CString(string(opts.VosPath))
defer C.free(unsafe.Pointer(ctx.ctx.dc_pool_path))
cleanup := SetCString(&ctx.ctx.dc_pool_path, string(opts.VosPath))
defer cleanup()

if !strings.HasPrefix(string(opts.Args.RunCmd), "feature") &&
!strings.HasPrefix(string(opts.Args.RunCmd), "open") &&
Expand Down
Loading