diff options
author | Chantry Xavier <shiningxc@gmail.com> | 2007-10-14 10:17:48 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2007-10-14 18:47:19 -0500 |
commit | 3d7e06f204d7f94aa9d22cd4e4a895d2780025e8 (patch) | |
tree | 516677a3c2c734ba82ac46dd4bfa0c7535e68736 /lib/libalpm | |
parent | 4e6a03c4f6d413aa9f1c98d255c370c442ce55eb (diff) | |
download | pacman-3d7e06f204d7f94aa9d22cd4e4a895d2780025e8.tar.xz |
libalpm/trans.c : fix a recently introduced breakage in scriptlets handling.
Commit 4853a4aad97fe36f9237ffb7356201adab507a1c used the tmpdir variable
for checking the existence of /bin/sh, without resetting it.
This caused /bin/sh to be deleted during the cleanup part, as soon as a scriptlet
other than pre_upgrade or pre_install was executed.
For example, on the first post_upgrade during a -Su.
I introduced two variables : clean_tmpdir and restore_cwd, for deciding what should
be done in the cleanup part.
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Diffstat (limited to 'lib/libalpm')
-rw-r--r-- | lib/libalpm/trans.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index 68203fca..b8f87371 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -537,11 +537,13 @@ int _alpm_runscriptlet(const char *root, const char *installfn, { char scriptfn[PATH_MAX]; char cmdline[PATH_MAX]; - char tmpdir[PATH_MAX] = ""; + char tmpdir[PATH_MAX]; + char cwd[PATH_MAX]; char *scriptpath; struct stat buf; - char cwd[PATH_MAX] = ""; pid_t pid; + int clean_tmpdir = 0; + int restore_cwd = 0; int retval = 0; ALPM_LOG_FUNC; @@ -568,6 +570,8 @@ int _alpm_runscriptlet(const char *root, const char *installfn, if(mkdtemp(tmpdir) == NULL) { _alpm_log(PM_LOG_ERROR, _("could not create temp directory\n")); return(1); + } else { + clean_tmpdir = 1; } /* either extract or copy the scriptlet */ @@ -593,8 +597,8 @@ int _alpm_runscriptlet(const char *root, const char *installfn, /* save the cwd so we can restore it later */ if(getcwd(cwd, PATH_MAX) == NULL) { _alpm_log(PM_LOG_ERROR, _("could not get current working directory\n")); - /* in case of error, cwd content is undefined: so we set it to something */ - cwd[0] = 0; + } else { + restore_cwd = 1; } /* just in case our cwd was removed in the upgrade operation */ @@ -662,10 +666,10 @@ int _alpm_runscriptlet(const char *root, const char *installfn, } cleanup: - if(strlen(tmpdir) && _alpm_rmrf(tmpdir)) { + if(clean_tmpdir && _alpm_rmrf(tmpdir)) { _alpm_log(PM_LOG_WARNING, _("could not remove tmpdir %s\n"), tmpdir); } - if(strlen(cwd)) { + if(restore_cwd) { chdir(cwd); } |