From a71b943a09091438aaf240d513622f44d6728d6f Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 28 Apr 2007 04:50:16 -0400 Subject: Set HTTP_USER_AGENT envvar in pacman Instead of using libdownload's default user agent string, make one of our own. Format: Pacman/3.0.1 (Linux i686 2.6.21-rc7-ARCH; en_US.utf8) libalpm/1.0.0 Signed-off-by: Dan McGee --- src/pacman/pacman.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 8f640c8e..1f5c5aed 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include /* debug tracing (mtrace) */ @@ -190,6 +191,22 @@ static void localize(void) } } +/** + * @brief Set user agent environment variable. + */ +static void setuseragent(void) +{ + const char *pacman = "Pacman/" PACKAGE_VERSION; + const char *libalpm = "libalpm/" LIB_VERSION; + char agent[101]; + struct utsname un; + + uname(&un); + snprintf(agent, 100, "%s (%s %s %s; %s) %s", pacman, un.sysname, + un.machine, un.release, setlocale(LC_MESSAGES, NULL), libalpm); + setenv("HTTP_USER_AGENT", agent, 0); +} + /** * @brief Catches thrown signals. * Performs necessary cleanup to ensure database is in a consistant @@ -462,6 +479,9 @@ int main(int argc, char *argv[]) /* i18n init */ localize(); + /* set user agent for downloading */ + setuseragent(); + /* init config data */ config = config_new(); config->op = PM_OP_MAIN; -- cgit v1.2.3-24-g4f1b