[PATCH v2 2/2] xf86LogInit: log to XDG_DATA_HOME when not running as root
Peter Hutterer
peter.hutterer at who-t.net
Tue Apr 1 00:33:08 PDT 2014
On Wed, Mar 26, 2014 at 12:24:50PM +0100, Hans de Goede wrote:
> 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 at redhat.com>
> ---
> configure.ac | 4 ++++
> hw/xfree86/common/xf86Helper.c | 18 +++++++++++++++++-
> hw/xfree86/man/Xorg.man | 6 ++++--
> hw/xfree86/man/xorg.conf.man | 6 +++++-
> include/xorg-config.h.in | 6 ++++++
> 5 files changed, 36 insertions(+), 4 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index d278c6c..b16d30a 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -2043,6 +2043,8 @@ if test "x$XORG" = xyes; then
> AC_SUBST(XF86CONFIGDIR)
> CONFIGFILE="$sysconfdir/$XF86CONFIGFILE"
> LOGPREFIX="Xorg."
> + XDG_DATA_HOME=".local/share"
> + XDG_DATA_HOME_LOGDIR="xorg"
> AC_DEFINE(XORG_SERVER, 1, [Building Xorg server])
> AC_DEFINE(XORGSERVER, 1, [Building Xorg 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_LOGDIR, logdir, [Default log location])
> 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])
> if test "x$VGAHW" = xyes; then
> AC_DEFINE(WITH_VGAHW, 1, [Building vgahw module])
> diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
> index 12a8771..5131db6 100644
> --- a/hw/xfree86/common/xf86Helper.c
> +++ b/hw/xfree86/common/xf86Helper.c
> @@ -1220,13 +1220,29 @@ xf86ErrorF(const char *format, ...)
> void
> xf86LogInit(void)
> {
> - char *lf = NULL;
> + char *env, *lf = NULL;
> + char buf[PATH_MAX];
>
> #define LOGSUFFIX ".log"
> #define LOGOLDSUFFIX ".old"
>
> /* Get the log file name */
> 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) {
> + (void)mkdir(buf, 0777);
I've merged the first patch, but I have two questions for this one:
we can't really guarantee that XDG_DATA_HOME exists, especially when it's
overridden for e.g. a test setup. I think we should do mkdir -p here
to make sure we have the directory we want to write to.
the second point: 755 would be enough? any specific reason for 777?
Cheers,
Peter
PS: and of course this now brings up the question of whether we want
$XDG_CONFIG_DIR for xorg.conf.d snippets...
> + strlcat(buf, "/" DEFAULT_LOGPREFIX, sizeof(buf));
> + xf86LogFile = buf;
> + }
> + }
> /* Append the display number and ".log" */
> if (asprintf(&lf, "%s%%s" LOGSUFFIX, xf86LogFile) == -1)
> FatalError("Cannot allocate space for the log file name\n");
> diff --git a/hw/xfree86/man/Xorg.man b/hw/xfree86/man/Xorg.man
> index 0cd5a10..3ff6aef 100644
> --- a/hw/xfree86/man/Xorg.man
> +++ b/hw/xfree86/man/Xorg.man
> @@ -301,9 +301,11 @@ Use the file called
> .I filename
> as the
> .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
> -on most platforms, where
> +and for non root it is
> +.BI $XDG_DATA_HOME/xorg/Xorg. n .log
> +where
> .I n
> is the display number of the
> .B Xorg
> diff --git a/hw/xfree86/man/xorg.conf.man b/hw/xfree86/man/xorg.conf.man
> index 85f9f2e..6d2652e 100644
> --- a/hw/xfree86/man/xorg.conf.man
> +++ b/hw/xfree86/man/xorg.conf.man
> @@ -442,11 +442,15 @@ __modulepath__
> .TP 7
> .BI "LogFile \*q" path \*q
> 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
> .RS 11
> .RI __logdir__/Xorg. <n> .log
> .RE
> +and for non root it is
> +.RS 11
> +.RI $XDG_DATA_HOME/xorg/Xorg. <n> .log
> +.RE
> .PP
> .RS 7
> where
> diff --git a/include/xorg-config.h.in b/include/xorg-config.h.in
> index 4e2a45b..629ae40 100644
> --- a/include/xorg-config.h.in
> +++ b/include/xorg-config.h.in
> @@ -51,6 +51,12 @@
> /* Default logfile prefix */
> #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. */
> #undef XF86DRI
>
> --
> 1.9.0
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>
More information about the xorg-devel
mailing list