[PATCH v4 2/3] xfree86: Use xorg.conf.d directory for multiple config files

Dan Nicholson dbn.lists at gmail.com
Mon Dec 21 19:15:57 PST 2009


On Mon, Dec 21, 2009 at 3:05 PM, Julien Cristau <jcristau at debian.org> wrote:
> On Mon, Dec 21, 2009 at 12:35:08 -0800, Dan Nicholson wrote:
>
>> +/*
>> + * Given some searching parameters, locate and open the xorg config
>> + * directory. The directory does not need to contain config files.
>> + */
>> +static char *
>> +OpenConfigDir(const char *path, const char *projroot, const char *confname)
>> +{
>> +     char *dirpath, *pathcopy;
>> +     const char *template;
>> +     Bool found = FALSE;
>> +
>> +     pathcopy = strdup(path);
>> +     for (template = strtok(pathcopy, ","); template && !found;
>
> would removing this "&& !found" be enough to make multiple xorg.conf.d
> directories work?  It'd be nice to have both /usr/share/X11/xorg.conf.d
> and /etc/X11/xorg.conf.d, with the latter overriding the former…

No, it would be more complicated than that. What the !found does do is
prevent segfaults when the directory is empty. The caller only expects
to receive one directory path back. When it does, it proceeds to call
xf86readConfigFile instead of returning and triggering autoconfig
mode. Now, xf86readConfigFile should be fixed to not segfault when
there are not actually files to read, but that still doesn't fix the
expected behavior of the code that we return one directory when there
are actually .conf files present.

In order to have a second directory used, we would probably want to
add a second entry point. All the code in parser/scan.c revolves
around finding a single path. We could have xf86openConfigDirFiles and
xf86openSystemConfigDirFiles (or something) where they have different
templates. Or, we could just call xf86openConfigDirFiles twice with
different templates. It will just keep adding files till we max out
the array (currently a hard-coded and possibly too small 64 files). We
just have to keep the behavior that if no config files are found, we
return NULL to the caller to signal that.

>> +          template = strtok(NULL, ",")) {
>> +             struct dirent **list = NULL;
>> +             int num;
>> +
>> +             if (!(dirpath = DoSubstitution(template, NULL, projroot,
>> +                                            NULL, NULL, confname)))
>> +                     continue;
>> +             /* match files named *.conf */
>> +             num = scandir(dirpath, &list, ConfigFilter, alphasort);
>> +             found = AddConfigDirFiles(dirpath, list, num);
>> +             if (!found) {
>> +                     free(dirpath);
>> +                     dirpath = NULL;
>> +                     if (list)
>> +                             free(list);
>> +             }
>> +     }
>> +
>> +     return dirpath;
>> +}
>> +

Thanks.

--
Dan


More information about the xorg-devel mailing list