From debc8c337b3e7d8c76701991a4566714b78c1846 Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <troglobit@gmail.com>
Date: Mon, 31 Mar 2025 13:22:47 +0200
Subject: [PATCH 15/16] logger: show invalid option arguments if -p and -o
 parsing fail
Organization: Wires

Instead of just showing the usage instructions, include information
about the option and its argument failing.  Useful when debugging
faulty calls to the logger program deep in an operating system.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
---
 src/logger.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/logger.c b/src/logger.c
index 8fcb42a..5bf263f 100644
--- a/src/logger.c
+++ b/src/logger.c
@@ -393,13 +393,17 @@ int main(int argc, char *argv[])
 			break;
 
 		case 'o':
-			if (parse_opts(optarg, &iface, &ttl))
+			if (parse_opts(optarg, &iface, &ttl)) {
+				printf("Invalid option argument '-%c %s'\n", c, optarg);
 				return usage(1);
+			}
 			break;
 
 		case 'p':
-			if (parse_prio(optarg, &facility, &severity))
+			if (parse_prio(optarg, &facility, &severity)) {
+				printf("Invalid option argument '-%c %s'\n", c, optarg);
 				return usage(1);
+			}
 			break;
 
 		case 'P':
@@ -428,8 +432,12 @@ int main(int argc, char *argv[])
 			printf("%s\n", version_info);
 			return 0;
 
-		default:
+		case '?':
 			return usage(0);
+
+		default:
+			printf("Unsupported option '-%c'\n", c);
+			return usage(1);
 		}
 	}
 
-- 
2.43.0

