mirror of https://github.com/ceph/go-ceph
lib: fix parse commnad line arguments
Adds a placeholder string at argv[0] position because Ceph will start parsing the provided arguments at position argv[1] (skipping what would normally be the executable name). Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
This commit is contained in:
parent
728afd56be
commit
b8609f826c
14
conn.go
14
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))
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue