diff options
author | Paul Joseph Davis <davisp@apache.org> | 2010-11-05 23:59:14 +0000 |
---|---|---|
committer | Paul Joseph Davis <davisp@apache.org> | 2010-11-05 23:59:14 +0000 |
commit | 96aee7d6b6a94040787d935dc14d4ebda6981dcf (patch) | |
tree | f5bac44d1081c6c16922bc8a638373e75f4df92c | |
parent | 11469d902b15145d361f9f7ec66a09ac3d04757c (diff) |
Don't choke on unknown configuration settings.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1031884 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/couchdb/couch_os_daemons.erl | 12 | ||||
-rwxr-xr-x | test/etap/171-os-daemons-config.es | 5 |
2 files changed, 13 insertions, 4 deletions
diff --git a/src/couchdb/couch_os_daemons.erl b/src/couchdb/couch_os_daemons.erl index daf98f25..bdd39997 100644 --- a/src/couchdb/couch_os_daemons.erl +++ b/src/couchdb/couch_os_daemons.erl @@ -210,12 +210,16 @@ stop_port(#daemon{port=Port}=D) -> handle_port_message(#daemon{port=Port}=Daemon, [<<"get">>, Section]) -> KVs = couch_config:get(Section), Data = lists:map(fun({K, V}) -> {?l2b(K), ?l2b(V)} end, KVs), - JsonData = ?JSON_ENCODE({Data}), - port_command(Port, JsonData ++ "\n"), + Json = iolist_to_binary(?JSON_ENCODE({Data})), + port_command(Port, <<Json/binary, "\n">>), {ok, Daemon}; handle_port_message(#daemon{port=Port}=Daemon, [<<"get">>, Section, Key]) -> - Value = couch_config:get(Section, Key, null), - port_command(Port, ?JSON_ENCODE(?l2b(Value)) ++ "\n"), + Value = case couch_config:get(Section, Key, null) of + null -> null; + String -> ?l2b(String) + end, + Json = iolist_to_binary(?JSON_ENCODE(Value)), + port_command(Port, <<Json/binary, "\n">>), {ok, Daemon}; handle_port_message(Daemon, [<<"register">>, Sec]) when is_binary(Sec) -> Patterns = lists:usort(Daemon#daemon.cfg_patterns ++ [{?b2l(Sec)}]), diff --git a/test/etap/171-os-daemons-config.es b/test/etap/171-os-daemons-config.es index 96e051a3..1f68ddc6 100755 --- a/test/etap/171-os-daemons-config.es +++ b/test/etap/171-os-daemons-config.es @@ -50,6 +50,10 @@ test_get_cfg2() -> FileName = get_cfg(<<"os_daemons">>, <<"foo">>), <<"sequential">> = get_cfg(<<"uuids">>, <<"algorithm">>). +test_get_unknown_cfg() -> + {[]} = get_cfg(<<"aal;3p4">>), + null = get_cfg(<<"aal;3p4">>, <<"313234kjhsdfl">>). + test_log() -> log(<<"foobar!">>), log(<<"some stuff!">>, <<"debug">>), @@ -63,6 +67,7 @@ test_log() -> do_tests() -> test_get_cfg1(), test_get_cfg2(), + test_get_unknown_cfg(), test_log(), loop(io:read("")). |