summaryrefslogtreecommitdiff
path: root/src/package.c
diff options
context:
space:
mode:
authorHenrik Riomar <henrik.riomar@gmail.com>2017-02-03 00:37:23 +0100
committerTimo Teräs <timo.teras@iki.fi>2017-02-15 13:44:04 +0200
commit349c61c9612a328f3a80f301d37aa8c14adcb43a (patch)
treefb779b62735e2cb47ed9f1d763bc1451ed19bcd9 /src/package.c
parent28a9dcda568c575c569ffa4b68775034b655230a (diff)
downloadapk-tools-349c61c9612a328f3a80f301d37aa8c14adcb43a.tar.gz
apk-tools-349c61c9612a328f3a80f301d37aa8c14adcb43a.tar.bz2
apk-tools-349c61c9612a328f3a80f301d37aa8c14adcb43a.tar.xz
apk-tools-349c61c9612a328f3a80f301d37aa8c14adcb43a.zip
add support for pre and post commit hooks
This allows for instance integration of etckeeper [TT: Reorganized code a bit, and modified to use single directory commit_hooks.d with argument for script of stage.]
Diffstat (limited to 'src/package.c')
-rw-r--r--src/package.c24
1 files changed, 2 insertions, 22 deletions
diff --git a/src/package.c b/src/package.c
index c6e8e48..d1c9c8b 100644
--- a/src/package.c
+++ b/src/package.c
@@ -979,14 +979,9 @@ void apk_ipkg_run_script(struct apk_installed_package *ipkg,
struct apk_database *db,
unsigned int type, char **argv)
{
- static char * const environment[] = {
- "PATH=/usr/sbin:/usr/bin:/sbin:/bin",
- NULL
- };
struct apk_package *pkg = ipkg->pkg;
char fn[PATH_MAX];
- int fd, status, root_fd = db->root_fd;
- pid_t pid;
+ int fd, root_fd = db->root_fd;
if (type >= APK_SCRIPT_MAX || ipkg->script[type].ptr == NULL)
return;
@@ -1015,23 +1010,8 @@ void apk_ipkg_run_script(struct apk_installed_package *ipkg,
}
close(fd);
- pid = fork();
- if (pid == -1)
- goto error;
- if (pid == 0) {
- umask(0022);
- if (fchdir(root_fd) == 0 && chroot(".") == 0)
- execve(fn, argv, environment);
- exit(1);
- }
- waitpid(pid, &status, 0);
- unlinkat(root_fd, fn, 0);
- apk_id_cache_reset(&db->id_cache);
-
- if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
- apk_error("%s: script exited with error %d", &fn[15], WEXITSTATUS(status));
+ if (apk_db_run_script(db, fn, argv) < 0)
ipkg->broken_script = 1;
- }
return;
error:
apk_error("%s: failed to execute: %s", &fn[15], apk_error_str(errno));