libcap-2.24-setcap-errno.patch 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. From 62b190c09d5652c58679dffd7f09e4aceb4c7daa Mon Sep 17 00:00:00 2001
  2. From: Mike Frysinger <vapier@gentoo.org>
  3. Date: Mon, 13 Jul 2015 01:59:14 -0400
  4. Subject: [PATCH] setcap: fix errno display
  5. The commit 056ffb0bd25d91ffbcb83c521fc4d3d9904ec4d4 broke the display of
  6. the final error message because it would do more operations that would
  7. clobber errno. Example:
  8. (libcap-2.22) sudo setcap cap_ipc_lock=ep /proc/filesystems | head -1
  9. Failed to set capabilities on file `/proc/filesystems' (Operation not supported)
  10. (libcap-2.23) sudo setcap cap_ipc_lock=ep /proc/filesystems | head -1
  11. Failed to set capabilities on file `/proc/filesystems' (Invalid argument)
  12. Save the original errno value and use that for the final display instead.
  13. URL: https://bugs.gentoo.org/551672
  14. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
  15. ---
  16. progs/setcap.c | 3 ++-
  17. 1 file changed, 2 insertions(+), 1 deletion(-)
  18. diff --git a/progs/setcap.c b/progs/setcap.c
  19. index 83090ae..7304343 100644
  20. --- a/progs/setcap.c
  21. +++ b/progs/setcap.c
  22. @@ -171,6 +171,7 @@ int main(int argc, char **argv)
  23. retval = cap_set_file(*++argv, cap_d);
  24. if (retval != 0) {
  25. int explained = 0;
  26. + int oerrno = errno;
  27. #ifdef linux
  28. cap_value_t cap;
  29. cap_flag_value_t per_state;
  30. @@ -193,7 +194,7 @@ int main(int argc, char **argv)
  31. fprintf(stderr,
  32. "Failed to set capabilities on file `%s' (%s)\n",
  33. - argv[0], strerror(errno));
  34. + argv[0], strerror(oerrno));
  35. if (!explained) {
  36. usage();
  37. }
  38. --
  39. 2.4.4