[sr-dev] git:master:f1278a20: corex: added rpc command shm.info

Daniel-Constantin Mierla miconda at gmail.com
Thu Sep 17 13:22:31 CEST 2020


Module: kamailio
Branch: master
Commit: f1278a20bb37b29285c9d7cac298a3b1905f1c88
URL: https://github.com/kamailio/kamailio/commit/f1278a20bb37b29285c9d7cac298a3b1905f1c88

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2020-09-17T13:19:13+02:00

corex: added rpc command shm.info

---

Added: src/modules/corex/corex_rpc_shm.c
Added: src/modules/corex/corex_rpc_shm.h
Modified: src/modules/corex/corex_mod.c

---

Diff:  https://github.com/kamailio/kamailio/commit/f1278a20bb37b29285c9d7cac298a3b1905f1c88.diff
Patch: https://github.com/kamailio/kamailio/commit/f1278a20bb37b29285c9d7cac298a3b1905f1c88.patch

---

diff --git a/src/modules/corex/corex_mod.c b/src/modules/corex/corex_mod.c
index 8d0e649548..194efcdb8e 100644
--- a/src/modules/corex/corex_mod.c
+++ b/src/modules/corex/corex_mod.c
@@ -39,6 +39,7 @@
 
 #include "corex_lib.h"
 #include "corex_rpc.h"
+#include "corex_rpc_shm.h"
 #include "corex_var.h"
 #include "corex_nio.h"
 
@@ -188,6 +189,12 @@ static int mod_init(void)
 		return -1;
 	}
 
+	if(corex_init_rpc_shm()<0)
+	{
+		LM_ERR("failed to register RPC shm commands\n");
+		return -1;
+	}
+
 	if(corex_register_check_self()<0)
 	{
 		LM_ERR("failed to register check self callback\n");
diff --git a/src/modules/corex/corex_rpc_shm.c b/src/modules/corex/corex_rpc_shm.c
new file mode 100644
index 0000000000..5316cdc7bc
--- /dev/null
+++ b/src/modules/corex/corex_rpc_shm.c
@@ -0,0 +1,72 @@
+/**
+ * Copyright (C) 2020 Daniel-Constantin Mierla (asipto.com)
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../../core/dprint.h"
+#include "../../core/ut.h"
+#include "../../core/mem/shm.h"
+#include "../../core/globals.h"
+#include "../../core/rpc.h"
+#include "../../core/rpc_lookup.h"
+
+static const char* corex_rpc_shm_info_doc[2] = {
+	"Return details of the shared memory manager",
+	0
+};
+
+
+/*
+ * RPC command to list the listening sockets
+ */
+static void corex_rpc_shm_info(rpc_t* rpc, void* ctx)
+{
+	void* th;
+
+	if (rpc->add(ctx, "{", &th) < 0) {
+		rpc->fault(ctx, 500, "Internal error creating rpc");
+		return;
+	}
+	if(rpc->struct_add(th, "su",
+			"name", (_shm_root.mname)?_shm_root.mname:"unknown",
+			"size", (unsigned int)shm_mem_size) <0) {
+		rpc->fault(ctx, 500, "Internal error adding fields");
+		return;
+	}
+}
+
+rpc_export_t corex_rpc_shm_cmds[] = {
+	{"shm.info", corex_rpc_shm_info, corex_rpc_shm_info_doc, 0},
+	{0, 0, 0, 0}
+};
+
+/**
+ * register RPC shm commands
+ */
+int corex_init_rpc_shm(void)
+{
+	if (rpc_register_array(corex_rpc_shm_cmds)!=0) {
+		LM_ERR("failed to register RPC shm commands\n");
+		return -1;
+	}
+	return 0;
+}
diff --git a/src/modules/corex/corex_rpc_shm.h b/src/modules/corex/corex_rpc_shm.h
new file mode 100644
index 0000000000..392dcafc08
--- /dev/null
+++ b/src/modules/corex/corex_rpc_shm.h
@@ -0,0 +1,25 @@
+/**
+ * Copyright (C) 2020 Daniel-Constantin Mierla (asipto.com)
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#ifndef _COREX_RPC_SHM_H_
+#define _COREX_RPC_SHM_H_
+
+int corex_init_rpc_shm(void);
+
+#endif




More information about the sr-dev mailing list