On Wed, Mar 26, 2014 at 01:53:55PM -0400, Andrew Hills wrote:
Please find below a revised patch, now including alpm_options_set/get functions, documentation updates, and repaired indentation. I tested this the same way as the previous patch: by building it with makepkg and installing it on my system and using it. This means I haven't tested the alpm_options_set/get functions. I wasn't sure what to return for an invalid handle in alpm_option_get, but -1 looked to be the standard elsewhere in the file for this type.
What do you plan to set these values to in your environment? Why shouldn't we just adjust these to be more lax?
Thanks, Andrew
From 26ac679398d206338d625774ece69132fd369359 Mon Sep 17 00:00:00 2001 From: Andrew Hills <ahills@ednos.net> Date: Wed, 19 Mar 2014 14:03:30 -0400 Subject: [PATCH] Add LowSpeedLimit and LowSpeedTime configuration options to correspond to libcurl's CURLOPT_LOW_SPEED_LIMIT and CURLOPT_LOW_SPEED_TIME options.
Signed-off-by: Andrew Hills <ahills@ednos.net> --- doc/pacman.conf.5.txt | 14 ++++++++++++++ etc/pacman.conf.in | 2 ++ lib/libalpm/alpm.h | 10 ++++++++++ lib/libalpm/dload.c | 4 ++-- lib/libalpm/handle.c | 26 ++++++++++++++++++++++++++ lib/libalpm/handle.h | 4 ++++ src/pacman/conf.c | 24 ++++++++++++++++++++++++ src/pacman/conf.h | 5 +++++ 8 files changed, 87 insertions(+), 2 deletions(-)
diff --git a/doc/pacman.conf.5.txt b/doc/pacman.conf.5.txt index f19311c..3e70573 100644 --- a/doc/pacman.conf.5.txt +++ b/doc/pacman.conf.5.txt @@ -199,6 +199,20 @@ Options Displays name, version and size of target packages formatted as a table for upgrade, sync and remove operations.
+*LowSpeedLimit* = speed:: + Sets the speed in bytes per second that a download should be below during + `LowSpeedTime` seconds to abort the transfer for being too slow. Setting + 'speed' to 0 or a negative number will disable the speed check. Defaults to + 1 byte per second. Note that this option will not affect external programs + specified by `XferCommand`. + +*LowSpeedTime* = time:: + Sets the time in seconds that a download should be below the `LowSpeedLimit` + transfer speed to abort the transfer for being too slow. Setting 'time' to + 0 will disable the speed check. Setting 'time' to a negative number will + cause all downloads to fail. Defaults to 10 seconds. Note that this option + will not affect external programs specified by `XferCommand`. + Repository Sections ------------------- Each repository section defines a section name and at least one location where diff --git a/etc/pacman.conf.in b/etc/pacman.conf.in index b891de1..0bc5908 100644 --- a/etc/pacman.conf.in +++ b/etc/pacman.conf.in @@ -20,6 +20,8 @@ HoldPkg = pacman glibc #CleanMethod = KeepInstalled #UseDelta = 0.7 Architecture = auto +#LowSpeedLimit = 1 +#LowSpeedTime = 10
# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup #IgnorePkg = diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index b0adb95..e8cea12 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -595,6 +595,16 @@ const char *alpm_option_get_dbpath(alpm_handle_t *handle); /** Get the name of the database lock file. Read-only. */ const char *alpm_option_get_lockfile(alpm_handle_t *handle);
+/** Returns the libcurl low speed limit. */ +long alpm_option_get_lowspeedlimit(alpm_handle_t *handle); +/** Sets the libcurl low speed limit. */ +int alpm_option_set_lowspeedlimit(alpm_handle_t *handle, long lowspeedlimit);
What is this measured in ? bytes? megabytes? mebibytes?
+ +/** Returns the libcurl low speed time. */ +long alpm_option_get_lowspeedtime(alpm_handle_t *handle); +/** Sets the libcurl low speed time. */ +int alpm_option_set_lowspeedtime(alpm_handle_t *handle, long lowspeedtime); +
seconds? milliseconds? hours?
/** @name Accessors to the list of package cache directories. * @{ */ diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 53867f5..31edbf4 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -294,8 +294,8 @@ static void curl_set_handle_opts(struct dload_payload *payload, curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, dload_progress_cb); curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, (void *)payload); - curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1L); - curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L); + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, handle->lowspeedlimit); + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, handle->lowspeedtime); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, dload_parseheader_cb); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, (void *)payload); curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL); diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 0842d51..d0cd01c 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -198,6 +198,18 @@ const char SYMEXPORT *alpm_option_get_lockfile(alpm_handle_t *handle) return handle->lockfile; }
+long SYMEXPORT alpm_option_get_lowspeedlimit(alpm_handle_t *handle) +{ + CHECK_HANDLE(handle, return -1); + return handle->lowspeedlimit; +} + +long SYMEXPORT alpm_option_get_lowspeedtime(alpm_handle_t *handle) +{ + CHECK_HANDLE(handle, return -1); + return handle->lowspeedtime; +} + const char SYMEXPORT *alpm_option_get_gpgdir(alpm_handle_t *handle) { CHECK_HANDLE(handle, return NULL); @@ -294,6 +306,20 @@ int SYMEXPORT alpm_option_set_progresscb(alpm_handle_t *handle, alpm_cb_progress return 0; }
+int SYMEXPORT alpm_option_set_lowspeedlimit(alpm_handle_t *handle, long lowspeedlimit) +{ + CHECK_HANDLE(handle, return -1); + handle->lowspeedlimit = lowspeedlimit; + return 0; +} + +int SYMEXPORT alpm_option_set_lowspeedtime(alpm_handle_t *handle, long lowspeedtime) +{ + CHECK_HANDLE(handle, return -1); + handle->lowspeedtime = lowspeedtime; + return 0; +} + static char *canonicalize_path(const char *path) { char *new_path; diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index 27241ea..25a51ff 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -104,6 +104,10 @@ struct __alpm_handle_t { /* for delta parsing efficiency */ int delta_regex_compiled; regex_t delta_regex; + + /* Curl timeouts */ + long lowspeedlimit; + long lowspeedtime; };
alpm_handle_t *_alpm_handle_new(void); diff --git a/src/pacman/conf.c b/src/pacman/conf.c index f75f3a7..7916a1d 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -120,6 +120,9 @@ config_t *config_new(void) newconfig->colstr.err = ""; newconfig->colstr.nocolor = "";
+ newconfig->lowspeedlimit = 1L; + newconfig->lowspeedtime = 10L; + return newconfig; }
@@ -596,6 +599,24 @@ static int _parse_options(const char *key, char *value, return 1; } FREELIST(values); + } else if(strcmp(key, "LowSpeedLimit") == 0) { + config->lowspeedlimit = strtol(value, NULL, 0); + if((config->lowspeedlimit == LONG_MAX || config->lowspeedlimit == LONG_MIN) && errno == ERANGE) { + pm_printf(ALPM_LOG_WARNING, + _("config file %s, line %d: LowSpeedLimit overflow, using default.\n"), + file, linenum); + config->lowspeedlimit = 1L; + } + pm_printf(ALPM_LOG_DEBUG, "config: lowspeedlimit: %ld\n", config->lowspeedlimit); + } else if(strcmp(key, "LowSpeedTime") == 0) { + config->lowspeedtime = strtol(value, NULL, 0); + if((config->lowspeedtime == LONG_MAX || config->lowspeedtime == LONG_MIN) && errno == ERANGE) { + pm_printf(ALPM_LOG_WARNING, + _("config file %s, line %d: LowSpeedTime overflow, using default.\n"), + file, linenum); + config->lowspeedtime = 10L; + } + pm_printf(ALPM_LOG_DEBUG, "config: lowspeedtime: %lu\n", config->lowspeedtime); } else { pm_printf(ALPM_LOG_WARNING, _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"), @@ -690,6 +711,9 @@ static int setup_libalpm(void) alpm_option_set_questioncb(handle, cb_question); alpm_option_set_progresscb(handle, cb_progress);
+ handle->lowspeedlimit = config->lowspeedlimit; + handle->lowspeedtime = config->lowspeedtime; +
Not sure how this compiles -- the internals of the handle aren't visible from the frontend code. You need to use the setter methods you added.
config->logfile = config->logfile ? config->logfile : strdup(LOGFILE); ret = alpm_option_set_logfile(handle, config->logfile); if(ret != 0) { diff --git a/src/pacman/conf.h b/src/pacman/conf.h index e8cac50..6ab8b52 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -21,6 +21,7 @@ #define _PM_CONF_H
#include <alpm.h> +#include <handle.h>
typedef struct __colstr_t { const char *colon; @@ -113,6 +114,10 @@ typedef struct __config_t {
/* Color strings for output */ colstr_t colstr; + + /* Curl timeouts */ + long lowspeedlimit; + long lowspeedtime; } config_t;
/* Operations */ -- 1.9.0