xfree86: Allow config directory to be specified on command line
Add a new command line parameter, -configdir, to specify the config directory to be used. Rules are the same as -config for root vs. user privileges. Signed-off-by: Dan Nicholson <dbn.lists@gmail.com> Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
This commit is contained in:
parent
efa5269f23
commit
592b20c517
|
@ -95,8 +95,18 @@ extern DeviceAssocRec mouse_assoc;
|
||||||
"%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
|
"%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
|
||||||
"%P/lib/X11/%X"
|
"%P/lib/X11/%X"
|
||||||
#endif
|
#endif
|
||||||
#ifndef CONFIGDIRPATH
|
#ifndef ROOT_CONFIGDIRPATH
|
||||||
#define CONFIGDIRPATH "/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \
|
#define ROOT_CONFIGDIRPATH "%A," "%R," \
|
||||||
|
"/etc/X11/%R," "%P/etc/X11/%R," \
|
||||||
|
"/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \
|
||||||
|
"%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \
|
||||||
|
"%P/etc/X11/%X," \
|
||||||
|
"%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
|
||||||
|
"%P/lib/X11/%X"
|
||||||
|
#endif
|
||||||
|
#ifndef USER_CONFIGDIRPATH
|
||||||
|
#define USER_CONFIGDIRPATH "/etc/X11/%S," "%P/etc/X11/%S," \
|
||||||
|
"/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \
|
||||||
"%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \
|
"%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \
|
||||||
"%P/etc/X11/%X," \
|
"%P/etc/X11/%X," \
|
||||||
"%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
|
"%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
|
||||||
|
@ -2397,35 +2407,48 @@ ConfigStatus
|
||||||
xf86HandleConfigFile(Bool autoconfig)
|
xf86HandleConfigFile(Bool autoconfig)
|
||||||
{
|
{
|
||||||
const char *filename, *dirname;
|
const char *filename, *dirname;
|
||||||
char *searchpath;
|
char *filesearch, *dirsearch;
|
||||||
MessageType from = X_DEFAULT;
|
MessageType filefrom = X_DEFAULT;
|
||||||
|
MessageType dirfrom = X_DEFAULT;
|
||||||
char *scanptr;
|
char *scanptr;
|
||||||
Bool singlecard = 0;
|
Bool singlecard = 0;
|
||||||
Bool implicit_layout = FALSE;
|
Bool implicit_layout = FALSE;
|
||||||
|
|
||||||
if (!autoconfig) {
|
if (!autoconfig) {
|
||||||
if (getuid() == 0)
|
if (getuid() == 0) {
|
||||||
searchpath = ROOT_CONFIGPATH;
|
filesearch = ROOT_CONFIGPATH;
|
||||||
else
|
dirsearch = ROOT_CONFIGDIRPATH;
|
||||||
searchpath = USER_CONFIGPATH;
|
} else {
|
||||||
|
filesearch = USER_CONFIGPATH;
|
||||||
|
dirsearch = USER_CONFIGDIRPATH;
|
||||||
|
}
|
||||||
|
|
||||||
if (xf86ConfigFile)
|
if (xf86ConfigFile)
|
||||||
from = X_CMDLINE;
|
filefrom = X_CMDLINE;
|
||||||
|
if (xf86ConfigDir)
|
||||||
|
dirfrom = X_CMDLINE;
|
||||||
|
|
||||||
xf86initConfigFiles();
|
xf86initConfigFiles();
|
||||||
filename = xf86openConfigFile(searchpath, xf86ConfigFile, PROJECTROOT);
|
filename = xf86openConfigFile(filesearch, xf86ConfigFile, PROJECTROOT);
|
||||||
dirname = xf86openConfigDirFiles(CONFIGDIRPATH, NULL, PROJECTROOT);
|
dirname = xf86openConfigDirFiles(dirsearch, xf86ConfigDir, PROJECTROOT);
|
||||||
if (filename) {
|
if (filename) {
|
||||||
xf86MsgVerb(from, 0, "Using config file: \"%s\"\n", filename);
|
xf86MsgVerb(filefrom, 0, "Using config file: \"%s\"\n", filename);
|
||||||
xf86ConfigFile = xnfstrdup(filename);
|
xf86ConfigFile = xnfstrdup(filename);
|
||||||
} else {
|
} else {
|
||||||
if (xf86ConfigFile)
|
if (xf86ConfigFile)
|
||||||
xf86Msg(X_ERROR, "Unable to locate/open config file: \"%s\"\n",
|
xf86Msg(X_ERROR, "Unable to locate/open config file: \"%s\"\n",
|
||||||
xf86ConfigFile);
|
xf86ConfigFile);
|
||||||
}
|
}
|
||||||
if (dirname)
|
if (dirname) {
|
||||||
xf86MsgVerb(X_DEFAULT, 0, "Using config directory: \"%s\"\n",
|
xf86MsgVerb(dirfrom, 0, "Using config directory: \"%s\"\n",
|
||||||
dirname);
|
dirname);
|
||||||
|
xf86ConfigDir = xnfstrdup(dirname);
|
||||||
|
} else {
|
||||||
|
if (xf86ConfigDir)
|
||||||
|
xf86Msg(X_ERROR,
|
||||||
|
"Unable to locate/open config directory: \"%s\"\n",
|
||||||
|
xf86ConfigDir);
|
||||||
|
}
|
||||||
if (!filename && !dirname)
|
if (!filename && !dirname)
|
||||||
return CONFIG_NOFILE;
|
return CONFIG_NOFILE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,6 +143,7 @@ xf86InfoRec xf86Info = {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
const char *xf86ConfigFile = NULL;
|
const char *xf86ConfigFile = NULL;
|
||||||
|
const char *xf86ConfigDir = NULL;
|
||||||
const char *xf86ModulePath = DEFAULT_MODULE_PATH;
|
const char *xf86ModulePath = DEFAULT_MODULE_PATH;
|
||||||
MessageType xf86ModPathFrom = X_DEFAULT;
|
MessageType xf86ModPathFrom = X_DEFAULT;
|
||||||
const char *xf86LogFile = DEFAULT_LOGPREFIX;
|
const char *xf86LogFile = DEFAULT_LOGPREFIX;
|
||||||
|
|
|
@ -1387,6 +1387,19 @@ ddxProcessArgument(int argc, char **argv, int i)
|
||||||
xf86ConfigFile = argv[i + 1];
|
xf86ConfigFile = argv[i + 1];
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
if (!strcmp(argv[i], "-configdir"))
|
||||||
|
{
|
||||||
|
CHECK_FOR_REQUIRED_ARGUMENT();
|
||||||
|
if (getuid() != 0 && !xf86PathIsSafe(argv[i + 1])) {
|
||||||
|
FatalError("\nInvalid argument for %s\n"
|
||||||
|
"\tFor non-root users, the file specified with %s must be\n"
|
||||||
|
"\ta relative path and must not contain any \"..\" elements.\n"
|
||||||
|
"\tUsing default "__XCONFIGDIR__" search path.\n\n",
|
||||||
|
argv[i], argv[i]);
|
||||||
|
}
|
||||||
|
xf86ConfigDir = argv[i + 1];
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
if (!strcmp(argv[i],"-flipPixels"))
|
if (!strcmp(argv[i],"-flipPixels"))
|
||||||
{
|
{
|
||||||
xf86FlipPixels = TRUE;
|
xf86FlipPixels = TRUE;
|
||||||
|
@ -1670,6 +1683,8 @@ ddxUseMsg(void)
|
||||||
}
|
}
|
||||||
ErrorF("-config file specify a configuration file, relative to the\n");
|
ErrorF("-config file specify a configuration file, relative to the\n");
|
||||||
ErrorF(" "__XCONFIGFILE__" search path, only root can use absolute\n");
|
ErrorF(" "__XCONFIGFILE__" search path, only root can use absolute\n");
|
||||||
|
ErrorF("-configdir dir specify a configuration directory, relative to the\n");
|
||||||
|
ErrorF(" "__XCONFIGDIR__" search path, only root can use absolute\n");
|
||||||
ErrorF("-verbose [n] verbose startup messages\n");
|
ErrorF("-verbose [n] verbose startup messages\n");
|
||||||
ErrorF("-logverbose [n] verbose log messages\n");
|
ErrorF("-logverbose [n] verbose log messages\n");
|
||||||
ErrorF("-quiet minimal startup messages\n");
|
ErrorF("-quiet minimal startup messages\n");
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
* The global state of these things is held in xf86InfoRec (when appropriate).
|
* The global state of these things is held in xf86InfoRec (when appropriate).
|
||||||
*/
|
*/
|
||||||
extern _X_EXPORT const char *xf86ConfigFile;
|
extern _X_EXPORT const char *xf86ConfigFile;
|
||||||
|
extern _X_EXPORT const char *xf86ConfigDir;
|
||||||
extern _X_EXPORT Bool xf86AllowMouseOpenFail;
|
extern _X_EXPORT Bool xf86AllowMouseOpenFail;
|
||||||
#ifdef XF86VIDMODE
|
#ifdef XF86VIDMODE
|
||||||
extern _X_EXPORT Bool xf86VidModeDisabled;
|
extern _X_EXPORT Bool xf86VidModeDisabled;
|
||||||
|
|
|
@ -109,7 +109,7 @@ script.
|
||||||
.B __xservername__
|
.B __xservername__
|
||||||
supports several mechanisms for supplying/obtaining configuration and
|
supports several mechanisms for supplying/obtaining configuration and
|
||||||
run-time parameters: command line options, environment variables, the
|
run-time parameters: command line options, environment variables, the
|
||||||
__xconfigfile__(__filemansuffix__) configuration file, auto-detection, and
|
__xconfigfile__(__filemansuffix__) configuration files, auto-detection, and
|
||||||
fallback defaults. When the same information is supplied in more than
|
fallback defaults. When the same information is supplied in more than
|
||||||
one way, the highest precedence mechanism is used. The list of mechanisms
|
one way, the highest precedence mechanism is used. The list of mechanisms
|
||||||
is ordered from highest precedence to lowest. Note that not all parameters
|
is ordered from highest precedence to lowest. Note that not all parameters
|
||||||
|
@ -176,6 +176,13 @@ This option will work for any file when the server is run as root (i.e,
|
||||||
with real-uid 0), or for files relative to a directory in the config
|
with real-uid 0), or for files relative to a directory in the config
|
||||||
search path for all other users.
|
search path for all other users.
|
||||||
.TP 8
|
.TP 8
|
||||||
|
.BI \-configdir " directory"
|
||||||
|
Read the server configuration files from
|
||||||
|
.IR directory .
|
||||||
|
This option will work for any directory when the server is run as root
|
||||||
|
(i.e, with real-uid 0), or for directories relative to a directory in the
|
||||||
|
config directory search path for all other users.
|
||||||
|
.TP 8
|
||||||
.B \-configure
|
.B \-configure
|
||||||
When this option is specified, the
|
When this option is specified, the
|
||||||
.B __xservername__
|
.B __xservername__
|
||||||
|
@ -456,6 +463,10 @@ __xconfigfile__(__filemansuffix__) file option.
|
||||||
.B __xservername__
|
.B __xservername__
|
||||||
typically uses a configuration file called
|
typically uses a configuration file called
|
||||||
.B __xconfigfile__
|
.B __xconfigfile__
|
||||||
|
and configuration files with the suffix
|
||||||
|
.I .conf
|
||||||
|
in a directory called
|
||||||
|
.B __xconfigdir__
|
||||||
for its initial setup.
|
for its initial setup.
|
||||||
Refer to the __xconfigfile__(__filemansuffix__) manual page for information
|
Refer to the __xconfigfile__(__filemansuffix__) manual page for information
|
||||||
about the format of this file.
|
about the format of this file.
|
||||||
|
@ -464,7 +475,9 @@ about the format of this file.
|
||||||
has a mechanism for automatically generating a built-in configuration
|
has a mechanism for automatically generating a built-in configuration
|
||||||
at run-time when no
|
at run-time when no
|
||||||
.B __xconfigfile__
|
.B __xconfigfile__
|
||||||
file is present. The current version of this automatic configuration
|
file or
|
||||||
|
.B __xconfigdir__
|
||||||
|
files are present. The current version of this automatic configuration
|
||||||
mechanism works in two ways.
|
mechanism works in two ways.
|
||||||
.PP
|
.PP
|
||||||
The first is via enhancements that have made many components of the
|
The first is via enhancements that have made many components of the
|
||||||
|
@ -486,7 +499,7 @@ supported by __xservername__. Enhancements are planned for future releases.
|
||||||
.SH FILES
|
.SH FILES
|
||||||
The
|
The
|
||||||
.B __xservername__
|
.B __xservername__
|
||||||
server config file can be found in a range of locations. These are
|
server config files can be found in a range of locations. These are
|
||||||
documented fully in the __xconfigfile__(__filemansuffix__) manual page. The
|
documented fully in the __xconfigfile__(__filemansuffix__) manual page. The
|
||||||
most commonly used locations are shown here.
|
most commonly used locations are shown here.
|
||||||
.TP 30
|
.TP 30
|
||||||
|
@ -505,6 +518,21 @@ Server configuration file.
|
||||||
.B __projectroot__/lib/X11/__xconfigfile__
|
.B __projectroot__/lib/X11/__xconfigfile__
|
||||||
Server configuration file.
|
Server configuration file.
|
||||||
.TP 30
|
.TP 30
|
||||||
|
.B /etc/X11/__xconfigdir__
|
||||||
|
Server configuration directory.
|
||||||
|
.TP 30
|
||||||
|
.B /etc/X11/__xconfigdir__-4
|
||||||
|
Server configuration directory.
|
||||||
|
.TP 30
|
||||||
|
.B /etc/__xconfigdir__
|
||||||
|
Server configuration directory.
|
||||||
|
.TP 30
|
||||||
|
.B __projectroot__/etc/__xconfigdir__
|
||||||
|
Server configuration directory.
|
||||||
|
.TP 30
|
||||||
|
.B __projectroot__/lib/X11/__xconfigdir__
|
||||||
|
Server configuration directory.
|
||||||
|
.TP 30
|
||||||
.BI __logdir__/__xservername__. n .log
|
.BI __logdir__/__xservername__. n .log
|
||||||
Server log file for display
|
Server log file for display
|
||||||
.IR n .
|
.IR n .
|
||||||
|
|
|
@ -874,11 +874,13 @@ AddConfigDirFiles(const char *dirpath, struct dirent **list, int num)
|
||||||
* directory. The directory does not need to contain config files.
|
* directory. The directory does not need to contain config files.
|
||||||
*/
|
*/
|
||||||
static char *
|
static char *
|
||||||
OpenConfigDir(const char *path, const char *projroot, const char *confname)
|
OpenConfigDir(const char *path, const char *cmdline, const char *projroot,
|
||||||
|
const char *confname)
|
||||||
{
|
{
|
||||||
char *dirpath, *pathcopy;
|
char *dirpath, *pathcopy;
|
||||||
const char *template;
|
const char *template;
|
||||||
Bool found = FALSE;
|
Bool found = FALSE;
|
||||||
|
int cmdlineUsed = 0;
|
||||||
|
|
||||||
pathcopy = strdup(path);
|
pathcopy = strdup(path);
|
||||||
for (template = strtok(pathcopy, ","); template && !found;
|
for (template = strtok(pathcopy, ","); template && !found;
|
||||||
|
@ -886,9 +888,16 @@ OpenConfigDir(const char *path, const char *projroot, const char *confname)
|
||||||
struct dirent **list = NULL;
|
struct dirent **list = NULL;
|
||||||
int num;
|
int num;
|
||||||
|
|
||||||
if (!(dirpath = DoSubstitution(template, NULL, projroot,
|
dirpath = DoSubstitution(template, cmdline, projroot,
|
||||||
NULL, NULL, confname)))
|
&cmdlineUsed, NULL, confname);
|
||||||
|
if (!dirpath)
|
||||||
continue;
|
continue;
|
||||||
|
if (cmdline && !cmdlineUsed) {
|
||||||
|
free(dirpath);
|
||||||
|
dirpath = NULL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* match files named *.conf */
|
/* match files named *.conf */
|
||||||
num = scandir(dirpath, &list, ConfigFilter, alphasort);
|
num = scandir(dirpath, &list, ConfigFilter, alphasort);
|
||||||
found = AddConfigDirFiles(dirpath, list, num);
|
found = AddConfigDirFiles(dirpath, list, num);
|
||||||
|
@ -992,7 +1001,7 @@ xf86openConfigDirFiles(const char *path, const char *cmdline,
|
||||||
projroot = PROJECTROOT;
|
projroot = PROJECTROOT;
|
||||||
|
|
||||||
/* Search for the multiconf directory */
|
/* Search for the multiconf directory */
|
||||||
configDirPath = OpenConfigDir(path, projroot, XCONFIGDIR);
|
configDirPath = OpenConfigDir(path, cmdline, projroot, XCONFIGDIR);
|
||||||
return configDirPath;
|
return configDirPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -853,6 +853,9 @@ winUseMsg (void)
|
||||||
ErrorF ("-config\n"
|
ErrorF ("-config\n"
|
||||||
"\tSpecify a configuration file.\n");
|
"\tSpecify a configuration file.\n");
|
||||||
|
|
||||||
|
ErrorF ("-configdir\n"
|
||||||
|
"\tSpecify a configuration directory.\n");
|
||||||
|
|
||||||
ErrorF ("-keyboard\n"
|
ErrorF ("-keyboard\n"
|
||||||
"\tSpecify a keyboard device from the configuration file.\n");
|
"\tSpecify a keyboard device from the configuration file.\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -64,6 +64,7 @@ XF86ConfigPtr g_xf86configptr = NULL;
|
||||||
WinCmdlineRec g_cmdline = {
|
WinCmdlineRec g_cmdline = {
|
||||||
#ifdef XWIN_XF86CONFIG
|
#ifdef XWIN_XF86CONFIG
|
||||||
NULL, /* configFile */
|
NULL, /* configFile */
|
||||||
|
NULL, /* configDir */
|
||||||
#endif
|
#endif
|
||||||
NULL, /* fontPath */
|
NULL, /* fontPath */
|
||||||
#ifdef XWIN_XF86CONFIG
|
#ifdef XWIN_XF86CONFIG
|
||||||
|
@ -117,19 +118,26 @@ winReadConfigfile ()
|
||||||
{
|
{
|
||||||
Bool retval = TRUE;
|
Bool retval = TRUE;
|
||||||
const char *filename, *dirname;
|
const char *filename, *dirname;
|
||||||
MessageType from = X_DEFAULT;
|
MessageType filefrom = X_DEFAULT;
|
||||||
|
MessageType dirfrom = X_DEFAULT;
|
||||||
char *xf86ConfigFile = NULL;
|
char *xf86ConfigFile = NULL;
|
||||||
|
char *xf86ConfigDir = NULL;
|
||||||
|
|
||||||
if (g_cmdline.configFile)
|
if (g_cmdline.configFile)
|
||||||
{
|
{
|
||||||
from = X_CMDLINE;
|
filefrom = X_CMDLINE;
|
||||||
xf86ConfigFile = g_cmdline.configFile;
|
xf86ConfigFile = g_cmdline.configFile;
|
||||||
}
|
}
|
||||||
|
if (g_cmdline.configDir)
|
||||||
|
{
|
||||||
|
dirfrom = X_CMDLINE;
|
||||||
|
xf86ConfigDir = g_cmdline.configDir;
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse config file into data structure */
|
/* Parse config file into data structure */
|
||||||
xf86initConfigFiles();
|
xf86initConfigFiles();
|
||||||
filename = xf86openConfigFile (CONFIGPATH, xf86ConfigFile, PROJECTROOT);
|
filename = xf86openConfigFile (CONFIGPATH, xf86ConfigFile, PROJECTROOT);
|
||||||
dirname = xf86openConfigDirFiles (CONFIGDIRPATH, NULL, PROJECTROOT);
|
dirname = xf86openConfigDirFiles (CONFIGDIRPATH, xf86ConfigDir, PROJECTROOT);
|
||||||
|
|
||||||
/* Hack for backward compatibility */
|
/* Hack for backward compatibility */
|
||||||
if (!filename && from == X_DEFAULT)
|
if (!filename && from == X_DEFAULT)
|
||||||
|
@ -150,6 +158,13 @@ winReadConfigfile ()
|
||||||
{
|
{
|
||||||
winMsg (from, "Using config directory: \"%s\"\n", dirname);
|
winMsg (from, "Using config directory: \"%s\"\n", dirname);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
winMsg (X_ERROR, "Unable to locate/open config directory");
|
||||||
|
if (xf86ConfigDir)
|
||||||
|
ErrorF (": \"%s\"", xf86ConfigDir);
|
||||||
|
ErrorF ("\n");
|
||||||
|
}
|
||||||
if (!filename && !dirname)
|
if (!filename && !dirname)
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
|
@ -188,6 +188,7 @@ typedef struct
|
||||||
/* Files */
|
/* Files */
|
||||||
#ifdef XWIN_XF86CONFIG
|
#ifdef XWIN_XF86CONFIG
|
||||||
char *configFile;
|
char *configFile;
|
||||||
|
char *configDir;
|
||||||
#endif
|
#endif
|
||||||
char *fontPath;
|
char *fontPath;
|
||||||
/* input devices - keyboard */
|
/* input devices - keyboard */
|
||||||
|
|
|
@ -1340,6 +1340,24 @@ ddxProcessArgument (int argc, char *argv[], int i)
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Look for the '-configdir' argument
|
||||||
|
*/
|
||||||
|
if (IS_OPTION ("-configdir"))
|
||||||
|
{
|
||||||
|
CHECK_ARGS (1);
|
||||||
|
#ifdef XWIN_XF86CONFIG
|
||||||
|
g_cmdline.configDir = argv[++i];
|
||||||
|
#else
|
||||||
|
winMessageBoxF ("The %s option is not supported in this "
|
||||||
|
"release.\n"
|
||||||
|
"Ignoring this option and continuing.\n",
|
||||||
|
MB_ICONINFORMATION,
|
||||||
|
argv[i]);
|
||||||
|
#endif
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Look for the '-keyboard' argument
|
* Look for the '-keyboard' argument
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user