From 55a76279c53198084faa393f9fb52476f13729a6 Mon Sep 17 00:00:00 2001 From: Aurelien Foret Date: Sun, 1 Jan 2006 12:20:36 +0000 Subject: - fixed a regression with pacman 2.x (patch from VMiklos ) - code reowrk to ensure the /tmp/alpm_foo directory is always removed --- lib/libalpm/util.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'lib/libalpm') diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 178de865..0e685d07 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -360,8 +360,9 @@ int _alpm_runscriptlet(char *root, char *installfn, char *script, char *ver, cha char tmpdir[PATH_MAX] = ""; char *scriptpath; struct stat buf; - char cwd[PATH_MAX]; + char cwd[PATH_MAX] = ""; pid_t pid; + int retval = 0; if(stat(installfn, &buf)) { /* not found */ @@ -382,7 +383,6 @@ int _alpm_runscriptlet(char *root, char *installfn, char *script, char *ver, cha snprintf(scriptfn, PATH_MAX, "%s/.INSTALL", tmpdir); /* chop off the root so we can find the tmpdir in the chroot */ scriptpath = scriptfn + strlen(root) - 1; - return(0); } else { STRNCPY(scriptfn, installfn, PATH_MAX); /* chop off the root so we can find the tmpdir in the chroot */ @@ -391,14 +391,16 @@ int _alpm_runscriptlet(char *root, char *installfn, char *script, char *ver, cha if(!_alpm_grep(scriptfn, script)) { /* script not found in scriptlet file */ - if(strlen(tmpdir) && _alpm_rmrf(tmpdir)) { - _alpm_log(PM_LOG_WARNING, "could not remove tmpdir %s", tmpdir); - } - return(0); + goto cleanup; } /* save the cwd so we can restore it later */ - getcwd(cwd, PATH_MAX); + if(getcwd(cwd, PATH_MAX) == NULL) { + _alpm_log(PM_LOG_ERROR, "could not get current working directory"); + /* in case of error, cwd content is undefined: so we set it to something */ + cwd[0] = 0; + } + /* just in case our cwd was removed in the upgrade operation */ chdir("/"); @@ -416,15 +418,15 @@ int _alpm_runscriptlet(char *root, char *installfn, char *script, char *ver, cha pid = fork(); if(pid == -1) { _alpm_log(PM_LOG_ERROR, "could not fork a new process (%s)", strerror(errno)); - chdir(cwd); - return(1); + retval = 1; + goto cleanup; } if(pid == 0) { _alpm_log(PM_LOG_DEBUG, "chrooting in %s", root); if(chroot(root) != 0) { _alpm_log(PM_LOG_ERROR, "could not change the root directory (%s)", strerror(errno)); - return (1); + return(1); } umask(0022); _alpm_log(PM_LOG_DEBUG, "executing \"%s\"", cmdline); @@ -433,17 +435,20 @@ int _alpm_runscriptlet(char *root, char *installfn, char *script, char *ver, cha } else { if(waitpid(pid, 0, 0) == -1) { _alpm_log(PM_LOG_ERROR, "call to waitpid failed (%s)", strerror(errno)); - chdir(cwd); - return(1); + retval = 1; + goto cleanup; } } +cleanup: if(strlen(tmpdir) && _alpm_rmrf(tmpdir)) { _alpm_log(PM_LOG_WARNING, "could not remove tmpdir %s", tmpdir); } + if(strlen(cwd)) { + chdir(cwd); + } - chdir(cwd); - return(0); + return(retval); } /* vim: set ts=2 sw=2 noet: */ -- cgit v1.2.3-24-g4f1b