From 3d7e06f204d7f94aa9d22cd4e4a895d2780025e8 Mon Sep 17 00:00:00 2001 From: Chantry Xavier Date: Sun, 14 Oct 2007 10:17:48 +0200 Subject: 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 --- lib/libalpm/trans.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lib/libalpm/trans.c') 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); } -- cgit v1.2.3