[pacman-dev] [PATCH 2/2] use execv to avoid using sh just to run ldconfig
Signed-off-by: Jonathan Conder <j@skurvy.no-ip.org> --- lib/libalpm/trans.c | 5 ++++- lib/libalpm/util.c | 11 ++++++----- lib/libalpm/util.h | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) I just improved the debug output for this patch, which I've been meaning to do since I first submitted it. diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index 523f33b..61d0722 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -343,6 +343,7 @@ int _alpm_runscriptlet(const char *root, const char *installfn, char scriptfn[PATH_MAX]; char cmdline[PATH_MAX]; char tmpdir[PATH_MAX]; + char *argv[] = { "sh", "-c", cmdline, NULL }; char *scriptpath; int clean_tmpdir = 0; int retval = 0; @@ -400,7 +401,9 @@ int _alpm_runscriptlet(const char *root, const char *installfn, scriptpath, script, ver); } - retval = _alpm_run_chroot(root, cmdline); + _alpm_log(PM_LOG_DEBUG, "executing \"%s\"\n", cmdline); + + retval = _alpm_run_chroot(root, "/bin/sh", argv); cleanup: if(clean_tmpdir && _alpm_rmrf(tmpdir)) { diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 46460f0..8a1f392 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -452,7 +452,7 @@ int _alpm_logaction(int usesyslog, FILE *f, const char *fmt, va_list args) return(ret); } -int _alpm_run_chroot(const char *root, const char *cmd) +int _alpm_run_chroot(const char *root, const char *path, char *const argv[]) { char cwd[PATH_MAX]; pid_t pid; @@ -475,7 +475,7 @@ int _alpm_run_chroot(const char *root, const char *cmd) goto cleanup; } - _alpm_log(PM_LOG_DEBUG, "executing \"%s\" under chroot \"%s\"\n", cmd, root); + _alpm_log(PM_LOG_DEBUG, "executing \"%s\" under chroot \"%s\"\n", path, root); /* Flush open fds before fork() to avoid cloning buffers */ fflush(NULL); @@ -513,8 +513,8 @@ int _alpm_run_chroot(const char *root, const char *cmd) exit(1); } umask(0022); - execl("/bin/sh", "sh", "-c", cmd, (char *) NULL); - fprintf(stderr, _("call to execl failed (%s)\n"), strerror(errno)); + execv(path, argv); + fprintf(stderr, _("call to execv failed (%s)\n"), strerror(errno)); exit(1); } else { /* this code runs for the parent only (wait on the child) */ @@ -578,7 +578,8 @@ int _alpm_ldconfig(const char *root) if(access(line, F_OK) == 0) { snprintf(line, PATH_MAX, "%ssbin/ldconfig", root); if(access(line, X_OK) == 0) { - _alpm_run_chroot(root, "/sbin/ldconfig"); + char *argv[] = { "ldconfig", NULL }; + _alpm_run_chroot(root, "/sbin/ldconfig", argv); } } diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 8a3154a..35c4d28 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -68,7 +68,7 @@ int _alpm_unpack_single(const char *archive, const char *prefix, const char *fn) int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int breakfirst); int _alpm_rmrf(const char *path); int _alpm_logaction(int usesyslog, FILE *f, const char *fmt, va_list args); -int _alpm_run_chroot(const char *root, const char *cmd); +int _alpm_run_chroot(const char *root, const char *path, char *const argv[]); int _alpm_ldconfig(const char *root); int _alpm_str_cmp(const void *s1, const void *s2); char *_alpm_filecache_find(const char *filename); -- 1.7.2.1
On Wed, Aug 18, 2010 at 2:07 PM, Jonathan Conder <j@skurvy.no-ip.org> wrote:
Signed-off-by: Jonathan Conder <j@skurvy.no-ip.org> --- lib/libalpm/trans.c | 5 ++++- lib/libalpm/util.c | 11 ++++++----- lib/libalpm/util.h | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-)
I just improved the debug output for this patch, which I've been meaning to do since I first submitted it.
I already ack-ed both a while ago and had merged them in my tree, but for some reasons they stayed there. So new ack for the 2 lines change, and merged to my working branch again ;) http://code.toofishes.net/cgit/xavier/pacman.git/log/?h=working
On Thu, 2010-08-19 at 00:09 +0200, Xavier Chantry wrote:
On Wed, Aug 18, 2010 at 2:07 PM, Jonathan Conder <j@skurvy.no-ip.org> wrote:
Signed-off-by: Jonathan Conder <j@skurvy.no-ip.org> --- lib/libalpm/trans.c | 5 ++++- lib/libalpm/util.c | 11 ++++++----- lib/libalpm/util.h | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-)
I just improved the debug output for this patch, which I've been meaning to do since I first submitted it.
I already ack-ed both a while ago and had merged them in my tree, but for some reasons they stayed there. So new ack for the 2 lines change, and merged to my working branch again ;) http://code.toofishes.net/cgit/xavier/pacman.git/log/?h=working
Thanks :). Just a heads-up: the new version of fakechroot (2.10) implements popen[1], so if nothing else the pactest might need to go in. Jonathan [1] http://fakechroot.alioth.debian.org/
participants (2)
-
Jonathan Conder
-
Xavier Chantry