[Asterisk-code-review] cli: Add core dump info to core show settings. (asterisk[19])
Friendly Automation
asteriskteam at digium.com
Wed Feb 23 13:38:16 CST 2022
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/18043 )
Change subject: cli: Add core dump info to core show settings.
......................................................................
cli: Add core dump info to core show settings.
Adds two pieces of information to the core show settings command
which are useful in the context of getting backtraces.
The first is to display whether or not Asterisk would generate
a core dump if it were to crash.
The second is to show the current running directory of Asterisk.
ASTERISK-29866 #close
Change-Id: Ic42c0a9ecc233381aad274d86c62808d1ebb4d83
---
M main/asterisk.c
1 file changed, 36 insertions(+), 3 deletions(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Friendly Automation: Approved for Submit
diff --git a/main/asterisk.c b/main/asterisk.c
index 4520318..de520a0 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -446,6 +446,23 @@
}
}
+/*! \brief Print the contents of a file */
+static int print_file(int fd, char *desc, const char *filename)
+{
+ FILE *f;
+ char c;
+ if (!(f = fopen(filename, "r"))) {
+ return -1;
+ }
+ ast_cli(fd, "%s", desc);
+ while ((c = fgetc(f)) != EOF) {
+ ast_cli(fd, "%c", c);
+ }
+ fclose(f);
+ /* no need for trailing new line, the file already has one */
+ return 0;
+}
+
/*! \brief Give an overview of core settings */
static char *handle_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
@@ -454,6 +471,9 @@
char eid_str[128];
struct rlimit limits;
char pbx_uuid[AST_UUID_STR_LEN];
+#if defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS)
+ char dir[PATH_MAX];
+#endif
switch (cmd) {
case CLI_INIT:
@@ -491,6 +511,8 @@
ast_cli(a->fd, " Current console verbosity: %d\n", ast_verb_console_get());
ast_cli(a->fd, " Debug level: %d\n", option_debug);
ast_cli(a->fd, " Trace level: %d\n", option_trace);
+ ast_cli(a->fd, " Dump core on crash: %s\n", ast_opt_dump_core ? "Yes" : "No");
+ print_file(a->fd, " Core dump file: ", "/proc/sys/kernel/core_pattern");
ast_cli(a->fd, " Maximum load average: %lf\n", ast_option_maxload);
#if defined(HAVE_SYSINFO)
ast_cli(a->fd, " Minimum free memory: %ld MB\n", option_minmemfree);
@@ -510,6 +532,20 @@
ast_cli(a->fd, " Default language: %s\n", ast_defaultlanguage);
ast_cli(a->fd, " Language prefix: %s\n", ast_language_is_prefix ? "Enabled" : "Disabled");
ast_cli(a->fd, " User name and group: %s/%s\n", ast_config_AST_RUN_USER, ast_config_AST_RUN_GROUP);
+#if defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS)
+#if defined(HAVE_EUIDACCESS) && !defined(HAVE_EACCESS)
+#define eaccess euidaccess
+#endif
+ if (!getcwd(dir, sizeof(dir))) {
+ if (eaccess(dir, R_OK | X_OK | F_OK)) {
+ ast_cli(a->fd, " Running directory: %s\n", "Unable to access");
+ } else {
+ ast_cli(a->fd, " Running directory: %s (%s)\n", dir, "Unable to access");
+ }
+ } else {
+ ast_cli(a->fd, " Running directory: %s\n", dir);
+ }
+#endif /* defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS) */
ast_cli(a->fd, " Executable includes: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_EXEC_INCLUDES) ? "Enabled" : "Disabled");
ast_cli(a->fd, " Transcode via SLIN: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSCODE_VIA_SLIN) ? "Enabled" : "Disabled");
ast_cli(a->fd, " Transmit silence during rec: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSMIT_SILENCE) ? "Enabled" : "Disabled");
@@ -3861,9 +3897,6 @@
{
#if defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS)
-#if defined(HAVE_EUIDACCESS) && !defined(HAVE_EACCESS)
-#define eaccess euidaccess
-#endif
char dir[PATH_MAX];
if (!getcwd(dir, sizeof(dir)) || eaccess(dir, R_OK | X_OK | F_OK)) {
fprintf(stderr, "Unable to access the running directory (%s). Changing to '/' for compatibility.\n", strerror(errno));
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18043
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 19
Gerrit-Change-Id: Ic42c0a9ecc233381aad274d86c62808d1ebb4d83
Gerrit-Change-Number: 18043
Gerrit-PatchSet: 2
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220223/17c8e3eb/attachment-0001.html>
More information about the asterisk-code-review
mailing list