- 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:
parent
d28415a3b7
commit
55a76279c5
1 changed files with 19 additions and 14 deletions
|
@ -360,8 +360,9 @@ int _alpm_runscriptlet(char *root, char *installfn, char *script, char *ver, cha
|
||||||
char tmpdir[PATH_MAX] = "";
|
char tmpdir[PATH_MAX] = "";
|
||||||
char *scriptpath;
|
char *scriptpath;
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
char cwd[PATH_MAX];
|
char cwd[PATH_MAX] = "";
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
int retval = 0;
|
||||||
|
|
||||||
if(stat(installfn, &buf)) {
|
if(stat(installfn, &buf)) {
|
||||||
/* not found */
|
/* 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);
|
snprintf(scriptfn, PATH_MAX, "%s/.INSTALL", tmpdir);
|
||||||
/* chop off the root so we can find the tmpdir in the chroot */
|
/* chop off the root so we can find the tmpdir in the chroot */
|
||||||
scriptpath = scriptfn + strlen(root) - 1;
|
scriptpath = scriptfn + strlen(root) - 1;
|
||||||
return(0);
|
|
||||||
} else {
|
} else {
|
||||||
STRNCPY(scriptfn, installfn, PATH_MAX);
|
STRNCPY(scriptfn, installfn, PATH_MAX);
|
||||||
/* chop off the root so we can find the tmpdir in the chroot */
|
/* 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)) {
|
if(!_alpm_grep(scriptfn, script)) {
|
||||||
/* script not found in scriptlet file */
|
/* script not found in scriptlet file */
|
||||||
if(strlen(tmpdir) && _alpm_rmrf(tmpdir)) {
|
goto cleanup;
|
||||||
_alpm_log(PM_LOG_WARNING, "could not remove tmpdir %s", tmpdir);
|
|
||||||
}
|
|
||||||
return(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* save the cwd so we can restore it later */
|
/* 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 */
|
/* just in case our cwd was removed in the upgrade operation */
|
||||||
chdir("/");
|
chdir("/");
|
||||||
|
|
||||||
|
@ -416,15 +418,15 @@ int _alpm_runscriptlet(char *root, char *installfn, char *script, char *ver, cha
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if(pid == -1) {
|
if(pid == -1) {
|
||||||
_alpm_log(PM_LOG_ERROR, "could not fork a new process (%s)", strerror(errno));
|
_alpm_log(PM_LOG_ERROR, "could not fork a new process (%s)", strerror(errno));
|
||||||
chdir(cwd);
|
retval = 1;
|
||||||
return(1);
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pid == 0) {
|
if(pid == 0) {
|
||||||
_alpm_log(PM_LOG_DEBUG, "chrooting in %s", root);
|
_alpm_log(PM_LOG_DEBUG, "chrooting in %s", root);
|
||||||
if(chroot(root) != 0) {
|
if(chroot(root) != 0) {
|
||||||
_alpm_log(PM_LOG_ERROR, "could not change the root directory (%s)", strerror(errno));
|
_alpm_log(PM_LOG_ERROR, "could not change the root directory (%s)", strerror(errno));
|
||||||
return (1);
|
return(1);
|
||||||
}
|
}
|
||||||
umask(0022);
|
umask(0022);
|
||||||
_alpm_log(PM_LOG_DEBUG, "executing \"%s\"", cmdline);
|
_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 {
|
} else {
|
||||||
if(waitpid(pid, 0, 0) == -1) {
|
if(waitpid(pid, 0, 0) == -1) {
|
||||||
_alpm_log(PM_LOG_ERROR, "call to waitpid failed (%s)", strerror(errno));
|
_alpm_log(PM_LOG_ERROR, "call to waitpid failed (%s)", strerror(errno));
|
||||||
chdir(cwd);
|
retval = 1;
|
||||||
return(1);
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
if(strlen(tmpdir) && _alpm_rmrf(tmpdir)) {
|
if(strlen(tmpdir) && _alpm_rmrf(tmpdir)) {
|
||||||
_alpm_log(PM_LOG_WARNING, "could not remove tmpdir %s", tmpdir);
|
_alpm_log(PM_LOG_WARNING, "could not remove tmpdir %s", tmpdir);
|
||||||
}
|
}
|
||||||
|
if(strlen(cwd)) {
|
||||||
|
chdir(cwd);
|
||||||
|
}
|
||||||
|
|
||||||
chdir(cwd);
|
return(retval);
|
||||||
return(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set ts=2 sw=2 noet: */
|
/* vim: set ts=2 sw=2 noet: */
|
||||||
|
|
Loading…
Add table
Reference in a new issue