summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@ugent.be>2018-02-23 16:17:12 +0100
committerDimitri Staessens <dimitri.staessens@ugent.be>2018-02-23 16:23:43 +0100
commit4dad657dec442052da2177e713e2008862fa1647 (patch)
tree365de3ea5a5dd1179def90e680b073627f12d92b /src
parent7f6969bd57d6d892ad7cf97b94311d55f0957e56 (diff)
downloadouroboros-4dad657dec442052da2177e713e2008862fa1647.tar.gz
ouroboros-4dad657dec442052da2177e713e2008862fa1647.zip
irmd: Replace fork and execv with posix_spawn
This replaces the fork and execv calls with posix_spawn since it is supported on more platforms, and is more efficient. Also fixes some bad indentation. Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be> Signed-off-by: Dimitri Staessens <dimitri.staessens@ugent.be>
Diffstat (limited to 'src')
-rw-r--r--src/irmd/ipcp.c19
-rw-r--r--src/irmd/main.c25
2 files changed, 16 insertions, 28 deletions
diff --git a/src/irmd/ipcp.c b/src/irmd/ipcp.c
index 87cbaca5..f90ba251 100644
--- a/src/irmd/ipcp.c
+++ b/src/irmd/ipcp.c
@@ -42,6 +42,7 @@
#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/time.h>
+#include <spawn.h>
static void close_ptr(void * o)
{
@@ -162,15 +163,6 @@ pid_t ipcp_create(const char * name,
sprintf(irmd_pid, "%u", getpid());
- pid = fork();
- if (pid == -1) {
- log_err("Failed to fork");
- return pid;
- }
-
- if (pid != 0)
- return pid;
-
strcpy(full_name, INSTALL_PREFIX);
strcat(full_name, ipcp_dir);
strcat(full_name, exec_name);
@@ -186,11 +178,12 @@ pid_t ipcp_create(const char * name,
argv[4] = NULL;
- execv(argv[0], &argv[0]);
+ if (posix_spawn(&pid, argv[0], NULL, NULL, argv, NULL)) {
+ log_err("Failed to spawn new process");
+ return -1;
+ }
- log_dbg("%s", strerror(errno));
- log_err("Failed to load IPCP daemon.");
- exit(EXIT_FAILURE);
+ return pid;
}
int ipcp_destroy(pid_t pid)
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 658811e2..74317610 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -59,6 +59,7 @@
#include <pthread.h>
#include <sys/stat.h>
#include <sys/wait.h>
+#include <spawn.h>
#ifdef HAVE_LIBGCRYPT
#include <gcrypt.h>
@@ -685,7 +686,8 @@ static int bind_program(char * prog,
if (argv_dup[i] == NULL) {
pthread_rwlock_unlock(&irmd.reg_lock);
argvfree(argv_dup);
- log_err("Failed to bind program %s to %s.",
+ log_err("Failed to bind program "
+ "%s to %s.",
prog, name);
free(progs);
free(progn);
@@ -1370,22 +1372,14 @@ static pid_t auto_execute(char ** argv)
return -1;
}
- pid = fork();
- if (pid == -1) {
- log_err("Failed to fork");
- return pid;
- }
-
- if (pid != 0) {
- log_info("Instantiated %s as process %d.", argv[0], pid);
- return pid;
+ if (posix_spawn(&pid, argv[0], NULL, NULL, argv, NULL)) {
+ log_err("Failed to spawn new process");
+ return -1;
}
- execv(argv[0], argv);
+ log_info("Instantiated %s as process %d.", argv[0], pid);
- log_err("Failed to execute %s.", argv[0]);
-
- exit(EXIT_FAILURE);
+ return pid;
}
static struct irm_flow * flow_req_arr(pid_t pid,
@@ -1776,7 +1770,8 @@ void * irm_sanitize(void * o)
if (kill(f->n_pid, 0) < 0) {
struct shm_flow_set * set;
- log_dbg("Process %d gone, deallocating flow %d.",
+ log_dbg("Process %d gone, deallocating "
+ "flow %d.",
f->n_pid, f->port_id);
set = shm_flow_set_open(f->n_pid);
if (set != NULL)