tags 562033 + patch
thanks

* Sebastian Andrzej Siewior | 2010-01-14 22:20:16 [+0100]:

>Let me look why there is NULL pointer passed to open() because this does
>not look right anyway.
I did not have a dot config file. This patch should fix this.

>From a4dee52cc70dbb424466a4d6736b3fbfd354ec5e Mon Sep 17 00:00:00 2001
From: Sebastian Andrzej Siewior <sebast...@breakpoint.cc>
Date: Thu, 14 Jan 2010 22:44:35 +0100
Subject: [PATCH] Use a default config file if the user does not have one

The "old" behavior was to look for the config only in one spot. With
XtResolvePathname() one config out of a few may be choosen (depending on
language settings for instance). However a NULL pointer will be returned if
none of those files exist.
This patch will come up with a default file for the user config if it does not
exist.

Signed-off-by: Sebastian Andrzej Siewior <sebast...@breakpoint.cc>
---
 resource.c |   27 +++++++++++++++++++++++----
 1 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/resource.c b/resource.c
index c46059a..8339bdc 100644
--- a/resource.c
+++ b/resource.c
@@ -558,9 +558,7 @@ GetConfig(Display *dpy, XXkbConfig *conf)
        char *homedir, *filename;
        char *str_list, *res_app_list, res_ctrls[256];
        int i, j;
-#ifndef XT_RESOURCE_SEARCH
        size_t len;
-#endif
 
        /*
         * Init pixbuf engine
@@ -587,7 +585,10 @@ GetConfig(Display *dpy, XXkbConfig *conf)
        }
        sprintf(filename, "%s/%s", APPDEFDIR, APPDEFFILE);
 #endif
-       db = XrmGetFileDatabase(filename);
+       if (filename)
+               db = XrmGetFileDatabase(filename);
+       else
+               db = NULL;
        if (db == NULL) {
                /*
                 * this situation is not fatal if the user has all
@@ -618,12 +619,30 @@ GetConfig(Display *dpy, XXkbConfig *conf)
        /*
         * merge settings
         */
-       stat = XrmCombineFileDatabase(filename, &db, True);
+       if (filename)
+               stat = XrmCombineFileDatabase(filename, &db, True);
+       else
+               stat = NULL;
        if (stat == 0 && db == NULL) {
                /* failed */
                warnx("Unable to find configuration data");
                return 5;
        }
+
+       if (!filename) {
+               /*
+                * In case the user did not have a config file we have to come
+                * up with one
+                */
+               len = strlen(homedir) + 1 + strlen(USERDEFFILE);
+               filename = malloc(len + 1);
+               if (filename == NULL) {
+                       warn(NULL);
+                       XrmDestroyDatabase(db);
+                       return 1;
+               }
+               sprintf(filename, "%s/%s", homedir, USERDEFFILE);
+       }
        /*
         * start with the conf object
         */
-- 
1.6.6




-- 
To UNSUBSCRIBE, email to debian-bugs-rc-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to