From: Zhi Li <lizhi1215@gmail.com>
Date: Wed, 20 Jul 2011 09:35:48 +0800
Subject: refine setcap output on errors (Closes: #633075)

The error message of setcap is a little confused. From the error message it is
hard to detect what is wrong. I removed the last 'usage' function call,
because at that code point the 'usage' can not provide any useful information.
Instead, I added a function 'mystrerror' which shall provide more information.

Last-Update: 2014-07-26

--- progs/setcap.c
+++ progs/setcap.c
@@ -22,6 +22,25 @@ static void usage(void)
     exit(1);
 }
 
+static const char * mystrerror(int n)
+{
+  struct my_error {
+    int num;
+    const char *desp;
+  }db[] = {
+    { EINVAL, "The value of the capability argument is not permitted for a file. Or the file is not a regular (non-symlink) file" },
+    { ENODATA, "Are you removing capabilities from a file? That file does not have any capability."},
+    {0, ""}
+  };
+
+  struct my_error *p = &db[0];
+  while (p->num) {
+    if ( n == p->num ) return p->desp;
+    p++;
+  }
+  return "";
+}
+
 #define MAXCAP  2048
 
 static int read_caps(int quiet, const char *filename, char *buffer)
@@ -195,7 +214,8 @@ int main(int argc, char **argv)
 			"Failed to set capabilities on file `%s' (%s)\n",
 			argv[0], strerror(errno));
 		if (!explained) {
-		    usage();
+			fprintf(stderr, "%s\n", mystrerror(errno));
+			exit(1);
 		}
 	    }
 	}
