When verification failed and the reply string was not updated, the
message "Someone forgot to fill in the reply." was shown instead
of the default "Value failed verification." message.
This patch changes the default reply handling in ctrl_cmd_handle()
by setting the reply to NULL initially and then checking it at the
end. If it hasn't been set, a generic message is assigned and an
error is logged.
---
openbsc/src/libctrl/control_if.c | 10 +++++++++-
openbsc/tests/ctrl_test_runner.py | 4 ++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/openbsc/src/libctrl/control_if.c b/openbsc/src/libctrl/control_if.c
index b31f34f..2076f0c 100644
--- a/openbsc/src/libctrl/control_if.c
+++ b/openbsc/src/libctrl/control_if.c
@@ -147,7 +147,7 @@ int ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data)
vector vline, cmdvec, cmds_vec;
ret = CTRL_CMD_ERROR;
- cmd->reply = "Someone forgot to fill in the reply.";
+ cmd->reply = NULL;
node = CTRL_NODE_ROOT;
cmd->node = net;
@@ -238,6 +238,14 @@ int ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data)
cmd_free_strvec(vline);
err:
+ if (!cmd->reply) {
+ LOGP(DCTRL, LOGL_ERROR, "cmd->replay has not been set.\n", ret);
+ if (ret == CTRL_CMD_ERROR)
+ cmd->reply = "An error has occured.";
+ else
+ cmd->reply = "Command has been handled.";
+ }
+
if (ret == CTRL_CMD_ERROR)
cmd->type = CTRL_TYPE_ERROR;
return ret;
diff --git a/openbsc/tests/ctrl_test_runner.py b/openbsc/tests/ctrl_test_runner.py
index 8f5a0ec..b012981 100644
--- a/openbsc/tests/ctrl_test_runner.py
+++ b/openbsc/tests/ctrl_test_runner.py
@@ -159,6 +159,10 @@ class TestCtrlBSC(TestCtrlBase):
self.assertEquals(r['mtype'], 'ERROR')
self.assertEquals(r['error'], 'Command not found')
+ r = self.do_set('rf_locked', '999')
+ self.assertEquals(r['mtype'], 'ERROR')
+ self.assertEquals(r['error'], 'Value failed verification.')
+
r = self.do_get('bts')
self.assertEquals(r['mtype'], 'ERROR')
self.assertEquals(r['error'], 'Error while parsing the index.')
--
1.7.9.5