aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew G. Morgan <morgan@kernel.org>2016-01-30 16:25:21 -0800
committerAndrew G. Morgan <morgan@kernel.org>2016-01-30 16:25:21 -0800
commit1bebacbdb4da0734ae51ed408170cc69fa5290eb (patch)
tree1d742282231bf8dc681b2363b78b46427b9a5629
parentebcbf9f99fb1a8b18422ecef8b13076b254c5cad (diff)
downloadlibcap-1bebacbdb4da0734ae51ed408170cc69fa5290eb.tar.gz
setcap: fix errno display
The commit 056ffb0bd25d91ffbcb83c521fc4d3d9904ec4d4 broke the display of the final error message because it would do more operations that would clobber errno. Example: (libcap-2.22) sudo setcap cap_ipc_lock=ep /proc/filesystems | head -1 Failed to set capabilities on file `/proc/filesystems' (Operation not supported) (libcap-2.23) sudo setcap cap_ipc_lock=ep /proc/filesystems | head -1 Failed to set capabilities on file `/proc/filesystems' (Invalid argument) Save the original errno value and use that for the final display instead. URL: https://bugs.gentoo.org/551672 Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
-rw-r--r--progs/setcap.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/progs/setcap.c b/progs/setcap.c
index 83090ae..7304343 100644
--- a/progs/setcap.c
+++ b/progs/setcap.c
@@ -171,6 +171,7 @@ int main(int argc, char **argv)
retval = cap_set_file(*++argv, cap_d);
if (retval != 0) {
int explained = 0;
+ int oerrno = errno;
#ifdef linux
cap_value_t cap;
cap_flag_value_t per_state;
@@ -193,7 +194,7 @@ int main(int argc, char **argv)
fprintf(stderr,
"Failed to set capabilities on file `%s' (%s)\n",
- argv[0], strerror(errno));
+ argv[0], strerror(oerrno));
if (!explained) {
usage();
}