summaryrefslogtreecommitdiff
path: root/src/libsystem/exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystem/exec.c')
-rw-r--r--src/libsystem/exec.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/libsystem/exec.c b/src/libsystem/exec.c
index 272014d..5fb49f4 100644
--- a/src/libsystem/exec.c
+++ b/src/libsystem/exec.c
@@ -29,10 +29,11 @@
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <signal.h>
#include "libsystem.h"
-static int wait_child(pid_t pid, int64_t timeout_msec) {
+static int wait_child(pid_t pid, int64_t timeout_msec, int sig) {
struct timeval start, timeout;
int status;
@@ -62,8 +63,10 @@ static int wait_child(pid_t pid, int64_t timeout_msec) {
timersub(&current, &start, &delta);
- if (timercmp(&timeout, &delta, <))
+ if (timercmp(&timeout, &delta, <)) {
+ (void) kill(pid, sig);
return -ETIME;
+ }
usleep(100000);
}
@@ -71,7 +74,7 @@ static int wait_child(pid_t pid, int64_t timeout_msec) {
return WEXITSTATUS(status);
}
-int do_fork_exec_redirect(char *const argv[], char * const envp[], int64_t timeout_msec, int fd, int flags) {
+int do_fork_exec_kill_redirect(char *const argv[], char * const envp[], int64_t timeout_msec, int sig, int fd, int flags) {
pid_t pid;
assert(argv);
@@ -97,12 +100,26 @@ int do_fork_exec_redirect(char *const argv[], char * const envp[], int64_t timeo
_exit(EXIT_FAILURE);
}
- return wait_child(pid, timeout_msec);
+ return wait_child(pid, timeout_msec, sig);
+}
+
+int do_fork_exec_redirect(char *const argv[], char * const envp[], int64_t timeout_msec, int fd, int flags) {
+
+ assert(argv);
+
+ return do_fork_exec_kill_redirect(argv, envp, timeout_msec, SIGTERM, fd, flags);
+}
+
+int do_fork_exec_kill(char *const argv[], char * const envp[], int64_t timeout_msec, int sig) {
+
+ assert(argv);
+
+ return do_fork_exec_kill_redirect(argv, envp, timeout_msec, sig, -1, EXEC_REDIRECT_NONE);
}
int do_fork_exec(char *const argv[], char * const envp[], int64_t timeout_msec) {
assert(argv);
- return do_fork_exec_redirect(argv, envp, timeout_msec, -1, EXEC_REDIRECT_NONE);
+ return do_fork_exec_kill(argv, envp, timeout_msec, SIGTERM);
}