output: Replace system() with explicit bash invocation
authorHilko Bengen <bengen@debian.org>
Sat, 9 Jan 2021 23:24:53 +0000 (00:24 +0100)
committerHilko Bengen <bengen@debian.org>
Fri, 10 May 2024 10:38:26 +0000 (12:38 +0200)
Tehre is probably a better way to do this.

Gbp-Pq: Name 0007-output-Replace-system-with-explicit-bash-invocation.patch

filters/log/output.c

index 4a1160466c42ef24144f6df4d8746cbc814fb0d0..e769dc5d8f697a518aa5cb482e8860dbfd0a0bac 100644 (file)
@@ -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");
 }