- 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
This commit is contained in:
Aurelien Foret 2006-01-01 12:20:36 +00:00
parent d28415a3b7
commit 55a76279c5

View file

@ -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,8 +418,8 @@ 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) {
@ -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);
return(0);
}
return(retval);
}
/* vim: set ts=2 sw=2 noet: */