diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2018-04-03 16:51:49 +0200 |
---|---|---|
committer | Neels Hofmeyr <neels@hofmeyr.de> | 2018-04-05 03:11:49 +0200 |
commit | cdbc9afe5da5fe728ce8fa62e36ded17efe70032 (patch) | |
tree | 5d1980f1c46409ec441557acaf66897295aedf84 /src/ctrl | |
parent | 6882b80d9630293f7db7606b1d73194d0571e6a4 (diff) |
ctrl: fix deferred commands (and hence fix osmo-bts-sysmo 'clock-info' cmd)
The CTRL interface has a ctrl_cmd_def_* API that allows deferring a CTRL
command reply until later. However, the command handling currently fails to
acknowledge this and deallocates the struct ctrl_cmd anyway.
Fix: in struct ctrl_cmd, add a defer pointer to be populated by
ctrl_cmd_def_make(). A cmd thus marked as deferred is not deallocated at the
end of command handling. This fix needs no change in calling code.
(Another idea was to return a different code than CTRL_CMD_HANDLED when the
command is to be deferred, but that would require adjusting each user of
ctrl_cmd_def_make(). The implicit marking is safer and easier.)
Show that handling deferred commands is fixed by adjusting the expectations of
ctrl_test.c's test_deferred_cmd() and removing the now obsolete exit_early
label.
One symptom of the breakage is that osmo-bts-sysmo crashes when asked to report
a trx's clock-info, which is aggravated by the fact that the sysmobts-mgr does
ask osmo-bts-sysmo for a clock-info.
The crash appears since Id583b413f8b8bd16e5cf92a8a9e8663903646381 -- it looked
like just fixing an obvious memory leak, which it did as shown by the unit
test, but deferred ctrl commands actually relied on that leak. Both fixed now.
Related: OS#3120
Change-Id: I24232be7dcf7be79f4def91ddc8b8f8005b56318
Diffstat (limited to 'src/ctrl')
-rw-r--r-- | src/ctrl/control_cmd.c | 1 | ||||
-rw-r--r-- | src/ctrl/control_if.c | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/src/ctrl/control_cmd.c b/src/ctrl/control_cmd.c index c747e84d..fb0cd2b7 100644 --- a/src/ctrl/control_cmd.c +++ b/src/ctrl/control_cmd.c @@ -566,6 +566,7 @@ ctrl_cmd_def_make(const void *ctx, struct ctrl_cmd *cmd, void *data, unsigned in cd = talloc_zero(ctx, struct ctrl_cmd_def); + cmd->defer = cd; cd->cmd = cmd; cd->data = data; diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c index 07de0d46..df8abbc6 100644 --- a/src/ctrl/control_if.c +++ b/src/ctrl/control_if.c @@ -401,6 +401,13 @@ int ctrl_handle_msg(struct ctrl_handle *ctrl, struct ctrl_connection *ccon, stru if (cmd->type != CTRL_TYPE_ERROR) { cmd->ccon = ccon; if (ctrl_cmd_handle(ctrl, cmd, ctrl->data) == CTRL_CMD_HANDLED) { + + if (cmd->defer) { + /* The command is still stored as ctrl_cmd_def.cmd, in the def_cmds list. + * Just leave hanging for deferred handling. Reply will happen later. */ + return 0; + } + /* On CTRL_CMD_HANDLED, no reply needs to be sent back. */ talloc_free(cmd); cmd = NULL; |