diff --git a/conn.go b/conn.go index e0a8637..61dcae0 100644 --- a/conn.go +++ b/conn.go @@ -179,12 +179,20 @@ func (c *Conn) GetClusterStats() (stat ClusterStat, err error) { // ParseCmdLineArgs configures the connection from command line arguments. func (c *Conn) ParseCmdLineArgs(args []string) error { - argc := C.int(len(args)) + // add an empty element 0 -- Ceph treats the array as the actual contents + // of argv and skips the first element (the executable name) + argc := C.int(len(args) + 1) argv := make([]*C.char, argc) + + // make the first element a string just in case it is ever examined + argv[0] = C.CString("placeholder") + defer C.free(unsafe.Pointer(argv[0])) + for i, arg := range args { - argv[i] = C.CString(arg) - defer C.free(unsafe.Pointer(argv[i])) + argv[i+1] = C.CString(arg) + defer C.free(unsafe.Pointer(argv[i+1])) } + ret := C.rados_conf_parse_argv(c.cluster, argc, &argv[0]) if ret < 0 { return RadosError(int(ret)) diff --git a/rados_test.go b/rados_test.go index dafcc53..9eb329c 100644 --- a/rados_test.go +++ b/rados_test.go @@ -56,16 +56,17 @@ func TestParseDefaultConfigEnv(t *testing.T) { func TestParseCmdLineArgs(t *testing.T) { conn, _ := rados.NewConn() + conn.ReadDefaultConfigFile() - log_file_val, _ := conn.GetConfigOption("mon_host") - assert.NotEqual(t, log_file_val, "127.0.0.1") + mon_host_val, _ := conn.GetConfigOption("mon_host") + assert.NotEqual(t, mon_host_val, "1.1.1.1") - args := []string{ "--mon-host 127.0.0.1" } + args := []string{ "--mon-host", "1.1.1.1" } err := conn.ParseCmdLineArgs(args) assert.NoError(t, err) - log_file_val, _ = conn.GetConfigOption("mon_host") - assert.Equal(t, log_file_val, "127.0.0.1") + mon_host_val, _ = conn.GetConfigOption("mon_host") + assert.Equal(t, mon_host_val, "1.1.1.1") } func TestGetClusterStats(t *testing.T) {