[Asterisk-code-review] asterisk.c: Warn of incompatibilities with remote console. (asterisk[19])

Joshua Colp asteriskteam at digium.com
Wed Apr 27 12:39:04 CDT 2022


Joshua Colp has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/18475 )

Change subject: asterisk.c: Warn of incompatibilities with remote console.
......................................................................

asterisk.c: Warn of incompatibilities with remote console.

Some command line options to Asterisk only apply when Asterisk
is started and cannot be used with remote console mode. If a
user tries to use any of these, they are currently simply
silently ignored.

This prints out a warning if incompatible options are used,
informing users that an option used cannot be used with remote
console mode. Additionally, some clarifications are added to
the help text and man page.

ASTERISK-22246
ASTERISK-26582

Change-Id: I980a5380ef2c19e8ea348596396d5382893c4337
---
M doc/asterisk.8
M main/asterisk.c
2 files changed, 54 insertions(+), 3 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
  Benjamin Keith Ford: Looks good to me, approved



diff --git a/doc/asterisk.8 b/doc/asterisk.8
index e5991d9..50ad8f6 100644
--- a/doc/asterisk.8
+++ b/doc/asterisk.8
@@ -158,6 +158,7 @@
 .TP
 \-n
 Disable ANSI colors even on terminals capable of displaying them.
+This option can be used only at startup (e.g. not with remote console).
 .TP
 \-p
 If supported by the operating system (and executing as root),
@@ -195,7 +196,8 @@
 .TP
 \-T
 Add timestamp to all non-command related output going to the console
-when running with verbose and/or logging to the console.
+when running with verbose and/or logging to the console. Can only be
+used at startup (e.g. not with remote console mode).
 .TP
 \-U \fIuser\fR
 Run as user \fIuser\fR instead of the
diff --git a/main/asterisk.c b/main/asterisk.c
index de520a0..b965a4d 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -3351,7 +3351,7 @@
 	printf("   -L <load>       Limit the maximum load average before rejecting new calls\n");
 	printf("   -M <value>      Limit the maximum number of calls to the specified value\n");
 	printf("   -m              Mute debugging and console output on the console\n");
-	printf("   -n              Disable console colorization\n");
+	printf("   -n              Disable console colorization. Can be used only at startup.\n");
 	printf("   -p              Run as pseudo-realtime thread\n");
 	printf("   -q              Quiet mode (suppress output)\n");
 	printf("   -r              Connect to Asterisk on this machine\n");
@@ -3360,7 +3360,7 @@
 	printf("   -t              Record soundfiles in /var/tmp and move them where they\n");
 	printf("                   belong after they are done\n");
 	printf("   -T              Display the time in [Mmm dd hh:mm:ss] format for each line\n");
-	printf("                   of output to the CLI\n");
+	printf("                   of output to the CLI. Cannot be used with remote console mode.\n\n");
 	printf("   -v              Increase verbosity (multiple v's = more verbose)\n");
 	printf("   -x <cmd>        Execute command <cmd> (implies -r)\n");
 	printf("   -X              Enable use of #exec in asterisk.conf\n");
@@ -3716,6 +3716,55 @@
 		}
 	}
 
+	if (ast_opt_remote) {
+		int didwarn = 0;
+		optind = 1;
+
+		/* Not all options can be used with remote console. Warn if they're used. */
+		while ((c = getopt(argc, argv, getopt_settings)) != -1) {
+			switch (c) {
+			/* okay to run with remote console */
+			case 'B': /* force black background */
+			case 'd': /* debug */
+			case 'h': /* help */
+			case 'I': /* obsolete timing option: warning already thrown if used */
+			case 'L': /* max load */
+			case 'M': /* max calls */
+			case 'R': /* reconnect */
+			case 'r': /* remote */
+			case 's': /* set socket path */
+			case 'V': /* version */
+			case 'v': /* verbose */
+			case 'W': /* white background */
+			case 'x': /* remote execute */
+			case '?': /* ? */
+				break;
+			/* can only be run when Asterisk is starting */
+			case 'X': /* enables #exec for asterisk.conf only. */
+			case 'C': /* set config path */
+			case 'c': /* foreground console */
+			case 'e': /* minimum memory free */
+			case 'F': /* always fork */
+			case 'f': /* no fork */
+			case 'G': /* run group */
+			case 'g': /* dump core */
+			case 'i': /* init keys */
+			case 'm': /* mute */
+			case 'n': /* no color */
+			case 'p': /* high priority */
+			case 'q': /* quiet */
+			case 'T': /* timestamp */
+			case 't': /* cache record files */
+			case 'U': /* run user */
+				fprintf(stderr, "'%c' option is not compatible with remote console mode and has no effect.\n", c);
+				didwarn = 1;
+			}
+		}
+		if (didwarn) {
+			fprintf(stderr, "\n"); /* if any warnings print out, make them stand out */
+		}
+	}
+
 	/* For remote connections, change the name of the remote connection.
 	 * We do this for the benefit of init scripts (which need to know if/when
 	 * the main asterisk process has died yet). */

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18475
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 19
Gerrit-Change-Id: I980a5380ef2c19e8ea348596396d5382893c4337
Gerrit-Change-Number: 18475
Gerrit-PatchSet: 2
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220427/b2a01fab/attachment.html>


More information about the asterisk-code-review mailing list