Browse code

corex: added rpc command shm.info

Daniel-Constantin Mierla authored on 17/09/2020 11:19:13
Showing 3 changed files
... ...
@@ -39,6 +39,7 @@
39 39
 
40 40
 #include "corex_lib.h"
41 41
 #include "corex_rpc.h"
42
+#include "corex_rpc_shm.h"
42 43
 #include "corex_var.h"
43 44
 #include "corex_nio.h"
44 45
 
... ...
@@ -188,6 +189,12 @@ static int mod_init(void)
188 189
 		return -1;
189 190
 	}
190 191
 
192
+	if(corex_init_rpc_shm()<0)
193
+	{
194
+		LM_ERR("failed to register RPC shm commands\n");
195
+		return -1;
196
+	}
197
+
191 198
 	if(corex_register_check_self()<0)
192 199
 	{
193 200
 		LM_ERR("failed to register check self callback\n");
194 201
new file mode 100644
... ...
@@ -0,0 +1,72 @@
1
+/**
2
+ * Copyright (C) 2020 Daniel-Constantin Mierla (asipto.com)
3
+ *
4
+ * This file is part of Kamailio, a free SIP server.
5
+ *
6
+ * Permission to use, copy, modify, and distribute this software for any
7
+ * purpose with or without fee is hereby granted, provided that the above
8
+ * copyright notice and this permission notice appear in all copies.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ *
18
+ */
19
+
20
+#include <stdio.h>
21
+#include <unistd.h>
22
+#include <stdlib.h>
23
+#include <string.h>
24
+
25
+#include "../../core/dprint.h"
26
+#include "../../core/ut.h"
27
+#include "../../core/mem/shm.h"
28
+#include "../../core/globals.h"
29
+#include "../../core/rpc.h"
30
+#include "../../core/rpc_lookup.h"
31
+
32
+static const char* corex_rpc_shm_info_doc[2] = {
33
+	"Return details of the shared memory manager",
34
+	0
35
+};
36
+
37
+
38
+/*
39
+ * RPC command to list the listening sockets
40
+ */
41
+static void corex_rpc_shm_info(rpc_t* rpc, void* ctx)
42
+{
43
+	void* th;
44
+
45
+	if (rpc->add(ctx, "{", &th) < 0) {
46
+		rpc->fault(ctx, 500, "Internal error creating rpc");
47
+		return;
48
+	}
49
+	if(rpc->struct_add(th, "su",
50
+			"name", (_shm_root.mname)?_shm_root.mname:"unknown",
51
+			"size", (unsigned int)shm_mem_size) <0) {
52
+		rpc->fault(ctx, 500, "Internal error adding fields");
53
+		return;
54
+	}
55
+}
56
+
57
+rpc_export_t corex_rpc_shm_cmds[] = {
58
+	{"shm.info", corex_rpc_shm_info, corex_rpc_shm_info_doc, 0},
59
+	{0, 0, 0, 0}
60
+};
61
+
62
+/**
63
+ * register RPC shm commands
64
+ */
65
+int corex_init_rpc_shm(void)
66
+{
67
+	if (rpc_register_array(corex_rpc_shm_cmds)!=0) {
68
+		LM_ERR("failed to register RPC shm commands\n");
69
+		return -1;
70
+	}
71
+	return 0;
72
+}
0 73
new file mode 100644
... ...
@@ -0,0 +1,25 @@
1
+/**
2
+ * Copyright (C) 2020 Daniel-Constantin Mierla (asipto.com)
3
+ *
4
+ * This file is part of Kamailio, a free SIP server.
5
+ *
6
+ * Permission to use, copy, modify, and distribute this software for any
7
+ * purpose with or without fee is hereby granted, provided that the above
8
+ * copyright notice and this permission notice appear in all copies.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ *
18
+ */
19
+
20
+#ifndef _COREX_RPC_SHM_H_
21
+#define _COREX_RPC_SHM_H_
22
+
23
+int corex_init_rpc_shm(void);
24
+
25
+#endif