libalpm: handle syscall interruption correctly

It is possible to throw EINTR from a system call such as open(), close(), or
waitpid() if custom signal handlers are set up and they are not initialized
with the SA_RESTART flag. This was noticed by Andreas Radke when ^C (SIGINT)
was given during the call to waitpid(), causing it to throw the EINTR error
and we could not accommodate it.

Simply wrap these calls in a simple loop that allows us to retry the call if
interrupted.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2008-09-10 14:29:50 -05:00
parent 18452a6c51
commit f9be2334f7
2 changed files with 4 additions and 4 deletions

View File

@ -30,7 +30,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <unistd.h>
#include <errno.h>
/* libalpm */
@ -205,7 +204,7 @@ int SYMEXPORT alpm_trans_release()
/* unlock db */
if(handle->lckfd != -1) {
close(handle->lckfd);
while(close(handle->lckfd) == -1 && errno == EINTR);
handle->lckfd = -1;
}
if(_alpm_lckrm()) {
@ -576,7 +575,7 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
/* this code runs for the parent only (wait on the child) */
pid_t retpid;
int status;
retpid = waitpid(pid, &status, 0);
while((retpid = waitpid(pid, &status, 0)) == -1 && errno == EINTR);
if(retpid == -1) {
_alpm_log(PM_LOG_ERROR, _("call to waitpid failed (%s)\n"),
strerror(errno));

View File

@ -254,7 +254,8 @@ int _alpm_lckmk()
_alpm_makepath(dir);
FREE(dir);
fd = open(file, O_WRONLY | O_CREAT | O_EXCL, 0000);
while((fd = open(file, O_WRONLY | O_CREAT | O_EXCL, 0000)) == -1
&& errno == EINTR);
return(fd > 0 ? fd : -1);
}