From f9be2334f7b01ba30235500cb12d4ed61fff564b Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 10 Sep 2008 14:29:50 -0500 Subject: 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 --- lib/libalpm/trans.c | 5 ++--- lib/libalpm/util.c | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index d6b165d3..f996c02c 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -30,7 +30,6 @@ #include #include #include -#include #include /* 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)); diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index b26c9702..da3463b0 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -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); } -- cgit v1.2.3-70-g09d2 From f0e1846b51dfdeb095038b6b04d307ddfdec0029 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 10 Sep 2008 14:32:24 -0500 Subject: Remove unnecessary unistd.h header inclusion Signed-off-by: Dan McGee --- lib/libalpm/cache.c | 1 - lib/libalpm/conflict.c | 1 - lib/libalpm/db.c | 1 - lib/libalpm/package.c | 1 - 4 files changed, 4 deletions(-) (limited to 'lib') diff --git a/lib/libalpm/cache.c b/lib/libalpm/cache.c index 032cc978..10857792 100644 --- a/lib/libalpm/cache.c +++ b/lib/libalpm/cache.c @@ -19,7 +19,6 @@ #include "config.h" -#include #include #include #include diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c index a8bcdd59..a044fc60 100644 --- a/lib/libalpm/conflict.c +++ b/lib/libalpm/conflict.c @@ -25,7 +25,6 @@ #include #include -#include #include #include #include diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 191c8ba0..5632ffac 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -23,7 +23,6 @@ #include "config.h" -#include #include #include #include diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index eaef688d..a9f4b43d 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -30,7 +30,6 @@ #include #include #include -#include /* libarchive */ #include -- cgit v1.2.3-70-g09d2