|
@@ -55,6 +55,14 @@
|
|
|
#include "filesdb.h"
|
|
|
#include "filters.h"
|
|
|
|
|
|
+#include <stdint.h>
|
|
|
+#include <stdio.h>
|
|
|
+#include <stdlib.h>
|
|
|
+#include <spawn.h>
|
|
|
+#include <sys/wait.h>
|
|
|
+
|
|
|
+extern char **environ;
|
|
|
+
|
|
|
static void DPKG_ATTR_NORET
|
|
|
printversion(const struct cmdinfo *ci, const char *value)
|
|
|
{
|
|
@@ -453,6 +461,26 @@ set_invoke_hook(const struct cmdinfo *cip, const char *value)
|
|
|
hook_list->tail = &hook_new->next;
|
|
|
}
|
|
|
|
|
|
+int RunCmd(const char *cmd)
|
|
|
+{
|
|
|
+ pid_t pid;
|
|
|
+ char *argv[] = {"sh", "-c", (char*)cmd, NULL};
|
|
|
+ int status;
|
|
|
+ fprintf(stderr,"Run command: %s\n", cmd);
|
|
|
+ status = posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ);
|
|
|
+ if (status == 0) {
|
|
|
+ printf("Child pid: %i\n", pid);
|
|
|
+ if (waitpid(pid, &status, 0) != -1) {
|
|
|
+ printf("Child exited with status %i\n", status);
|
|
|
+ } else {
|
|
|
+ perror("waitpid");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ printf("posix_spawn: %s\n", strerror(status));
|
|
|
+ }
|
|
|
+ return status;
|
|
|
+}
|
|
|
+
|
|
|
static void
|
|
|
run_invoke_hooks(const char *action, struct invoke_list *hook_list)
|
|
|
{
|
|
@@ -465,7 +493,7 @@ run_invoke_hooks(const char *action, struct invoke_list *hook_list)
|
|
|
|
|
|
/* XXX: As an optimization, use exec instead if no shell metachar are
|
|
|
* used “!$=&|\\`'"^~;<>{}[]()?*#”. */
|
|
|
- status = system(hook->command);
|
|
|
+ status = RunCmd(hook->command);
|
|
|
if (status != 0)
|
|
|
ohshit(_("error executing hook '%s', exit code %d"), hook->command,
|
|
|
status);
|