Change in osmo-sysmon[master]: ctrl: make config structure public

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/.

Max gerrit-no-reply at lists.osmocom.org
Fri Dec 14 15:12:14 UTC 2018


Max has uploaded this change for review. ( https://gerrit.osmocom.org/12316


Change subject: ctrl: make config structure public
......................................................................

ctrl: make config structure public

Moving configuration data from anonymous struct into shared header as a
preparation for ctrl logging improvements in follow-up patches.

Change-Id: I3520e14ca6e1b8e270dbd4b1bf2378fe486991ce
Related: SYS#2655
---
M src/osysmon_ctrl.c
M src/simple_ctrl.h
2 files changed, 26 insertions(+), 19 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-sysmon refs/changes/16/12316/1

diff --git a/src/osysmon_ctrl.c b/src/osysmon_ctrl.c
index 25c2b4c..097e24c 100644
--- a/src/osysmon_ctrl.c
+++ b/src/osysmon_ctrl.c
@@ -38,14 +38,7 @@
 struct ctrl_client {
 	/* links to osysmon.ctrl_clients */
 	struct llist_head list;
-	struct {
-		/* name of this CTRL client */
-		const char *name;
-		/* remote host/IP */
-		const char *remote_host;
-		/* remote CTRL port */
-		uint16_t remote_port;
-	} cfg;
+	struct ctrl_cfg *cfg;
 	struct simple_ctrl_handle *sch;
 	/* list of ctrl_client_get_var objects */
 	struct llist_head get_vars;
@@ -69,7 +62,7 @@
 {
 	struct ctrl_client *cc;
 	llist_for_each_entry(cc, &os->ctrl_clients, list) {
-		if (!strcmp(name, cc->cfg.name))
+		if (!strcmp(name, cc->cfg->name))
 			return cc;
 	}
 	return NULL;
@@ -86,9 +79,14 @@
 	cc = talloc_zero(os, struct ctrl_client);
 	if (!cc)
 		return NULL;
-	cc->cfg.name = talloc_strdup(cc, name);
-	cc->cfg.remote_host = talloc_strdup(cc, host);
-	cc->cfg.remote_port = port;
+
+	cc->cfg = talloc_zero(cc, struct ctrl_cfg);
+	if (!cc->cfg)
+		return NULL;
+
+	cc->cfg->name = talloc_strdup(cc, name);
+	cc->cfg->remote_host = talloc_strdup(cc, host);
+	cc->cfg->remote_port = port;
 	INIT_LLIST_HEAD(&cc->get_vars);
 	llist_add_tail(&cc->list, &os->ctrl_clients);
 	/* FIXME */
@@ -163,10 +161,10 @@
 	struct ctrl_client *cc;
 	cc = ctrl_client_find(g_oss, argv[0]);
 	if (cc) {
-		if ((strcmp(cc->cfg.remote_host, argv[1])) ||
-		    (cc->cfg.remote_port != atoi(argv[2]))) {
+		if ((strcmp(cc->cfg->remote_host, argv[1])) ||
+		    (cc->cfg->remote_port != atoi(argv[2]))) {
 			vty_out(vty, "Client %s has different IP/port, please remove it first%s",
-				cc->cfg.name, VTY_NEWLINE);
+				cc->cfg->name, VTY_NEWLINE);
 			return CMD_WARNING;
 		}
 	} else
@@ -222,8 +220,8 @@
 static void write_one_ctrl_client(struct vty *vty, struct ctrl_client *cc)
 {
 	struct ctrl_client_get_var *ccgv;
-	vty_out(vty, "ctrl-client %s %s %u%s", cc->cfg.name,
-		cc->cfg.remote_host, cc->cfg.remote_port, VTY_NEWLINE);
+	vty_out(vty, "ctrl-client %s %s %u%s", cc->cfg->name,
+		cc->cfg->remote_host, cc->cfg->remote_port, VTY_NEWLINE);
 	llist_for_each_entry(ccgv, &cc->get_vars, list) {
 		vty_out(vty, " get-variable %s%s", ccgv->cfg.name, VTY_NEWLINE);
 		if (ccgv->cfg.display_name)
@@ -266,11 +264,11 @@
 static int ctrl_client_poll(struct ctrl_client *cc, struct value_node *parent)
 {
 	struct ctrl_client_get_var *ccgv;
-	struct value_node *vn_clnt = value_node_add(parent, parent, cc->cfg.name, NULL);
+	struct value_node *vn_clnt = value_node_add(parent, parent, cc->cfg->name, NULL);
 
 	/* attempt to re-connect */
 	if (!cc->sch)
-		cc->sch = simple_ctrl_open(cc, cc->cfg.remote_host, cc->cfg.remote_port, 1000);
+		cc->sch = simple_ctrl_open(cc, cc->cfg->remote_host, cc->cfg->remote_port, 1000);
 	/* abort, if that failed */
 	if (!cc->sch) {
 		return -1;
diff --git a/src/simple_ctrl.h b/src/simple_ctrl.h
index 81a759d..f5aa770 100644
--- a/src/simple_ctrl.h
+++ b/src/simple_ctrl.h
@@ -2,6 +2,15 @@
 
 #include <stdint.h>
 
+struct ctrl_cfg {
+	/* name of this CTRL client */
+	const char *name;
+	/* remote host/IP */
+	const char *remote_host;
+	/* remote CTRL port */
+	uint16_t remote_port;
+};
+
 struct simple_ctrl_handle;
 
 struct simple_ctrl_handle *simple_ctrl_open(void *ctx, const char *host, uint16_t dport,

-- 
To view, visit https://gerrit.osmocom.org/12316
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-sysmon
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3520e14ca6e1b8e270dbd4b1bf2378fe486991ce
Gerrit-Change-Number: 12316
Gerrit-PatchSet: 1
Gerrit-Owner: Max <msuraev at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181214/3d174d4c/attachment.htm>


More information about the gerrit-log mailing list