summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/osmocom/ctrl/control_cmd.h3
-rw-r--r--src/ctrl/control_cmd.c1
-rw-r--r--src/ctrl/control_if.c7
-rw-r--r--tests/ctrl/ctrl_test.c4
-rw-r--r--tests/ctrl/ctrl_test.ok3
5 files changed, 13 insertions, 5 deletions
diff --git a/include/osmocom/ctrl/control_cmd.h b/include/osmocom/ctrl/control_cmd.h
index 865b006b..a5df753d 100644
--- a/include/osmocom/ctrl/control_cmd.h
+++ b/include/osmocom/ctrl/control_cmd.h
@@ -56,6 +56,8 @@ struct ctrl_connection {
struct llist_head def_cmds;
};
+struct ctrl_cmd_def;
+
struct ctrl_cmd {
struct ctrl_connection *ccon;
enum ctrl_type type;
@@ -64,6 +66,7 @@ struct ctrl_cmd {
char *variable;
char *value;
char *reply;
+ struct ctrl_cmd_def *defer;
};
#define ctrl_cmd_reply_printf(cmd, fmt, args ...) \
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;
diff --git a/tests/ctrl/ctrl_test.c b/tests/ctrl/ctrl_test.c
index f20f534c..b7b30c3e 100644
--- a/tests/ctrl/ctrl_test.c
+++ b/tests/ctrl/ctrl_test.c
@@ -401,8 +401,6 @@ static void test_deferred_cmd()
/* Expecting a ctrl_cmd_def as well as the cmd to still be allocated */
if (talloc_total_size(ctx) <= ctx_size_before_defer) {
printf("deferred command apparently deallocated too soon\n");
- /* ERROR -- showing current bug in handling deallocated cmds, hence exiting early */
- goto exit_early;
talloc_report_full(ctx, stdout);
OSMO_ASSERT(false);
}
@@ -417,8 +415,6 @@ static void test_deferred_cmd()
OSMO_ASSERT(false);
}
-exit_early:
-
talloc_free(ccon);
talloc_free(ctrl);
diff --git a/tests/ctrl/ctrl_test.ok b/tests/ctrl/ctrl_test.ok
index 6a902be0..07f4aac5 100644
--- a/tests/ctrl/ctrl_test.ok
+++ b/tests/ctrl/ctrl_test.ok
@@ -176,5 +176,6 @@ ok
test_deferred_cmd
get_test_defer called
ctrl_handle_msg() returned 0
-deferred command apparently deallocated too soon
+invoking ctrl_test_defer_cb() asynchronously
+ctrl_test_defer_cb called
success