diff options
author | Dan McGee <dan@archlinux.org> | 2008-10-31 19:40:55 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2008-10-31 19:46:13 -0500 |
commit | 43f9eb1aa95d78a1560e30536a05525f2b18de0d (patch) | |
tree | 5addf29cea2778774f47389f1d5abda68570f3c8 /lib/libalpm | |
parent | 8d4e1e67546bcc04b5412e0f94a752c7215fb53d (diff) |
Set SIGPIPE handler to SIG_IGN when downloading
We don't want a failed write to kill our whole program when we are
downloading things, so set the SIGPIPE handler to ignore when downloading
and restore any previous signal handler when we complete the download.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm')
-rw-r--r-- | lib/libalpm/dload.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index e4a8a0b0..f197d060 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -24,6 +24,7 @@ #include <errno.h> #include <string.h> #include <unistd.h> +#include <signal.h> #include <limits.h> /* the following two are needed on BSD for libfetch */ #if defined(HAVE_SYS_SYSLIMITS_H) @@ -115,6 +116,7 @@ static int download_internal(const char *url, const char *localpath, size_t dl_thisfile = 0; char *tempfile, *destfile, *filename; int ret = 0; + struct sigaction new_action, old_action; struct url *fileurl = url_for_string(url); if(!fileurl) { @@ -148,6 +150,13 @@ static int download_internal(const char *url, const char *localpath, /* 10s timeout - TODO make a config option */ fetchTimeout = 10000; + /* ignore any SIGPIPE signals- these may occur if our FTP socket dies or + * something along those lines. Store the old signal handler first. */ + new_action.sa_handler = SIG_IGN; + sigemptyset(&new_action.sa_mask); + sigaction(SIGPIPE, NULL, &old_action); + sigaction(SIGPIPE, &new_action, NULL); + dlf = fetchXGet(fileurl, &ust, (handle->nopassiveftp ? "" : "p")); if(fetchLastErrCode != 0 || dlf == NULL) { @@ -238,6 +247,9 @@ static int download_internal(const char *url, const char *localpath, ret = 0; cleanup: + /* restore any existing SIGPIPE signal handler */ + sigaction(SIGPIPE, &old_action, NULL); + FREE(tempfile); FREE(destfile); if(localf != NULL) { |