From 6d58636daa5dd9d7b6d1ea7017d4966a04e04318 Mon Sep 17 00:00:00 2001 From: corinna Date: Wed, 11 Nov 2009 10:12:34 +0000 Subject: [PATCH] * getfacl.c (print_version): Fix copyright. (main): Don't reuse local variables confusingly. Don't print any file information if acl() fails. Improve error message. Always print a trailing empty line. Set return code to 2 if accessing some file fails. --- winsup/utils/ChangeLog | 7 +++++++ winsup/utils/getfacl.c | 34 ++++++++++++++++------------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog index e019dfb415..20a78bca64 100644 --- a/winsup/utils/ChangeLog +++ b/winsup/utils/ChangeLog @@ -1,3 +1,10 @@ +2009-11-11 Corinna Vinschen + + * getfacl.c (print_version): Fix copyright. + (main): Don't reuse local variables confusingly. Don't print any file + information if acl() fails. Improve error message. Always print a + trailing empty line. Set return code to 2 if accessing some file fails. + 2009-11-04 Corinna Vinschen * path.cc (read_mounts): Skip unnecessary test if path has been diff --git a/winsup/utils/getfacl.c b/winsup/utils/getfacl.c index 0afcd698da..6a5e7be207 100644 --- a/winsup/utils/getfacl.c +++ b/winsup/utils/getfacl.c @@ -1,6 +1,6 @@ /* getfacl.c - Copyright 2000, 2001, 2002 Red Hat Inc. + Copyright 2000, 2001, 2002, 2003, 2004, 2009 Red Hat Inc. Written by Corinna Vinschen @@ -19,6 +19,7 @@ details. */ #include #include #include +#include static const char version[] = "$Revision$"; static char *prog_name; @@ -135,7 +136,7 @@ print_version () printf ("\ getfacl (cygwin) %.*s\n\ ACL Utility\n\ -Copyright (c) 2000, 2001, 2002 Red Hat, Inc.\n\ +Copyright (c) 2000, 2001, 2002, 2003, 2004, 2009 Red Hat, Inc.\n\ Compiled on %s\n\ ", len, v, __DATE__); } @@ -143,11 +144,11 @@ Compiled on %s\n\ int main (int argc, char **argv) { - int c, i; + int c; + int ret = 0; int aopt = 0; int dopt = 0; int nopt = 0; - int first = 1; struct stat st; aclent_t acls[MAX_ACL_ENTRIES]; @@ -186,17 +187,18 @@ main (int argc, char **argv) usage (stderr); return 1; } - while ((c = optind++) < argc) + for (; optind < argc; ++optind) { - if (stat (argv[c], &st)) + int i, num_acls; + if (stat (argv[optind], &st) + || (num_acls = acl (argv[optind], GETACL, MAX_ACL_ENTRIES, acls)) < 0) { - perror (argv[0]); + fprintf (stderr, "%s: %s: %s\n", + prog_name, argv[optind], strerror (errno)); + ret = 2; continue; } - if (!first) - putchar ('\n'); - first = 0; - printf ("# file: %s\n", argv[c]); + printf ("# file: %s\n", argv[optind]); if (nopt) { printf ("# owner: %lu\n", (unsigned long)st.st_uid); @@ -207,12 +209,7 @@ main (int argc, char **argv) printf ("# owner: %s\n", username (st.st_uid)); printf ("# group: %s\n", groupname (st.st_gid)); } - if ((c = acl (argv[c], GETACL, MAX_ACL_ENTRIES, acls)) < 0) - { - perror (argv[0]); - continue; - } - for (i = 0; i < c; ++i) + for (i = 0; i < num_acls; ++i) { if (acls[i].a_type & ACL_DEFAULT) { @@ -251,6 +248,7 @@ main (int argc, char **argv) } printf ("%s\n", permstr (acls[i].a_perm)); } + putchar ('\n'); } - return 0; + return ret; } -- 2.11.0