2 * UDP Gateway persistent configuration pathname detection
3 * Copyright (C) 2005 Jan Kratochvil <project-udpgate@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <glib/gmessages.h>
23 #include <glib/gmem.h>
24 #include <glib/gstrfuncs.h>
29 #include "configuration-pathname.h" /* self */
32 /* OK, GConf would be nice.
33 * Unfortunately the fully-static build does not support GConf process spawn at
34 * all. Also /etc/sysconfig directory is standard for the daemon services.
38 static const gchar *static_pathname;
39 static gboolean verbose=FALSE;
42 static gboolean try_pairname(const gchar *dirname,const gchar *filename)
46 g_return_val_if_fail(dirname!=NULL,FALSE);
47 g_return_val_if_fail(filename!=NULL,FALSE);
51 if (access(dirname,W_OK|X_OK)) {
53 g_warning(_("Configuration directory not accessible(X) and/or writable(W): %s"),dirname);
56 pathname=g_strdup_printf("%s/%s",dirname,filename);
57 if (access(pathname,R_OK|W_OK) && errno!=ENOENT) {
59 g_warning(_("Configuration pathname not readable(R) and/or writable(W): %s"),pathname);
63 static_pathname=pathname;
67 G_CONST_RETURN gchar *configuration_pathname(void)
69 const gchar *home_val;
70 static gboolean first=TRUE;
72 if (!static_pathname && first) {
73 try_pairname(G_STRINGIFY(SYSCONFDIR) "/sysconfig",PACKAGE);
74 try_pairname(G_STRINGIFY(SYSCONFDIR) "/default",PACKAGE);
75 try_pairname(G_STRINGIFY(SYSCONFDIR) "",PACKAGE);
76 if ((home_val=getenv("HOME")))
77 try_pairname(home_val,"." PACKAGE "rc");
78 if (!static_pathname && !verbose) {
80 configuration_pathname();
81 g_warning(_("All automatic configuration pathnames failed; configuration persistency disabled."));
85 return static_pathname;