Change in osmocom-bb[master]: mobile: abort in case of argv handling errors

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Wed Nov 21 03:44:14 UTC 2018


Vadim Yanitskiy has uploaded this change for review. ( https://gerrit.osmocom.org/11851


Change subject: mobile: abort in case of argv handling errors
......................................................................

mobile: abort in case of argv handling errors

The process should be aborted if a non-existing command line
option or an incorrect parameter value is passed.

Change-Id: Ib656ad12f12429ed15dc2a1554901ffa51148ff6
---
M src/host/layer23/src/mobile/main.c
1 file changed, 10 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/51/11851/1

diff --git a/src/host/layer23/src/mobile/main.c b/src/host/layer23/src/mobile/main.c
index 115ac41..e015c30 100644
--- a/src/host/layer23/src/mobile/main.c
+++ b/src/host/layer23/src/mobile/main.c
@@ -99,7 +99,7 @@
 		"offer socket\n");
 }
 
-static void handle_options(int argc, char **argv)
+static int handle_options(int argc, char **argv)
 {
 	while (1) {
 		int option_index = 0, c;
@@ -148,9 +148,12 @@
 			use_mncc_sock = 1;
 			break;
 		default:
-			break;
+			/* Unknown parameter passed */
+			return -EINVAL;
 		}
 	}
+
+	return 0;
 }
 
 void sighandler(int sigset)
@@ -218,7 +221,11 @@
 	/* Init default stderr logging */
 	osmo_init_logging2(l23_ctx, &log_info);
 
-	handle_options(argc, argv);
+	rc = handle_options(argc, argv);
+	if (rc) { /* Abort in case of parsing errors */
+		fprintf(stderr, "Error in command line options. Exiting.\n");
+		return 1;
+	}
 
 	if (gsmtap_ip) {
 		gsmtap_inst = gsmtap_source_init(gsmtap_ip, GSMTAP_UDP_PORT, 1);

-- 
To view, visit https://gerrit.osmocom.org/11851
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib656ad12f12429ed15dc2a1554901ffa51148ff6
Gerrit-Change-Number: 11851
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181121/7635aa6a/attachment.html>


More information about the gerrit-log mailing list