1
0
mirror of https://github.com/moparisthebest/pacman synced 2025-01-10 21:38:19 -05:00

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>
This commit is contained in:
Dan McGee 2007-04-28 04:50:16 -04:00
parent a57b2f233f
commit a71b943a09

View File

@ -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) */
@ -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;