commit:     657234dd353ffc2ee1f464634aa8950260317404
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 22 09:02:54 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sun Feb 22 09:02:54 2015 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/portage-utils.git;a=commit;h=657234dd

qmerge: support running pkg funcs in a dir via fd

---
 libq/xsystem.c | 5 ++++-
 qmerge.c       | 5 +++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/libq/xsystem.c b/libq/xsystem.c
index 199a1d2..d8a551a 100644
--- a/libq/xsystem.c
+++ b/libq/xsystem.c
@@ -14,13 +14,16 @@ static void xsystem(const char *command)
                errp("system(%s) failed", command);
 }
 
-static void xsystembash(const char *command)
+static void xsystembash(const char *command, int cwd)
 {
        pid_t p = vfork();
        int status;
 
        switch (p) {
        case 0: /* child */
+               if (cwd != AT_FDCWD)
+                       if (fchdir(cwd))
+                               errp("fchdir failed");
                execl("/bin/bash", "bash", "--norc", "--noprofile", "-c", 
command, NULL);
                /* Hrm, still here ?  Maybe no bash ... */
                _exit(execl("/bin/sh", "sh", "-c", command, NULL));

diff --git a/qmerge.c b/qmerge.c
index c58e4f2..980a5b6 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -417,7 +417,7 @@ qprint_tree_node(int level, const depend_atom *atom, const 
struct pkg_t *pkg)
 }
 
 _q_static void
-pkg_run_func(const char *vdb_path, const char *phases, const char *func, const 
char *D, const char *T)
+pkg_run_func_at(int dirfd, const char *vdb_path, const char *phases, const 
char *func, const char *D, const char *T)
 {
        const char *phase;
        char *script;
@@ -484,9 +484,10 @@ pkg_run_func(const char *vdb_path, const char *phases, 
const char *func, const c
                /*5*/ D,
                /*6*/ T,
                /*7*/ debug ? "set -x;" : "");
-       xsystembash(script);
+       xsystembash(script, dirfd);
        free(script);
 }
+#define pkg_run_func(...) pkg_run_func_at(AT_FDCWD, __VA_ARGS__)
 
 /* Copy one tree (the single package) to another tree (ROOT) */
 _q_static int

Reply via email to