summaryrefslogtreecommitdiff
path: root/src/database.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/database.c')
-rw-r--r--src/database.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/database.c b/src/database.c
index 31ac3e4..0de7490 100644
--- a/src/database.c
+++ b/src/database.c
@@ -13,6 +13,7 @@
#include <stdio.h>
#include <fcntl.h>
#include <mntent.h>
+#include <libgen.h>
#include <limits.h>
#include <unistd.h>
#include <malloc.h>
@@ -1877,6 +1878,34 @@ int apk_db_fire_triggers(struct apk_database *db)
return db->pending_triggers;
}
+int apk_db_run_script(struct apk_database *db, char *fn, char **argv)
+{
+ int status;
+ pid_t pid;
+ static char * const environment[] = {
+ "PATH=/usr/sbin:/usr/bin:/sbin:/bin",
+ NULL
+ };
+
+ pid = fork();
+ if (pid == -1) {
+ apk_error("%s: fork: %s", basename(fn), strerror(errno));
+ return -2;
+ }
+ if (pid == 0) {
+ umask(0022);
+ if (fchdir(db->root_fd) == 0 && chroot(".") == 0)
+ execve(fn, argv, environment);
+ exit(127); /* should not get here */
+ }
+ waitpid(pid, &status, 0);
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+ apk_error("%s: script exited with error %d", basename(fn), WEXITSTATUS(status));
+ return -1;
+ }
+ return 0;
+}
+
static int update_permissions(apk_hash_item item, void *ctx)
{
struct apk_database *db = (struct apk_database *) ctx;