From 32e81e75554e296c5fa9364a7d4312da1395e79c Mon Sep 17 00:00:00 2001 From: Juan RP Date: Wed, 8 Apr 2009 03:20:13 +0200 Subject: [PATCH] For INSTALL/REMOVE scripts use xbps_file_chdir_exec(). This will chroot() to rootdir and removes many chroot() commands from those scripts. --HG-- extra : convert_revision : 4845df1949996da1bcd2776fcc50c3d0a00b451b --- lib/remove.c | 16 +++++----------- lib/unpack.c | 4 ++-- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/remove.c b/lib/remove.c index 33109c1b105..93f1da01493 100644 --- a/lib/remove.c +++ b/lib/remove.c @@ -214,7 +214,7 @@ xbps_remove_binary_pkg(const char *pkgname, bool update) prop_dictionary_t dict; const char *rootdir = xbps_get_rootdir(); char *path, *buf; - int fd, rv = 0; + int rv = 0; bool prepostf = false; assert(pkgname != NULL); @@ -231,7 +231,7 @@ xbps_remove_binary_pkg(const char *pkgname, bool update) if (chdir(rootdir) == -1) return errno; - buf = xbps_xasprintf("%s/%s/metadata/%s/REMOVE", rootdir, + buf = xbps_xasprintf(".%s/metadata/%s/REMOVE", XBPS_META_PATH, pkgname); if (buf == NULL) return errno; @@ -239,20 +239,14 @@ xbps_remove_binary_pkg(const char *pkgname, bool update) /* * Find out if the REMOVE file exists. */ - if ((fd = open(buf, O_RDONLY)) == -1) { - if (errno != ENOENT) { - free(buf); - return errno; - } - } else { + if (access(buf, R_OK) == 0) { /* * Run the pre remove action. */ - (void)close(fd); prepostf = true; (void)printf("\n"); (void)fflush(stdout); - rv = xbps_file_exec(buf, rootdir, "pre", pkgname, NULL); + rv = xbps_file_chdir_exec(rootdir, buf, "pre", pkgname, NULL); if (rv != 0) { printf("%s: prerm action target error (%s)\n", pkgname, strerror(errno)); @@ -293,7 +287,7 @@ xbps_remove_binary_pkg(const char *pkgname, bool update) * Run the post remove action if REMOVE file is there. */ if (prepostf) { - if ((rv = xbps_file_exec(buf, rootdir, "post", + if ((rv = xbps_file_chdir_exec(rootdir, buf, "post", pkgname, NULL)) != 0) { printf("%s: postrm action target error (%s)\n", pkgname, strerror(errno)); diff --git a/lib/unpack.c b/lib/unpack.c index 2f16e9c0c49..efac0944d6a 100644 --- a/lib/unpack.c +++ b/lib/unpack.c @@ -176,7 +176,7 @@ unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg) break; } - if ((rv = xbps_file_exec(buf, rootdir, "pre", + if ((rv = xbps_file_chdir_exec(rootdir, buf, "pre", pkgname, version, NULL)) != 0) { printf("%s: preinst action target error %s\n", pkgname, strerror(errno)); @@ -219,7 +219,7 @@ unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg) * Run the post installaction action target, if package * contains the script. */ - if ((rv = xbps_file_exec(buf, rootdir, "post", + if ((rv = xbps_file_chdir_exec(rootdir, buf, "post", pkgname, version, NULL)) != 0) { printf("%s: postinst action target error %s\n", pkgname, strerror(errno));