1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
From: Hilko Bengen <bengen@debian.org>
Date: Sun, 10 Jan 2021 00:24:53 +0100
Subject: output: Replace system() with explicit bash invocation
Tehre is probably a better way to do this.
---
filters/log/output.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/filters/log/output.c b/filters/log/output.c
index 4a11604..e769dc5 100644
--- a/filters/log/output.c
+++ b/filters/log/output.c
@@ -44,6 +44,7 @@
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
+#include <sys/wait.h>
#include <nbdkit-filter.h>
@@ -113,6 +114,8 @@ to_script (struct handle *h, log_id_t id, const char *act, enum type type,
CLEANUP_FREE char *str = NULL;
size_t len = 0;
int r;
+ int pid;
+ int wstatus = 0;
/* Create the shell variables + script. */
fp = open_memstream (&str, &len);
@@ -140,7 +143,14 @@ to_script (struct handle *h, log_id_t id, const char *act, enum type type,
fclose (fp);
/* Run the script. Log the status, but ignore it. */
- r = system (str);
+ if (pid = fork() == 0) {
+ execl ("/bin/bash", "sh", "-c", str, NULL);
+ exit (-errno);
+ } else if (pid > 0) {
+ waitpid (pid, &r, 0);
+ } else {
+ r = -1;
+ }
exit_status_to_nbd_error (r, "logscript");
}
|