From a6a102ec4c8d96fcfb968c88fbdae80f6142c7bf Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 17 Jul 2023 09:36:17 +0200 Subject: getfattr: fix "getfattr NOTEXIST" - now prints error msg function old new delta getfattr_main 309 307 -2 .rodata 105395 105391 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-6) Total: -6 bytes Signed-off-by: Denys Vlasenko --- miscutils/getfattr.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/miscutils/getfattr.c b/miscutils/getfattr.c index 59b6f6bca..905aec65f 100644 --- a/miscutils/getfattr.c +++ b/miscutils/getfattr.c @@ -31,6 +31,7 @@ enum { OPT_h = (1 << 0), OPT_d = (1 << 1), + OPT_n = (1 << 2), }; static int print_attr(const char *file, const char *name, char **buf, size_t *bufsize) @@ -85,8 +86,9 @@ int getfattr_main(int argc UNUSED_PARAM, char **argv) opt = getopt32(argv, "^" "hdn:" - /* Min one arg; exactly one of -n or -d is required. */ - "\0" "-1:d:n:n--d:d--n" + /* Min one arg; -d and -n are exclusive */ + "\0" "-1:n--d:d--n" + //getfattr 2.5.1 does not enforce this: ":d:n" /* exactly one of -n or -d is required */ , &name ); argv += optind; @@ -94,8 +96,11 @@ int getfattr_main(int argc UNUSED_PARAM, char **argv) do { int r; - if (opt & OPT_d) { +//getfattr 2.5.1 with no -n/-d defaults to -d + if (!(opt & OPT_n)) { ssize_t len = list_attr(*argv, &list, &listsize); + if (len < 0) + goto err; if (len > 0) { char *key; printf("# file: %s\n", *argv); @@ -118,7 +123,7 @@ int getfattr_main(int argc UNUSED_PARAM, char **argv) err: bb_simple_perror_msg(*argv); status = EXIT_FAILURE; - // continue; maybe? + continue; } bb_putchar('\n'); } -- cgit v1.2.3