Skip to Content.
Sympa Menu

freetds - Re: [freetds] look for all config files under $FREETDS

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: <samuel.ferencik AT barclays.com>
  • To: <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] look for all config files under $FREETDS
  • Date: Mon, 17 Feb 2014 13:10:49 +0000

[minor correction below - removing some extra dots in the documentation]

Currently there is no way to put locales.conf and pool.conf under a
non-constant path: FreeTDS always searches for them under the path compiled
into freetds_sysconfdir.h.

In contrast, we look for freetds.conf under $FREETDS.

Here is a patch that makes this possible for locales.conf and pool.conf as
well.

Sam

--- src\pool\config#1.c 2014-02-17 14:05:43.000000000 +-0100
+++ src\pool\config.c 2014-02-17 14:02:27.000000000 +-0100
@@ -46,21 +46,56 @@
#define POOL_STR_DATABASE "database"
#define POOL_STR_MAX_MBR_AGE "max member age"
#define POOL_STR_MAX_POOL_CONN "max pool conn"
#define POOL_STR_MIN_POOL_CONN "min pool conn"
#define POOL_STR_MAX_POOL_USERS "max pool users"

+#if !defined(_WIN32) && !defined(DOS32X)
+static const char pool_conf[] = "%s/etc/pool.conf";
+#else
+static const char pool_conf[] = "%s\\pool.conf";
+#endif
+
static void pool_parse(const char *option, const char *value, void *param);

+/**
+ * Get pool information based on configuration gathered from
+ * a) a readable file in $FREETDS/etc/pool.conf (or %FREETDS%\pool.conf on
+ * Windows)
+ * b) a readable file in [FREETDS_SYSCONFDIR]/pool.conf (as defined in
+ * freetds_sysconfdir.h)
+ *
+ * @return 0 on error
+ */
int
pool_read_conf_file(char *poolname, TDS_POOL * pool)
{
FILE *in;
int found = 0;
+ char *path = NULL;
+ char *eptr = NULL;

- in = fopen(FREETDS_POOLCONFFILE, "r");
+ tdsdump_log(TDS_DBG_INFO1, "Attempting to read pool.conf file\n");
+
+ /* FREETDS env var */
+ eptr = getenv("FREETDS");
+ if (eptr && asprintf(&path, pool_conf, eptr) >= 0) {
+ tdsdump_log(TDS_DBG_INFO2, "... trying $FREETDS.\n");
+ in = fopen(path, "r");
+ free(path);
+ }
+ else {
+ tdsdump_log(TDS_DBG_INFO2, "... $FREETDS not set.\n");
+ }
+
+ /* default */
+ if (!in) {
+ tdsdump_log(TDS_DBG_INFO2, "... trying %s.\n",
FREETDS_POOLCONFFILE);
+ in = fopen(FREETDS_POOLCONFFILE, "r");
+ }
+
if (in) {
fprintf(stderr, "Found conf file in %s reading sections\n",
FREETDS_POOLCONFFILE);
tds_read_conf_section(in, "global", pool_parse, pool);
rewind(in);
found = tds_read_conf_section(in, poolname, pool_parse, pool);
fclose(in);



--- src\tds\config#1.c 2014-02-17 13:57:04.000000000 +-0100
+++ src\tds\config.c 2014-02-17 14:01:59.000000000 +-0100
@@ -141,14 +141,17 @@
* tds_read_config_info() will fill the tds connection structure based on
configuration
* information gathered in the following order:
* 1) Program specified in TDSLOGIN structure
* 2) The environment variables TDSVER, TDSDUMP, TDSPORT, TDSQUERY, TDSHOST
* 3) A config file with the following search order:
* a) a readable file specified by environment variable FREETDSCONF
- * b) a readable file in ~/.freetds.conf
- * c) a readable file in $prefix/etc/freetds.conf
+ * b) a readable file in $FREETDS/etc/freetds.conf (or
%FREETDS%\freetds.conf
+ * on Windows)
+ * c) a readable file in ~/.freetds.conf
+ * d) a readable file in [FREETDS_SYSCONFDIR]/freetds.conf (as defined in
+ * freetds_sysconfdir.h)
* 3) ~/.interfaces if exists
* 4) $SYBASE/interfaces if exists
* 5) TDS_DEF_* default values
*
* .tdsrc and freetds.conf have been added to make the package easier to
* integration with various Linux and *BSD distributions.



--- src\tds\locale#1.c 2014-02-17 13:57:04.000000000 +-0100
+++ src\tds\locale.c 2014-02-17 13:49:14.000000000 +-0100
@@ -47,31 +47,60 @@

TDS_RCSID(var, "$Id: locale.c,v 1.30 2010/07/21 20:12:18 freddy77 Exp $");


static void tds_parse_locale(const char *option, const char *value, void
*param);

+#if !defined(_WIN32) && !defined(DOS32X)
+static const char locales_conf[] = "%s/etc/locales.conf";
+#else
+static const char locales_conf[] = "%s\\locales.conf";
+#endif
+
/**
- * Get locale information.
+ * Get locale information based on configuration gathered from
+ * a) a readable file in $FREETDS/etc/locales.conf (or
%FREETDS%\locales.conf on
+ * Windows)
+ * b) a readable file in [FREETDS_SYSCONFDIR]/locales.conf (as defined in
+ * freetds_sysconfdir.h)
+ *
* @return allocated structure with all information or NULL if error
*/
TDSLOCALE *
tds_get_locale(void)
{
TDSLOCALE *locale;
char *s;
FILE *in;
+ char *path = NULL;
+ char *eptr = NULL;

/* allocate a new structure with hard coded and build-time defaults */
locale = tds_alloc_locale();
if (!locale)
return NULL;

tdsdump_log(TDS_DBG_INFO1, "Attempting to read locales.conf file\n");

- in = fopen(FREETDS_LOCALECONFFILE, "r");
+ /* FREETDS env var */
+ eptr = getenv("FREETDS");
+ if (eptr && asprintf(&path, locales_conf, eptr) >= 0) {
+ tdsdump_log(TDS_DBG_INFO2, "... trying $FREETDS.\n");
+ in = fopen(path, "r");
+ free(path);
+ }
+ else {
+ tdsdump_log(TDS_DBG_INFO2, "... $FREETDS not set.\n");
+ }
+
+ /* default */
+ if (!in) {
+ tdsdump_log(TDS_DBG_INFO2, "... trying %s.\n",
FREETDS_LOCALECONFFILE);
+ in = fopen(FREETDS_LOCALECONFFILE, "r");
+ }
+
if (in) {
tds_read_conf_section(in, "default", tds_parse_locale, locale);

#if HAVE_LOCALE_H
s = setlocale(LC_ALL, NULL);
#else

_______________________________________________

This message is for information purposes only, it is not a recommendation,
advice, offer or solicitation to buy or sell a product or service nor an
official confirmation of any transaction. It is directed at persons who are
professionals and is not intended for retail customer use. Intended for
recipient only. This message is subject to the terms at:
www.barclays.com/emaildisclaimer.

For important disclosures, please see:
www.barclays.com/salesandtradingdisclaimer regarding market commentary from
Barclays Sales and/or Trading, who are active market participants; and in
respect of Barclays Research, including disclosures relating to specific
issuers, please see http://publicresearch.barclays.com.

_______________________________________________




Archive powered by MHonArc 2.6.24.

Top of Page