[libbsd 1/9] ipsec-tools: Do not use signals

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Jun 10 06:08:27 UTC 2022


---
 ipsec-tools/src/racoon/privsep.c              | 12 +++++++++-
 .../racoon/rtems-bsd-racoon-session-data.h    |  3 ---
 ipsec-tools/src/racoon/session.c              | 23 +++++++++++--------
 3 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/ipsec-tools/src/racoon/privsep.c b/ipsec-tools/src/racoon/privsep.c
index 8efdae84..914d8a44 100644
--- a/ipsec-tools/src/racoon/privsep.c
+++ b/ipsec-tools/src/racoon/privsep.c
@@ -80,7 +80,9 @@ static int privsep_sock[2] = { -1, -1 };
 static int privsep_recv(int, struct privsep_com_msg **, size_t *);
 static int privsep_send(int, struct privsep_com_msg *, size_t);
 static int safety_check(struct privsep_com_msg *, int i);
+#ifndef __rtems__
 static int port_check(int);
+#endif /* __rtems__ */
 static int unsafe_env(char *const *);
 static int unknown_name(int);
 static int unsafe_path(char *, int);
@@ -321,7 +323,6 @@ privsep_init(void)
 #if defined(__NetBSD__) || defined(__FreeBSD__)
 	setproctitle("[priv]");
 #endif
-#endif /* __rtems__ */
 	
 	/*
 	 * Don't catch any signal
@@ -334,13 +335,16 @@ privsep_init(void)
 	signal(SIGUSR1, SIG_DFL);
 	signal(SIGUSR2, SIG_DFL);
 	signal(SIGCHLD, SIG_DFL);
+#endif /* __rtems__ */
 
 	while (1) {
 		size_t len;
 		struct privsep_com_msg *combuf;
 		struct privsep_com_msg *reply;
 		char *data;
+#ifndef __rtems__
 		size_t *buflen;
+#endif /* __rtems__ */
 		size_t totallen;
 		char *bufs[PRIVSEP_NBUF_MAX];
 		int i;
@@ -1067,7 +1071,9 @@ privsep_getpsk(str, keylen)
 	vchar_t *psk;
 	struct privsep_com_msg *msg;
 	size_t len;
+#ifndef __rtems__
 	int *keylenp;
+#endif /* __rtems__ */
 	char *data;
 
 	if (geteuid() == 0)
@@ -1129,7 +1135,11 @@ privsep_socket(domain, type, protocol)
 	size_t len;
 	char *data;
 	struct socket_args socket_args;
+#ifndef __rtems__
 	int s, saved_errno = 0;
+#else /* __rtems__ */
+	int s;
+#endif /* __rtems__ */
 
 	if (geteuid() == 0)
 		return socket(domain, type, protocol);
diff --git a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h
index cdf8a74d..51b67d2e 100644
--- a/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h
+++ b/ipsec-tools/src/racoon/rtems-bsd-racoon-session-data.h
@@ -5,8 +5,5 @@
 RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set *allocated_active_mask);
 RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static fd_set *allocated_preset_mask);
 RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int nfds);
-RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static int signals[]);
-RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static sig_atomic_t volatile volatile sigreq[]);
 RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor *allocated_fd_monitors);
 RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct fd_monitor_list fd_monitor_tree[]);
-RTEMS_LINKER_RWSET_CONTENT(bsd_prog_racoon, static struct sched scflushsa);
diff --git a/ipsec-tools/src/racoon/session.c b/ipsec-tools/src/racoon/session.c
index 90120c76..7ea857ba 100644
--- a/ipsec-tools/src/racoon/session.c
+++ b/ipsec-tools/src/racoon/session.c
@@ -119,6 +119,7 @@ struct fd_monitor {
 
 #define NUM_PRIORITIES 2
 
+#ifndef __rtems__
 static void close_session __P((void));
 static void initfds __P((void));
 static void init_signal __P((void));
@@ -126,6 +127,7 @@ static int set_signal __P((int sig, RETSIGTYPE (*func) __P((int))));
 static void check_sigreq __P((void));
 static void check_flushsa __P((void));
 static int close_sockets __P((void));
+#endif /* __rtems__ */
 
 #ifndef __rtems__
 static fd_set preset_mask, active_mask;
@@ -140,8 +142,10 @@ static struct fd_monitor *allocated_fd_monitors;
 static TAILQ_HEAD(fd_monitor_list, fd_monitor) fd_monitor_tree[NUM_PRIORITIES];
 static int nfds = 0;
 
+#ifndef __rtems__
 static volatile sig_atomic_t sigreq[NSIG + 1];
 static struct sched scflushsa = SCHED_INITIALIZER();
+#endif /* __rtems__ */
 
 void
 monitor_fd(int fd, int (*callback)(void *, int), void *ctx, int priority)
@@ -199,9 +203,11 @@ session(void)
 {
 	struct timeval *timeout;
 	int error;
+#ifndef __rtems__
 	char pid_file[MAXPATHLEN];
 	FILE *fp;
 	pid_t racoon_pid = 0;
+#endif /* __rtems__ */
 	int i, count;
 	struct fd_monitor *fdm;
 
@@ -228,7 +234,9 @@ session(void)
 
 	/* initialize schedular */
 	sched_init();
+#ifndef __rtems__
 	init_signal();
+#endif /* __rtems__ */
 
 	if (pfkey_init() < 0)
 		errx(1, "failed to initialize pfkey socket");
@@ -325,17 +333,19 @@ session(void)
 	racoon_pid = getpid();
 	fprintf(fp, "%ld\n", (long)racoon_pid);
 	fclose(fp);
-#endif /* __rtems__ */
 
 	for (i = 0; i <= NSIG; i++)
 		sigreq[i] = 0;
+#endif /* __rtems__ */
 
 	while (1) {
+#ifndef __rtems__
 		/*
 		 * asynchronous requests via signal.
 		 * make sure to reset sigreq to 0.
 		 */
 		check_sigreq();
+#endif /* __rtems__ */
 
 		/* scheduling */
 		timeout = schedular();
@@ -379,6 +389,7 @@ session(void)
 	}
 }
 
+#ifndef __rtems__
 /* clear all status and exit program. */
 static void
 close_session()
@@ -391,11 +402,6 @@ close_session()
 	flushsainfo();
 	close_sockets();
 	backupsa_clean();
-#ifdef __rtems__
-	free(allocated_preset_mask); allocated_preset_mask = NULL;
-	free(allocated_active_mask); allocated_active_mask = NULL;
-	free(allocated_fd_monitors); allocated_fd_monitors = NULL;
-#endif /* __rtems__ */
 
 	plog(LLV_INFO, LOCATION, NULL, "racoon process %d shutdown\n", getpid());
 
@@ -565,11 +571,7 @@ set_signal(sig, func)
 
 	memset((caddr_t)&sa, 0, sizeof(sa));
 	sa.sa_handler = func;
-#ifndef __rtems__
 	sa.sa_flags = SA_RESTART;
-#else /* __rtems__ */
-	sa.sa_flags = 0;
-#endif /* __rtems__ */
 
 	if (sigemptyset(&sa.sa_mask) < 0)
 		return -1;
@@ -590,6 +592,7 @@ close_sockets()
 #endif
 	return 0;
 }
+#endif /* __rtems__ */
 
 #ifdef __rtems__
 #include "rtems-bsd-racoon-session-data.h"
-- 
2.35.3



More information about the devel mailing list