[MERGED] libosmocore[master]: cosmetic: flatten ctrl_handle_msg()

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Apr 5 13:51:09 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: cosmetic: flatten ctrl_handle_msg()
......................................................................


cosmetic: flatten ctrl_handle_msg()

Change-Id: I3a711f5c974b7f56e27b333d390d1a706fb57007
---
M src/ctrl/control_if.c
1 file changed, 19 insertions(+), 17 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c
index df8abbc..cc613ee 100644
--- a/src/ctrl/control_if.c
+++ b/src/ctrl/control_if.c
@@ -365,6 +365,7 @@
 	struct ctrl_cmd *cmd;
 	struct ipaccess_head *iph;
 	struct ipaccess_head_ext *iph_ext;
+	int result;
 
 	if (msg->len < sizeof(*iph) + sizeof(*iph_ext)) {
 		LOGP(DLCTRL, LOGL_ERROR, "The message is too short.\n");
@@ -398,28 +399,29 @@
 		cmd->reply = "Command parser error.";
 	}
 
-	if (cmd->type != CTRL_TYPE_ERROR) {
-		cmd->ccon = ccon;
-		if (ctrl_cmd_handle(ctrl, cmd, ctrl->data) == CTRL_CMD_HANDLED) {
+	/* In case of error, reply with the error message right away. */
+	if (cmd->type == CTRL_TYPE_ERROR)
+		goto send_reply;
 
-			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;
-			}
+	cmd->ccon = ccon;
+	result = ctrl_cmd_handle(ctrl, cmd, ctrl->data);
 
-			/* On CTRL_CMD_HANDLED, no reply needs to be sent back. */
-			talloc_free(cmd);
-			cmd = NULL;
-		}
+
+	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;
 	}
 
-	if (cmd) {
-		/* There is a reply or error that should be reported back to the sender. */
-		ctrl_cmd_send(&ccon->write_queue, cmd);
-		talloc_free(cmd);
-	}
+	/* On CTRL_CMD_HANDLED, no reply needs to be sent back. */
+	if (result == CTRL_CMD_HANDLED)
+		goto just_free;
 
+send_reply:
+	/* There is a reply or error that should be reported back to the sender. */
+	ctrl_cmd_send(&ccon->write_queue, cmd);
+just_free:
+	talloc_free(cmd);
 	return 0;
 }
 

-- 
To view, visit https://gerrit.osmocom.org/7619
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3a711f5c974b7f56e27b333d390d1a706fb57007
Gerrit-PatchSet: 3
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list