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:
parent
a57b2f233f
commit
a71b943a09
1 changed files with 20 additions and 0 deletions
|
@ -31,6 +31,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <mcheck.h> /* debug tracing (mtrace) */
|
#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.
|
* @brief Catches thrown signals.
|
||||||
* Performs necessary cleanup to ensure database is in a consistant
|
* Performs necessary cleanup to ensure database is in a consistant
|
||||||
|
@ -462,6 +479,9 @@ int main(int argc, char *argv[])
|
||||||
/* i18n init */
|
/* i18n init */
|
||||||
localize();
|
localize();
|
||||||
|
|
||||||
|
/* set user agent for downloading */
|
||||||
|
setuseragent();
|
||||||
|
|
||||||
/* init config data */
|
/* init config data */
|
||||||
config = config_new();
|
config = config_new();
|
||||||
config->op = PM_OP_MAIN;
|
config->op = PM_OP_MAIN;
|
||||||
|
|
Loading…
Add table
Reference in a new issue