xf86LogInit: log to XDG_DATA_HOME when not running as root

When no logfile was specified (xf86LogFileFrom == X_DEFAULT) and we're not
running as root log to $XDG_DATA_HOME/xorg/Xorg.#.log as Xorg won't be able to
log to the default /var/log/... when it is not running as root.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Hans de Goede 2014-04-01 11:24:17 +02:00 committed by Peter Hutterer
parent f37a469134
commit 9d65c515d8
5 changed files with 49 additions and 4 deletions

View File

@ -2043,6 +2043,8 @@ if test "x$XORG" = xyes; then
AC_SUBST(XF86CONFIGDIR) AC_SUBST(XF86CONFIGDIR)
CONFIGFILE="$sysconfdir/$XF86CONFIGFILE" CONFIGFILE="$sysconfdir/$XF86CONFIGFILE"
LOGPREFIX="Xorg." LOGPREFIX="Xorg."
XDG_DATA_HOME=".local/share"
XDG_DATA_HOME_LOGDIR="xorg"
AC_DEFINE(XORG_SERVER, 1, [Building Xorg server]) AC_DEFINE(XORG_SERVER, 1, [Building Xorg server])
AC_DEFINE(XORGSERVER, 1, [Building Xorg server]) AC_DEFINE(XORGSERVER, 1, [Building Xorg server])
AC_DEFINE(XFree86Server, 1, [Building XFree86 server]) AC_DEFINE(XFree86Server, 1, [Building XFree86 server])
@ -2057,6 +2059,8 @@ if test "x$XORG" = xyes; then
AC_DEFINE_DIR(DEFAULT_LIBRARY_PATH, libdir, [Default library install path]) AC_DEFINE_DIR(DEFAULT_LIBRARY_PATH, libdir, [Default library install path])
AC_DEFINE_DIR(DEFAULT_LOGDIR, logdir, [Default log location]) AC_DEFINE_DIR(DEFAULT_LOGDIR, logdir, [Default log location])
AC_DEFINE_DIR(DEFAULT_LOGPREFIX, LOGPREFIX, [Default logfile prefix]) AC_DEFINE_DIR(DEFAULT_LOGPREFIX, LOGPREFIX, [Default logfile prefix])
AC_DEFINE_DIR(DEFAULT_XDG_DATA_HOME, XDG_DATA_HOME, [Default XDG_DATA dir under HOME])
AC_DEFINE_DIR(DEFAULT_XDG_DATA_HOME_LOGDIR, XDG_DATA_HOME_LOGDIR, [Default log dir under XDG_DATA_HOME])
AC_DEFINE_UNQUOTED(__VENDORDWEBSUPPORT__, ["$VENDOR_WEB"], [Vendor web address for support]) AC_DEFINE_UNQUOTED(__VENDORDWEBSUPPORT__, ["$VENDOR_WEB"], [Vendor web address for support])
if test "x$VGAHW" = xyes; then if test "x$VGAHW" = xyes; then
AC_DEFINE(WITH_VGAHW, 1, [Building vgahw module]) AC_DEFINE(WITH_VGAHW, 1, [Building vgahw module])

View File

@ -1217,16 +1217,45 @@ xf86ErrorF(const char *format, ...)
va_end(ap); va_end(ap);
} }
/* Note temporarily modifies the passed in buffer! */
static void xf86_mkdir_p(char *path)
{
char *sep = path;
while ((sep = strchr(sep + 1, '/'))) {
*sep = 0;
(void)mkdir(path, 0777);
*sep = '/';
}
(void)mkdir(path, 0777);
}
void void
xf86LogInit(void) xf86LogInit(void)
{ {
char *lf = NULL; char *env, *lf = NULL;
char buf[PATH_MAX];
#define LOGSUFFIX ".log" #define LOGSUFFIX ".log"
#define LOGOLDSUFFIX ".old" #define LOGOLDSUFFIX ".old"
/* Get the log file name */ /* Get the log file name */
if (xf86LogFileFrom == X_DEFAULT) { if (xf86LogFileFrom == X_DEFAULT) {
/* When not running as root, we won't be able to write to /var/log */
if (geteuid() != 0) {
if ((env = getenv("XDG_DATA_HOME")))
snprintf(buf, sizeof(buf), "%s/%s", env,
DEFAULT_XDG_DATA_HOME_LOGDIR);
else if ((env = getenv("HOME")))
snprintf(buf, sizeof(buf), "%s/%s/%s", env,
DEFAULT_XDG_DATA_HOME, DEFAULT_XDG_DATA_HOME_LOGDIR);
if (env) {
xf86_mkdir_p(buf);
strlcat(buf, "/" DEFAULT_LOGPREFIX, sizeof(buf));
xf86LogFile = buf;
}
}
/* Append the display number and ".log" */ /* Append the display number and ".log" */
if (asprintf(&lf, "%s%%s" LOGSUFFIX, xf86LogFile) == -1) if (asprintf(&lf, "%s%%s" LOGSUFFIX, xf86LogFile) == -1)
FatalError("Cannot allocate space for the log file name\n"); FatalError("Cannot allocate space for the log file name\n");

View File

@ -301,9 +301,11 @@ Use the file called
.I filename .I filename
as the as the
.B Xorg .B Xorg
server log file. The default log file is server log file. The default log file when running as root is
.BI __logdir__/Xorg. n .log .BI __logdir__/Xorg. n .log
on most platforms, where and for non root it is
.BI $XDG_DATA_HOME/xorg/Xorg. n .log
where
.I n .I n
is the display number of the is the display number of the
.B Xorg .B Xorg

View File

@ -442,11 +442,15 @@ __modulepath__
.TP 7 .TP 7
.BI "LogFile \*q" path \*q .BI "LogFile \*q" path \*q
sets the name of the Xorg server log file. sets the name of the Xorg server log file.
The default log file name is The default log file name when running as root is
.PP .PP
.RS 11 .RS 11
.RI __logdir__/Xorg. <n> .log .RI __logdir__/Xorg. <n> .log
.RE .RE
and for non root it is
.RS 11
.RI $XDG_DATA_HOME/xorg/Xorg. <n> .log
.RE
.PP .PP
.RS 7 .RS 7
where where

View File

@ -51,6 +51,12 @@
/* Default logfile prefix */ /* Default logfile prefix */
#undef DEFAULT_LOGPREFIX #undef DEFAULT_LOGPREFIX
/* Default XDG_DATA dir under HOME */
#undef DEFAULT_XDG_DATA_HOME
/* Default log dir under XDG_DATA_HOME */
#undef DEFAULT_XDG_DATA_HOME_LOGDIR
/* Building DRI-capable DDX. */ /* Building DRI-capable DDX. */
#undef XF86DRI #undef XF86DRI