summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-04-28 04:50:16 -0400
committerDan McGee <dan@archlinux.org>2007-04-28 05:25:05 -0400
commita71b943a09091438aaf240d513622f44d6728d6f (patch)
treef5402e93daf64b7fb4c7ae273c60a3575b33ad04
parenta57b2f233f28c275b0b171cb291415351f9ec87d (diff)
downloadpacman-a71b943a09091438aaf240d513622f44d6728d6f.tar.xz
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 <dan@archlinux.org>
-rw-r--r--src/pacman/pacman.c20
1 files changed, 20 insertions, 0 deletions
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 <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/utsname.h>
#include <libintl.h>
#include <locale.h>
#include <mcheck.h> /* debug tracing (mtrace) */
@@ -191,6 +192,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
* state.
@@ -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;