Module: kamailio
Branch: master
Commit: 8f3d76e9808024bff1d816acddeb81667e1df0d2
URL:
https://github.com/kamailio/kamailio/commit/8f3d76e9808024bff1d816acddeb816…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-10-09T13:51:47+02:00
corex: rpc command to print shm status report to file based on filter
---
Modified: src/modules/corex/corex_rpc_shm.c
---
Diff:
https://github.com/kamailio/kamailio/commit/8f3d76e9808024bff1d816acddeb816…
Patch:
https://github.com/kamailio/kamailio/commit/8f3d76e9808024bff1d816acddeb816…
---
diff --git a/src/modules/corex/corex_rpc_shm.c b/src/modules/corex/corex_rpc_shm.c
index 6230f1b129d..02fa08f8a36 100644
--- a/src/modules/corex/corex_rpc_shm.c
+++ b/src/modules/corex/corex_rpc_shm.c
@@ -115,13 +115,41 @@ static void corex_rpc_shm_report(rpc_t *rpc, void *ctx)
mrep.min_used_frag_line);
}
+/*clang-format off*/
+static const char *corex_rpc_shm_rprint_doc[2] = {
+ "Print shm status report to file matching the filter", 0};
+/*clang-format on*/
+
+/*
+ * RPC command to print the shm status report
+ */
+static void corex_rpc_shm_rprint(rpc_t *rpc, void *ctx)
+{
+ char *fname = NULL;
+ str fmatch = STR_NULL;
+ FILE *fp = NULL;
+
+ if(rpc->scan(ctx, "ss", &fname, &fmatch) < 2) {
+ rpc->fault(ctx, 400, "Filename and filter not provided");
+ return;
+ }
+ fp = fopen(fname, "w");
+ if(fp == NULL) {
+ LM_ERR("cannot open file: %s\n", fname);
+ rpc->fault(ctx, 500, "Cannot open file");
+ return;
+ }
+ shm_status_filter(&fmatch, fp);
+ fclose(fp);
+}
+
/*clang-format off*/
rpc_export_t corex_rpc_shm_cmds[] = {
- {"shm.info", corex_rpc_shm_info, corex_rpc_shm_info_doc, 0},
- {"shm.report", corex_rpc_shm_report, corex_rpc_shm_report_doc, 0},
- {"shm.stats", corex_rpc_shm_stats, corex_rpc_shm_stats_doc, 0},
- {0, 0, 0, 0}
-};
+ {"shm.info", corex_rpc_shm_info, corex_rpc_shm_info_doc, 0},
+ {"shm.report", corex_rpc_shm_report, corex_rpc_shm_report_doc, 0},
+ {"shm.stats", corex_rpc_shm_stats, corex_rpc_shm_stats_doc, 0},
+ {"shm.rprint", corex_rpc_shm_rprint, corex_rpc_shm_rprint_doc, 0},
+ {0, 0, 0, 0}};
/*clang-format on*/
/**