[Asterisk-code-review] cli: Add core dump info to core show settings (asterisk[master])

N A asteriskteam at digium.com
Thu Jan 13 19:38:50 CST 2022


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/17868 )


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, 19 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/68/17868/1

diff --git a/main/asterisk.c b/main/asterisk.c
index eaf2d7d..2eb89b2 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -454,6 +454,7 @@
 	char eid_str[128];
 	struct rlimit limits;
 	char pbx_uuid[AST_UUID_STR_LEN];
+	char dir[PATH_MAX];
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -491,6 +492,7 @@
 	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");
 	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 +512,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)) || eaccess(dir, R_OK | X_OK | F_OK)) {
+		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");
@@ -2702,7 +2718,7 @@
 
 			/* Write over the CLI prompt */
 			if (!ast_opt_exec && !lastpos) {
-				if (write(STDOUT_FILENO, "\r", 5) < 0) {
+				if (write(STDOUT_FILENO, "\r[0K", 5) < 0) {
 				}
 			}
 
@@ -3862,8 +3878,10 @@
 	{
 #if defined(HAVE_EACCESS) || defined(HAVE_EUIDACCESS)
 #if defined(HAVE_EUIDACCESS) && !defined(HAVE_EACCESS)
+#ifndef eaccess
 #define eaccess euidaccess
 #endif
+#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/+/17868
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ic42c0a9ecc233381aad274d86c62808d1ebb4d83
Gerrit-Change-Number: 17868
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220113/8934714d/attachment.html>


More information about the asterisk-code-review mailing list