summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;