Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2006-01-01 12:20:36 +0000
committerAurelien Foret <aurelien@archlinux.org>2006-01-01 12:20:36 +0000
commit55a76279c53198084faa393f9fb52476f13729a6 (patch)
treee7df6c05e38262fba78577ed58df47dce00b2ce5 /lib
parentd28415a3b76c51253c37d192e68e630fe034bf5a (diff)
- fixed a regression with pacman 2.x (patch from VMiklos <vmiklos@frugalware.org>)
- code reowrk to ensure the /tmp/alpm_foo directory is always removed
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/util.c33
1 files changed, 19 insertions, 14 deletions
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: */