You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.8 KiB

  1. From 07e522cd7e223517389582a8eb647a4a6a8a5cf8 Mon Sep 17 00:00:00 2001
  2. From: Yousong Zhou <yszhou4tech@gmail.com>
  3. Date: Thu, 30 Apr 2015 13:53:11 +0800
  4. Subject: [PATCH 203/210] xl2tpd-control: cleaup result file atexit().
  5. ---
  6. xl2tpd-control.c | 21 ++++++++++++++-------
  7. 1 file changed, 14 insertions(+), 7 deletions(-)
  8. diff --git a/xl2tpd-control.c b/xl2tpd-control.c
  9. index 973ee87..abc0324 100644
  10. --- a/xl2tpd-control.c
  11. +++ b/xl2tpd-control.c
  12. @@ -12,6 +12,7 @@
  13. #define _GNU_SOURCE
  14. +#include <stdlib.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <stdarg.h>
  18. @@ -35,6 +36,9 @@
  19. #define TUNNEL_REQUIRED 1
  20. #define TUNNEL_NOT_REQUIRED 0
  21. +char result_filename[128];
  22. +int result_fd = -1;
  23. +
  24. int log_level = ERROR_LEVEL;
  25. void print_error (int level, const char *fmt, ...);
  26. @@ -117,6 +121,14 @@ void help()
  27. );
  28. }
  29. +void cleanup(void)
  30. +{
  31. + /* cleaning up */
  32. + if (result_fd >= 0)
  33. + close (result_fd);
  34. + unlink (result_filename);
  35. +}
  36. +
  37. int main (int argc, char *argv[])
  38. {
  39. char* control_filename = NULL;
  40. @@ -195,11 +207,11 @@ int main (int argc, char *argv[])
  41. FILE* mesf = fmemopen (buf, CONTROL_PIPE_MESSAGE_SIZE, "w");
  42. /* create result pipe for reading */
  43. - char result_filename[128];
  44. snprintf (result_filename, 128, RESULT_FILENAME_FORMAT, getpid());
  45. unlink (result_filename);
  46. mkfifo (result_filename, 0600);
  47. - int result_fd = open (result_filename, O_RDONLY | O_NONBLOCK, 0600);
  48. + atexit(cleanup);
  49. + result_fd = open (result_filename, O_RDONLY | O_NONBLOCK, 0600);
  50. if (result_fd < 0)
  51. {
  52. print_error (ERROR_LEVEL,
  53. @@ -293,11 +305,6 @@ int main (int argc, char *argv[])
  54. );
  55. printf ("%s", rbuf);
  56. - /* cleaning up */
  57. -
  58. - close (result_fd);
  59. - unlink (result_filename);
  60. -
  61. return command_result_code;
  62. }
  63. --
  64. 1.7.10.4