0001-Drop-on_exit-use-standard-atexit-instead.patch 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. From f6e20c9c6e9b50963caaf5483248d329473a6815 Mon Sep 17 00:00:00 2001
  2. From: Gerrit Renker <Gerrit.Renker@ctl.io>
  3. Date: Mon, 21 Jan 2019 09:23:43 -0700
  4. Subject: [PATCH] Drop on_exit(), use standard atexit() instead
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. `on_exit()` is a GLIBC specific extension and not available in musl and uClibc.
  9. Portable applications should avoid this function, and use the standard
  10. `atexit()` instead.
  11. Backported from:f6e20c9c6e9b50963caaf5483248d329473a6815
  12. Signed-off-by: Jörg Krause <joerg.krause@embedded.rocks>
  13. ---
  14. iw_if.c | 10 ++++++----
  15. iw_if.h | 2 +-
  16. iw_scan.c | 2 +-
  17. 3 files changed, 8 insertions(+), 6 deletions(-)
  18. diff --git a/iw_if.c b/iw_if.c
  19. index c0b0128..d8bacbc 100644
  20. --- a/iw_if.c
  21. +++ b/iw_if.c
  22. @@ -87,11 +87,13 @@ int if_set_down(const char *ifname)
  23. return if_set_up_or_down(ifname, false);
  24. }
  25. -/** Exit handler to restore interface 'down' state on exit via on_exit(3). */
  26. -void if_set_down_on_exit(int rc, void *arg)
  27. +/** Exit handler to restore interface 'down' state on exit via atexit(3). */
  28. +void if_set_down_on_exit(void)
  29. {
  30. - if (if_set_down(arg) < 0) {
  31. - err_msg("unable to restore %s interface state - set down manually", arg);
  32. + const char *ifname = conf_ifname();
  33. +
  34. + if (ifname && if_set_down(ifname) < 0) {
  35. + err_msg("unable to restore %s interface state - set down manually", ifname);
  36. }
  37. }
  38. diff --git a/iw_if.h b/iw_if.h
  39. index 50f5a47..e2199d3 100644
  40. --- a/iw_if.h
  41. +++ b/iw_if.h
  42. @@ -76,7 +76,7 @@ struct if_info {
  43. };
  44. extern bool if_is_up(const char *ifname);
  45. extern int if_set_up(const char *ifname);
  46. -extern void if_set_down_on_exit(int rc, void *arg);
  47. +extern void if_set_down_on_exit(void);
  48. extern void if_getinf(const char *ifname, struct if_info *info);
  49. /**
  50. diff --git a/iw_scan.c b/iw_scan.c
  51. index 18e9e06..e2b3067 100644
  52. --- a/iw_scan.c
  53. +++ b/iw_scan.c
  54. @@ -430,7 +430,7 @@ void *do_scan(void *sr_ptr)
  55. if (if_set_up(conf_ifname()) < 0)
  56. err_sys("Can not bring up interface '%s'", conf_ifname());
  57. - if (on_exit(if_set_down_on_exit, (void *)conf_ifname()) < 0)
  58. + if (atexit(if_set_down_on_exit) < 0)
  59. snprintf(sr->msg, sizeof(sr->msg), "Warning: unable to restore %s down state on exit", conf_ifname());
  60. break;
  61. }
  62. --
  63. 2.20.1