with an entry having a null <structfield>keyword</> pointer. The
null pointer is returned if memory could not be allocated. Note that
the current default values (<structfield>val</structfield> fields)
- will depend on environment variables and other context. Callers
+ will depend on environment variables and other context. A
+ missing or invalid service file will be silently ignored. Callers
must treat the connection options data as read-only.
</para>
connOptions = conninfo_init(&errorBuf);
if (connOptions != NULL)
{
- if (!conninfo_add_defaults(connOptions, &errorBuf))
+ /* pass NULL errorBuf to ignore errors */
+ if (!conninfo_add_defaults(connOptions, NULL))
{
PQconninfoFree(connOptions);
connOptions = NULL;
*
* Defaults are obtained from a service file, environment variables, etc.
*
- * Returns TRUE if successful, otherwise FALSE; errorMessage is filled in
- * upon failure. Note that failure to locate a default value is not an
- * error condition here --- we just leave the option's value as NULL.
+ * Returns TRUE if successful, otherwise FALSE; errorMessage, if supplied,
+ * is filled in upon failure. Note that failure to locate a default value
+ * is not an error condition here --- we just leave the option's value as
+ * NULL.
*/
static bool
conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage)
/*
* If there's a service spec, use it to obtain any not-explicitly-given
- * parameters.
+ * parameters. Ignore error if no error message buffer is passed
+ * because there is no way to pass back the failure message.
*/
- if (parseServiceInfo(options, errorMessage) != 0)
+ if (parseServiceInfo(options, errorMessage) != 0 && errorMessage)
return false;
/*
option->val = strdup(tmp);
if (!option->val)
{
- printfPQExpBuffer(errorMessage,
- libpq_gettext("out of memory\n"));
+ if (errorMessage)
+ printfPQExpBuffer(errorMessage,
+ libpq_gettext("out of memory\n"));
return false;
}
continue;
option->val = strdup(option->compiled);
if (!option->val)
{
- printfPQExpBuffer(errorMessage,
- libpq_gettext("out of memory\n"));
+ if (errorMessage)
+ printfPQExpBuffer(errorMessage,
+ libpq_gettext("out of memory\n"));
return false;
}
continue;
*/
if (strcmp(option->keyword, "user") == 0)
{
- option->val = pg_fe_getauthname(errorMessage);
+ option->val = pg_fe_getauthname();
continue;
}
}