From 3bbfdf4ce8d47f05006e5c62bbb71432b1ae67e3 Mon Sep 17 00:00:00 2001 From: Aurelien Foret Date: Tue, 29 Mar 2005 21:15:15 +0000 Subject: backport from pacman 2.9.5 - chdir --- lib/libalpm/util.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 29e39d30..73bab264 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -354,8 +354,7 @@ int _alpm_runscriptlet(char *root, char *installfn, char *script, char *ver, cha char tmpdir[PATH_MAX] = ""; char *scriptpath; struct stat buf; - - return(0); + char cwd[PATH_MAX]; if(stat(installfn, &buf)) { /* not found */ @@ -367,7 +366,7 @@ int _alpm_runscriptlet(char *root, char *installfn, char *script, char *ver, cha if(stat(tmpdir, &buf)) { _alpm_makepath(tmpdir); } - snprintf(tmpdir, PATH_MAX, "%stmp/pacman-XXXXXX", root); + snprintf(tmpdir, PATH_MAX, "%stmp/alpm_XXXXXX", root); if(mkdtemp(tmpdir) == NULL) { _alpm_log(PM_LOG_ERROR, "could not create temp directory"); return(1); @@ -391,6 +390,11 @@ int _alpm_runscriptlet(char *root, char *installfn, char *script, char *ver, cha return(0); } + /* save the cwd so we can restore it later */ + getcwd(cwd, PATH_MAX); + /* just in case our cwd was removed in the upgrade operation */ + chdir("/"); + _alpm_log(PM_LOG_FLOW2, "executing %s script...", script); if(oldver) { snprintf(cmdline, PATH_MAX, "echo \"umask 0022; source %s %s %s %s\" | chroot %s /bin/sh", @@ -405,6 +409,8 @@ int _alpm_runscriptlet(char *root, char *installfn, char *script, char *ver, cha if(strlen(tmpdir) && _alpm_rmrf(tmpdir)) { _alpm_log(PM_LOG_WARNING, "could not remove tmpdir %s", tmpdir); } + + chdir(cwd); return(0); } -- cgit v1.2.3