[PATCH 05/16] lslogins: reject unknown time format arguments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 login-utils/lslogins.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c
index cacf83c..4b07636 100644
--- a/login-utils/lslogins.c
+++ b/login-utils/lslogins.c
@@ -1180,16 +1180,6 @@ static void free_user(void *f)
 	free(u);
 }
 
-struct lslogins_timefmt {
-	const char *name;
-	int val;
-};
-
-static struct lslogins_timefmt timefmts[] = {
-	{ "short", TIME_SHORT },
-	{ "full", TIME_FULL },
-	{ "iso", TIME_ISO },
-};
 
 static void __attribute__((__noreturn__)) usage(FILE *out)
 {
@@ -1398,8 +1388,18 @@ int main(int argc, char *argv[])
 			break;
 		case OPT_TIME_FMT:
 			{
+				struct lslogins_timefmt {
+					const char *name;
+					const int val;
+				};
+				const struct lslogins_timefmt timefmts[] = {
+					{ "iso", TIME_ISO },
+					{ "full", TIME_FULL },
+					{ "short", TIME_SHORT },
+				};
 				size_t i;
 
+				ctl->time_mode = TIME_INVALID;
 				for (i = 0; i < ARRAY_SIZE(timefmts); i++) {
 					if (strcmp(timefmts[i].name, optarg) == 0) {
 						ctl->time_mode = timefmts[i].val;
@@ -1407,7 +1407,7 @@ int main(int argc, char *argv[])
 					}
 				}
 				if (ctl->time_mode == TIME_INVALID)
-					usage(stderr);
+					errx(EXIT_FAILURE, _("unknown time format: %s"), optarg);
 			}
 			break;
 		case 'V':
-- 
2.1.3

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux