index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Dan McGee <dan@archlinux.org> | 2007-10-05 00:13:36 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2007-10-08 20:46:55 -0500 |
commit | b1613c26518abb55ae5fc970dccfb7e3c97398d1 (patch) | |
tree | d479a6193c1384b34dd44013273481c3af184ed0 | |
parent | 3d8408759d16b1ecfa6e7981d0cc3db1f39163a4 (diff) |
-rw-r--r-- | lib/libalpm/trans.c | 23 |
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index 462b4d8b..22780899 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -608,6 +608,7 @@ int _alpm_runscriptlet(const char *root, const char *installfn, } _alpm_log(PM_LOG_DEBUG, "%s\n", cmdline); + /* fork- parent and child each have seperate code blocks below */ pid = fork(); if(pid == -1) { _alpm_log(PM_LOG_ERROR, _("could not fork a new process (%s)\n"), strerror(errno)); @@ -616,13 +617,16 @@ int _alpm_runscriptlet(const char *root, const char *installfn, } if(pid == 0) { + /* this code runs for the child only (the actual chroot/exec) */ _alpm_log(PM_LOG_DEBUG, "chrooting in %s\n", root); if(chroot(root) != 0) { - _alpm_log(PM_LOG_ERROR, _("could not change the root directory (%s)\n"), strerror(errno)); + _alpm_log(PM_LOG_ERROR, _("could not change the root directory (%s)\n"), + strerror(errno)); exit(1); } if(chdir("/") != 0) { - _alpm_log(PM_LOG_ERROR, _("could not change directory to / (%s)\n"), strerror(errno)); + _alpm_log(PM_LOG_ERROR, _("could not change directory to / (%s)\n"), + strerror(errno)); exit(1); } umask(0022); @@ -630,11 +634,24 @@ int _alpm_runscriptlet(const char *root, const char *installfn, execl("/bin/sh", "sh", "-c", cmdline, (char *)NULL); exit(0); } else { - if(waitpid(pid, 0, 0) == -1) { + /* this code runs for the parent only (wait on the child) */ + pid_t retpid; + int status; + retpid = waitpid(pid, &status, 0); + if(retpid == -1) { _alpm_log(PM_LOG_ERROR, _("call to waitpid failed (%s)\n"), strerror(errno)); retval = 1; goto cleanup; + } else { + /* check the return status, make sure it is 0 (success) */ + if(WIFEXITED(status)) { + _alpm_log(PM_LOG_DEBUG, "call to waitpid succeeded\n"); + if(WEXITSTATUS(status) != 0) { + _alpm_log(PM_LOG_ERROR, _("scriptlet failed to execute correctly\n")); + retval = 1; + } + } } } |