示例#1
0
/*
 *	set_pglocale_pgservice
 *
 *	Set application-specific locale and service directory
 *
 *	This function takes the value of argv[0] rather than a full path.
 *
 * (You may be wondering why this is in exec.c.  It requires this module's
 * services and doesn't introduce any new dependencies, so this seems as
 * good as anyplace.)
 */
void
set_pglocale_pgservice(const char *argv0, const char *app)
{
	char		path[MAXPGPATH];
	char		my_exec_path[MAXPGPATH];
	char		env_path[MAXPGPATH + sizeof("PGSYSCONFDIR=")];	/* longer than
																 * PGLOCALEDIR */
	char	   *dup_path;

	/* don't set LC_ALL in the backend */
	if (strcmp(app, PG_TEXTDOMAIN("postgres")) != 0)
	{
		setlocale(LC_ALL, "");

		/*
		 * One could make a case for reproducing here PostmasterMain()'s test
		 * for whether the process is multithreaded.  Unlike the postmaster,
		 * no frontend program calls sigprocmask() or otherwise provides for
		 * mutual exclusion between signal handlers.  While frontends using
		 * fork(), if multithreaded, are formally exposed to undefined
		 * behavior, we have not witnessed a concrete bug.  Therefore,
		 * complaining about multithreading here may be mere pedantry.
		 */
	}

	if (find_my_exec(argv0, my_exec_path) < 0)
		return;

#ifdef ENABLE_NLS
	get_locale_path(my_exec_path, path);
	bindtextdomain(app, path);
	textdomain(app);

	if (getenv("PGLOCALEDIR") == NULL)
	{
		/* set for libpq to use */
		snprintf(env_path, sizeof(env_path), "PGLOCALEDIR=%s", path);
		canonicalize_path(env_path + 12);
		dup_path = strdup(env_path);
		if (dup_path)
			putenv(dup_path);
	}
#endif

	if (getenv("PGSYSCONFDIR") == NULL)
	{
		get_etc_path(my_exec_path, path);

		/* set for libpq to use */
		snprintf(env_path, sizeof(env_path), "PGSYSCONFDIR=%s", path);
		canonicalize_path(env_path + 13);
		dup_path = strdup(env_path);
		if (dup_path)
			putenv(dup_path);
	}
}
示例#2
0
static void
show_localedir(bool all)
{
	char		path[MAXPGPATH];

	if (all)
		printf("LOCALEDIR = ");
	get_locale_path(mypath, path);
	cleanup_path(path);
	printf("%s\n", path);
}
示例#3
0
/*
 *	set_pglocale_pgservice
 *
 *	Set application-specific locale and service directory
 *
 *	This function takes an argv[0] rather than a full path.
 */
void
set_pglocale_pgservice(const char *argv0, const char *app)
{
	char		path[MAXPGPATH];
	char		my_exec_path[MAXPGPATH];
	char		env_path[MAXPGPATH + sizeof("PGSYSCONFDIR=")];	/* longer than
																 * PGLOCALEDIR */

	/* don't set LC_ALL in the backend */
	if (strcmp(app, "postgres") != 0)
		setlocale(LC_ALL, "");

	if (find_my_exec(argv0, my_exec_path) < 0)
		return;

#ifdef ENABLE_NLS
	get_locale_path(my_exec_path, path);
	bindtextdomain(app, path);
	textdomain(app);

	if (getenv("PGLOCALEDIR") == NULL)
	{
		/* set for libpq to use */
		snprintf(env_path, sizeof(env_path), "PGLOCALEDIR=%s", path);
		canonicalize_path(env_path + 12);
		putenv(strdup(env_path));
	}
#endif

	if (getenv("PGSYSCONFDIR") == NULL)
	{
		get_etc_path(my_exec_path, path);

		/* set for libpq to use */
		snprintf(env_path, sizeof(env_path), "PGSYSCONFDIR=%s", path);
		canonicalize_path(env_path + 13);
		putenv(strdup(env_path));
	}
}
示例#4
0
/*
 * get_configdata(const char *my_exec_path, size_t *configdata_len)
 *
 * Get configure-time constants. The caller is responsible
 * for pfreeing the result.
 */
ConfigData *
get_configdata(const char *my_exec_path, size_t *configdata_len)
{
	ConfigData *configdata;
	char		path[MAXPGPATH];
	char	   *lastsep;
	int			i = 0;

	/* Adjust this to match the number of items filled below */
	*configdata_len = 23;
	configdata = (ConfigData *) palloc(*configdata_len * sizeof(ConfigData));

	configdata[i].name = pstrdup("BINDIR");
	strlcpy(path, my_exec_path, sizeof(path));
	lastsep = strrchr(path, '/');
	if (lastsep)
		*lastsep = '\0';
	cleanup_path(path);
	configdata[i].setting = pstrdup(path);
	i++;

	configdata[i].name = pstrdup("DOCDIR");
	get_doc_path(my_exec_path, path);
	cleanup_path(path);
	configdata[i].setting = pstrdup(path);
	i++;

	configdata[i].name = pstrdup("HTMLDIR");
	get_html_path(my_exec_path, path);
	cleanup_path(path);
	configdata[i].setting = pstrdup(path);
	i++;

	configdata[i].name = pstrdup("INCLUDEDIR");
	get_include_path(my_exec_path, path);
	cleanup_path(path);
	configdata[i].setting = pstrdup(path);
	i++;

	configdata[i].name = pstrdup("PKGINCLUDEDIR");
	get_pkginclude_path(my_exec_path, path);
	cleanup_path(path);
	configdata[i].setting = pstrdup(path);
	i++;

	configdata[i].name = pstrdup("INCLUDEDIR-SERVER");
	get_includeserver_path(my_exec_path, path);
	cleanup_path(path);
	configdata[i].setting = pstrdup(path);
	i++;

	configdata[i].name = pstrdup("LIBDIR");
	get_lib_path(my_exec_path, path);
	cleanup_path(path);
	configdata[i].setting = pstrdup(path);
	i++;

	configdata[i].name = pstrdup("PKGLIBDIR");
	get_pkglib_path(my_exec_path, path);
	cleanup_path(path);
	configdata[i].setting = pstrdup(path);
	i++;

	configdata[i].name = pstrdup("LOCALEDIR");
	get_locale_path(my_exec_path, path);
	cleanup_path(path);
	configdata[i].setting = pstrdup(path);
	i++;

	configdata[i].name = pstrdup("MANDIR");
	get_man_path(my_exec_path, path);
	cleanup_path(path);
	configdata[i].setting = pstrdup(path);
	i++;

	configdata[i].name = pstrdup("SHAREDIR");
	get_share_path(my_exec_path, path);
	cleanup_path(path);
	configdata[i].setting = pstrdup(path);
	i++;

	configdata[i].name = pstrdup("SYSCONFDIR");
	get_etc_path(my_exec_path, path);
	cleanup_path(path);
	configdata[i].setting = pstrdup(path);
	i++;

	configdata[i].name = pstrdup("PGXS");
	get_pkglib_path(my_exec_path, path);
	strlcat(path, "/pgxs/src/makefiles/pgxs.mk", sizeof(path));
	cleanup_path(path);
	configdata[i].setting = pstrdup(path);
	i++;

	configdata[i].name = pstrdup("CONFIGURE");
#ifdef VAL_CONFIGURE
	configdata[i].setting = pstrdup(VAL_CONFIGURE);
#else
	configdata[i].setting = pstrdup(_("not recorded"));
#endif
	i++;

	configdata[i].name = pstrdup("CC");
#ifdef VAL_CC
	configdata[i].setting = pstrdup(VAL_CC);
#else
	configdata[i].setting = pstrdup(_("not recorded"));
#endif
	i++;

	configdata[i].name = pstrdup("CPPFLAGS");
#ifdef VAL_CPPFLAGS
	configdata[i].setting = pstrdup(VAL_CPPFLAGS);
#else
	configdata[i].setting = pstrdup(_("not recorded"));
#endif
	i++;

	configdata[i].name = pstrdup("CFLAGS");
#ifdef VAL_CFLAGS
	configdata[i].setting = pstrdup(VAL_CFLAGS);
#else
	configdata[i].setting = pstrdup(_("not recorded"));
#endif
	i++;

	configdata[i].name = pstrdup("CFLAGS_SL");
#ifdef VAL_CFLAGS_SL
	configdata[i].setting = pstrdup(VAL_CFLAGS_SL);
#else
	configdata[i].setting = pstrdup(_("not recorded"));
#endif
	i++;

	configdata[i].name = pstrdup("LDFLAGS");
#ifdef VAL_LDFLAGS
	configdata[i].setting = pstrdup(VAL_LDFLAGS);
#else
	configdata[i].setting = pstrdup(_("not recorded"));
#endif
	i++;

	configdata[i].name = pstrdup("LDFLAGS_EX");
#ifdef VAL_LDFLAGS_EX
	configdata[i].setting = pstrdup(VAL_LDFLAGS_EX);
#else
	configdata[i].setting = pstrdup(_("not recorded"));
#endif
	i++;

	configdata[i].name = pstrdup("LDFLAGS_SL");
#ifdef VAL_LDFLAGS_SL
	configdata[i].setting = pstrdup(VAL_LDFLAGS_SL);
#else
	configdata[i].setting = pstrdup(_("not recorded"));
#endif
	i++;

	configdata[i].name = pstrdup("LIBS");
#ifdef VAL_LIBS
	configdata[i].setting = pstrdup(VAL_LIBS);
#else
	configdata[i].setting = pstrdup(_("not recorded"));
#endif
	i++;

	configdata[i].name = pstrdup("VERSION");
	configdata[i].setting = pstrdup("PostgreSQL " PG_VERSION);
	i++;

	Assert(i == *configdata_len);

	return configdata;
}