|
@@ -2,19 +2,27 @@
|
|
|
#include <stdlib.h>
|
|
|
#include <sys/types.h>
|
|
|
#include <sys/wait.h>
|
|
|
-#include <string.h>
|
|
|
// TODO: Not nescessary
|
|
|
#include <stdio.h>
|
|
|
|
|
|
+#include <string>
|
|
|
+#include <vector>
|
|
|
+
|
|
|
#include "common.h"
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
-/* Runs the configured script with the given (single) argument and
|
|
|
- * environment variables. Returns -1 upon failure, or the exit code of
|
|
|
- * the script upon success. */
|
|
|
-int run_script(const char *arg0, char *const *envp)
|
|
|
+int run_script(std::string arg0, std::vector<std::string> env)
|
|
|
{
|
|
|
+ /* Convert the vector containing environment variables to the format
|
|
|
+ * expected by execle(). */
|
|
|
+ char const* envp[env.size() + 1];
|
|
|
+ for (int i = 0; i < env.size(); ++i) {
|
|
|
+ envp[i] = env[i].data();
|
|
|
+ }
|
|
|
+ envp[env.size()] = (char const*) NULL;
|
|
|
+
|
|
|
+ /* fork() & execle() */
|
|
|
int ret, wstatus, exitcode;
|
|
|
pid_t pid;
|
|
|
pid = fork();
|
|
@@ -25,7 +33,7 @@ int run_script(const char *arg0, char *const *envp)
|
|
|
}
|
|
|
if (pid == 0) {
|
|
|
/* Child process */
|
|
|
- ret = execle(script_path.data(), script_name.data(), arg0, (char *)NULL, envp);
|
|
|
+ ret = execle(script_path.data(), script_name.data(), arg0.data(), (char *)NULL, envp);
|
|
|
// TODO: logging, errno is usable
|
|
|
fprintf(stderr, "Error during execle() in child\n");
|
|
|
exit(EXIT_FAILURE);
|