packages/net/xl2tpd/patches/203-xl2tpd-control-cleaup-result-file-atexit.patch
Yousong Zhou 59f33d2aa7 xl2tpd: refactor for more resilience.
- Use netifd no_proto_task for notifying that xl2tpd does not have a
   protocol task running.
 - Use procd for xl2tpd service management.
 - Refreshed 2xx patches to

    - Prevent leftover regular type control result file.
    - Allow xl2tpd run as foreground process while logging via syslog.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>

 - bumped version
 - removed dependency on `ip` package as routes are setup by netifd
   if iproute2 is actually required, please depend on
   `@(PACKAGE_ip||PACKAGE_ip-full)` instead of `ip`

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2015-05-24 12:18:38 +02:00

75 lines
1.8 KiB
Diff

From 07e522cd7e223517389582a8eb647a4a6a8a5cf8 Mon Sep 17 00:00:00 2001
From: Yousong Zhou <yszhou4tech@gmail.com>
Date: Thu, 30 Apr 2015 13:53:11 +0800
Subject: [PATCH 203/210] xl2tpd-control: cleaup result file atexit().
---
xl2tpd-control.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/xl2tpd-control.c b/xl2tpd-control.c
index 973ee87..abc0324 100644
--- a/xl2tpd-control.c
+++ b/xl2tpd-control.c
@@ -12,6 +12,7 @@
#define _GNU_SOURCE
+#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
@@ -35,6 +36,9 @@
#define TUNNEL_REQUIRED 1
#define TUNNEL_NOT_REQUIRED 0
+char result_filename[128];
+int result_fd = -1;
+
int log_level = ERROR_LEVEL;
void print_error (int level, const char *fmt, ...);
@@ -117,6 +121,14 @@ void help()
);
}
+void cleanup(void)
+{
+ /* cleaning up */
+ if (result_fd >= 0)
+ close (result_fd);
+ unlink (result_filename);
+}
+
int main (int argc, char *argv[])
{
char* control_filename = NULL;
@@ -195,11 +207,11 @@ int main (int argc, char *argv[])
FILE* mesf = fmemopen (buf, CONTROL_PIPE_MESSAGE_SIZE, "w");
/* create result pipe for reading */
- char result_filename[128];
snprintf (result_filename, 128, RESULT_FILENAME_FORMAT, getpid());
unlink (result_filename);
mkfifo (result_filename, 0600);
- int result_fd = open (result_filename, O_RDONLY | O_NONBLOCK, 0600);
+ atexit(cleanup);
+ result_fd = open (result_filename, O_RDONLY | O_NONBLOCK, 0600);
if (result_fd < 0)
{
print_error (ERROR_LEVEL,
@@ -293,11 +305,6 @@ int main (int argc, char *argv[])
);
printf ("%s", rbuf);
- /* cleaning up */
-
- close (result_fd);
- unlink (result_filename);
-
return command_result_code;
}
--
1.7.10.4