Compare commits

...

12 Commits

Author SHA1 Message Date
Enrico Weigelt, metux IT consult cc5bf5999c xfree86: man: add -syslogverbse flag
Document the newly added -syslogverbose command line flag.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-10 10:49:23 +00:00
Enrico Weigelt, metux IT consult 29d0ceb2d6 os: log: add syslog support
Add support for logging to syslog.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-10 10:49:23 +00:00
Enrico Weigelt, metux IT consult 8b9fdefe82 os: helper for parsing an counting-flag or value-flag option
Parses an option that may either be used for setting an integer value or
given one or multiple times (without argument) to increase an value

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-10 10:49:23 +00:00
Enrico Weigelt, metux IT consult 47bbb3995d meson.build: move writing conf_data into tail of main meson file
This allows us to do further probing in the included meson files:
Individual subdirectories (eg. DDXes, extensions, OS layer, ...)
can now probe things that are only relevant to them - no need to fill
the already too fat includes/meson.build with even more things.

Preparation for upcoming commits that'll make us of that.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-10 10:49:23 +00:00
Enrico Weigelt, metux IT consult f379affc25 os: unexport internal logging functions
Lots of logging functions, especially init and teardown aren't called
by any drivers/modules, so no need to keep them exported.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-10 10:49:23 +00:00
Enrico Weigelt, metux IT consult 65a3954b2e os: drop obsolete LogSetParameter()
No callers anymore, thus can be dropped.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-10 10:49:23 +00:00
Enrico Weigelt, metux IT consult e203a6c57d os: direct access to logFileVerbosity
No need for complicated 'generic' setter, just make the variable
itself available to DDX'es.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-10 10:49:23 +00:00
Enrico Weigelt, metux IT consult 3640a33077 os: direct access to logVerbosity
No need for complicated 'generic' setter, just make the variable
itself available to DDX'es.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-10 10:49:23 +00:00
Enrico Weigelt, metux IT consult 4fa8b1658b os: direct access to logSync instead of complex LogSetParameter()
It's just a simple flag, and only written from one site, so no need
for complex 'generic' setter function.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-10 10:49:23 +00:00
Enrico Weigelt, metux IT consult 74ccb158eb os: log: consolidate OS specific fsync() call into helper
Instead of having lots of #ifdef's, consolidating the conditionally
compiled fsync() call into a tiny inline helper.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-10 10:49:23 +00:00
Enrico Weigelt, metux IT consult 4e5dad0573 os: log: drop now meaningless XLOG_FLUSH option
Since we're not indirectly writing via FILE anymore, this option has
become meaningless: it meant flushing out our in-process buffer to
the kernel, but we're now doing direct write() calls anyways.

xf86 still accepts the "flush" config file flag for backwards compatibility,
but it hasn't any practical meaning anymore.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-10 10:49:23 +00:00
Enrico Weigelt, metux IT consult a92d3f2a04 os: log via fd instead of FILE
Instead of maintaining both the logfile fd, as well as ANSI FILE pointer,
simplify it to just a fd.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-10 10:49:23 +00:00
62 changed files with 335 additions and 123 deletions

View File

@ -46,6 +46,7 @@ in this Software without prior written authorization from The Open Group.
#include "os/auth.h"
#include "os/busfault.h"
#include "os/client_priv.h"
#include "os/log_priv.h"
#include "os/osdep.h"
#include "misc.h"

View File

@ -36,6 +36,9 @@ from Kaleb S. KEITHLEY
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/extensions/xf86vmproto.h>
#include "os/log_priv.h"
#include "misc.h"
#include "dixstruct.h"
#include "extnsionst.h"

View File

@ -97,6 +97,7 @@ SOFTWARE.
#include "dix/exevents_priv.h"
#include "dix/input_priv.h"
#include "mi/mi_priv.h"
#include "os/log_priv.h"
#include "inputstr.h"
#include "windowstr.h"

View File

@ -28,6 +28,8 @@
#include <dbus/dbus.h>
#include <sys/select.h>
#include "os/log_priv.h"
#include "dix.h"
#include "os.h"

View File

@ -62,6 +62,7 @@ SOFTWARE.
#include "dix/ptrveloc_priv.h"
#include "mi/mi_priv.h"
#include "os/bug_priv.h"
#include "os/log_priv.h"
#include "os/osdep.h"
#include "xkb/xkbsrv_priv.h"

View File

@ -60,6 +60,7 @@ Equipment Corporation.
#include "dix/dix_priv.h"
#include "dix/gc_priv.h"
#include "os/auth.h"
#include "os/log_priv.h"
#include "scrnintstr.h"
#include "resource.h"

View File

@ -127,6 +127,7 @@ Equipment Corporation.
#include "os/bug_priv.h"
#include "os/client_priv.h"
#include "os/fmt.h"
#include "os/log_priv.h"
#include "xkb/xkbsrv_priv.h"
#include "misc.h"

View File

@ -33,6 +33,7 @@
#include "dix/input_priv.h"
#include "mi/mi_priv.h"
#include "os/bug_priv.h"
#include "os/log_priv.h"
#include "inputstr.h"
#include "scrnintstr.h"

View File

@ -28,6 +28,7 @@
#include "dix/dix_priv.h"
#include "os/cmdline.h"
#include "os/ddx_priv.h"
#include "os/log_priv.h"
#include "os/osdep.h"
#include "ephyr.h"
@ -288,10 +289,8 @@ ddxProcessArgument(int argc, char **argv, int i)
}
else if (!strcmp(argv[i], "-verbosity")) {
if (i + 1 < argc && argv[i + 1][0] != '-') {
int verbosity = atoi(argv[i + 1]);
LogSetParameter(XLOG_VERBOSITY, verbosity);
EPHYR_LOG("set verbosiry to %d\n", verbosity);
logVerbosity = atoi(argv[i + 1]);
EPHYR_LOG("set verbosiry to %d\n", logVerbosity);
return 2;
}
else {

View File

@ -50,6 +50,7 @@
#include <sys/types.h>
#include <grp.h>
#include "os/log_priv.h"
#include "os/osdep.h"
#include "xf86.h"
@ -827,13 +828,11 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
{
if ((s = xf86GetOptValString(FlagOptions, FLAG_LOG))) {
if (!xf86NameCmp(s, "flush")) {
LogMessageVerb(X_CONFIG, 1, "Flushing logfile enabled\n");
LogSetParameter(XLOG_FLUSH, TRUE);
LogMessageVerb(X_CONFIG, 1, "flush log flag is noop\n");
}
else if (!xf86NameCmp(s, "sync")) {
LogMessageVerb(X_CONFIG, 1, "Syncing logfile enabled\n");
LogSetParameter(XLOG_FLUSH, TRUE);
LogSetParameter(XLOG_SYNC, TRUE);
logSync = TRUE;
}
else {
LogMessageVerb(X_WARNING, 1, "Unknown Log option\n");

View File

@ -64,6 +64,7 @@
#include "dix/dix_priv.h"
#include "dix/input_priv.h"
#include "mi/mi_priv.h"
#include "os/log_priv.h"
#include "misc.h"
#include "xf86.h"

View File

@ -44,6 +44,7 @@
#include "dix/dix_priv.h"
#include "dix/input_priv.h"
#include "mi/mi_priv.h"
#include "os/log_priv.h"
#include "os.h"
#include "servermd.h"

View File

@ -58,6 +58,7 @@
#include "mi/mi_priv.h"
#include "os/cmdline.h"
#include "os/ddx_priv.h"
#include "os/log_priv.h"
#include "os/osdep.h"
#include "servermd.h"
@ -870,14 +871,14 @@ void
xf86SetVerbosity(int verb)
{
xf86Verbose = verb;
LogSetParameter(XLOG_VERBOSITY, verb);
logVerbosity = verb;
}
void
xf86SetLogVerbosity(int verb)
{
xf86LogVerbose = verb;
LogSetParameter(XLOG_FILE_VERBOSITY, verb);
logFileVerbosity = verb;
}
static void

View File

@ -85,6 +85,9 @@
#endif
#include <X11/X.h>
#include "os/log_priv.h"
#include "xf86Modes.h"
#include "xf86Crtc.h"
#include "os.h"

View File

@ -39,6 +39,9 @@
#endif
#include <X11/X.h>
#include "os/log_priv.h"
#include "os.h"
#include "xf86.h"
#include "xf86Priv.h"

View File

@ -30,18 +30,17 @@
#include <xorg-config.h>
#endif
#include <X11/X.h>
#include "os/log_priv.h"
#include "misc.h"
#include "xf86.h"
#include <X11/X.h>
#include "scrnintstr.h"
#include "regionstr.h"
#include "xf86fbman.h"
/*
#define DEBUG
*/
static DevPrivateKeyRec xf86FBManagerKeyRec;
static DevPrivateKey xf86FBManagerKey;

View File

@ -35,8 +35,11 @@
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <X11/X.h>
#include <pciaccess.h>
#include <X11/X.h>
#include "os/log_priv.h"
#include "os.h"
#include "Pci.h"
#include "xf86.h"

View File

@ -36,6 +36,8 @@
#include <stdio.h>
#include <string.h>
#include "os/log_priv.h"
#include "xf86.h"
#include "vbe.h"
#include "vbeModes.h"

View File

@ -293,6 +293,15 @@ file verbosity level. When the
value is supplied, the log file verbosity level is set to that value.
The default log file verbosity level is 3.
.TP 8
.BR \-syslogverbose " [\fIn\fP]"
Sets the verbosity level for information printed to syslog. If the
.I n
value isn't supplied, each occurrence of this option increments the log
file verbosity level. When the
.I n
value is supplied, the log file verbosity level is set to that value.
The default log file verbosity level is 0 (silent).
.TP 8
.BI \-modulepath " searchpath"
Set the module search path to
.IR searchpath .

View File

@ -10,6 +10,8 @@
#include <fcntl.h>
#include <errno.h>
#include "os/log_priv.h"
#include "os.h"
#include "xf86.h"
#include "xf86Priv.h"

View File

@ -4,6 +4,9 @@
#endif
#include <X11/X.h>
#include "os/log_priv.h"
#include "os.h"
#include "xf86.h"
#include "xf86Priv.h"

View File

@ -59,6 +59,7 @@
#include <errno.h>
#include <X11/X.h>
#include "os/log_priv.h"
#include "os/xserver_poll.h"
#include "xf86.h"

View File

@ -16,6 +16,9 @@
#include <unistd.h>
#include <X11/X.h>
#include "os/log_priv.h"
#include "misc.h"
#include "xf86.h"

View File

@ -23,6 +23,7 @@ is" without express or implied warranty.
#include "dix/screenint_priv.h"
#include "mi/mi_priv.h"
#include "os/ddx_priv.h"
#include "os/log_priv.h"
#include "os/osdep.h"
#include "screenint.h"

View File

@ -35,6 +35,7 @@
#include <X11/Xproto.h>
#include "os/ddx_priv.h"
#include "os/log_priv.h"
#include "os/osdep.h"
#include "os.h"

View File

@ -30,6 +30,8 @@
#include <drm_fourcc.h>
#include <wayland-util.h>
#include "os/log_priv.h"
#include "xwayland-dmabuf.h"
#include "xwayland-glamor-gbm.h"
#include "xwayland-screen.h"

View File

@ -35,6 +35,7 @@
#include "mi/mi_priv.h"
#include "mi/mipointer_priv.h"
#include "os/bug_priv.h"
#include "os/log_priv.h"
#include <inputstr.h>
#include <xkbsrv.h>

View File

@ -32,6 +32,7 @@
#include "dix/dix_priv.h"
#include "dix/input_priv.h"
#include "randr/randrstr_priv.h"
#include "os/log_priv.h"
#include "xwayland-cvt.h"
#include "xwayland-output.h"

View File

@ -40,6 +40,7 @@
#include "dix/input_priv.h"
#include "dix/property_priv.h"
#include "os/client_priv.h"
#include "os/log_priv.h"
#include "os/osdep.h"
#include "os/xserver_poll.h"

View File

@ -34,6 +34,7 @@
#include "dix/dix_priv.h"
#include "dix/property_priv.h"
#include "os/log_priv.h"
#include "compositeext.h"
#include "compint.h"

View File

@ -33,6 +33,7 @@
#include "dix/dix_priv.h"
#include "dix/input_priv.h"
#include "os/client_priv.h"
#include "os/log_priv.h"
#include <inputstr.h>
#include <inpututils.h>

View File

@ -41,6 +41,7 @@
#include "os/client_priv.h"
#include "os/ddx_priv.h"
#include "os/fmt.h"
#include "os/log_priv.h"
#include "os/osdep.h"
#include "os/xserver_poll.h"
@ -134,7 +135,6 @@ static int init_fd = -1;
static int wm_fd = -1;
static int listen_fds[5] = { -1, -1, -1, -1, -1 };
static int listen_fd_count = 0;
static int verbosity = 0;
static void
xwl_show_version(void)
@ -237,12 +237,11 @@ ddxProcessArgument(int argc, char *argv[], int i)
val = strtol(argv[i], &end, 0);
if (*end == '\0') {
verbosity = val;
LogSetParameter(XLOG_VERBOSITY, verbosity);
logVerbosity = val;
return 2;
}
}
LogSetParameter(XLOG_VERBOSITY, ++verbosity);
logVerbosity++;
return 1;
}
else if (strcmp(argv[i], "-version") == 0) {

View File

@ -37,6 +37,7 @@ from The Open Group.
#include "dix/dix_priv.h"
#include "dix/screenint_priv.h"
#include "os/ddx_priv.h"
#include "os/log_priv.h"
#include "os/osdep.h"
#include "winmsg.h"
@ -643,9 +644,8 @@ OsVendorInit(void)
g_pszLogFile = LogInit(g_pszLogFile, ".old");
}
LogSetParameter(XLOG_FLUSH, 1);
LogSetParameter(XLOG_VERBOSITY, g_iLogVerbose);
LogSetParameter(XLOG_FILE_VERBOSITY, g_iLogVerbose);
logVerbosity = 2;
logFileVerbosity = 2;
/* Log the version information */
if (serverGeneration == 1)

View File

@ -78,6 +78,8 @@
#include <xwin-config.h>
#endif
#include "os/log_priv.h"
#include "glwindows.h"
#include <glx/glxserver.h>
#include <glx/glxutil.h>
@ -297,7 +299,7 @@ fbConfigsDump(unsigned int n, __GLXconfig * c, PixelFormatRejectStats *rejects)
LogMessage(X_INFO, "ignored pixel formats: %d not OpenGL, %d unknown pixel type, %d unaccelerated\n",
rejects->notOpenGL, rejects->unknownPixelType, rejects->unaccelerated);
if (g_iLogVerbose < 3)
if (logVerbosity < 3)
return;
ErrorF
@ -572,7 +574,7 @@ glxWinScreenProbe(ScreenPtr pScreen)
if (!wgl_extensions)
wgl_extensions = "";
if (g_iLogVerbose >= 3) {
if (logVerbosity >= 3) {
glxLogExtensions("GL_EXTENSIONS: ", gl_extensions);
glxLogExtensions("WGL_EXTENSIONS: ", wgl_extensions);
}

View File

@ -109,7 +109,7 @@ srcs_windows += [
rsrc = windows.compile_resources(
'XWin.rc',
include_directories: include_directories('../../include/'),
include_directories: include_directories('../../include/', '../..'),
depend_files: ['XWin.exe.manifest', 'X.ico'],
)
srcs_windows += rsrc

View File

@ -32,6 +32,7 @@
#include <xwin-config.h>
#endif
#include "os/log_priv.h"
#include "os/osdep.h"
#include <../xfree86/common/xorgVersion.h>

View File

@ -69,7 +69,6 @@ const char *g_pszLogFile = DEFAULT_LOGDIR "/XWin.%s.log";
const char *g_pszLogFile = "XWin.log";
Bool g_fLogFileChanged = FALSE;
#endif
int g_iLogVerbose = 2;
Bool g_fLogInited = FALSE;
char *g_pszCommandLine = NULL;
Bool g_fSilentFatalError = FALSE;

View File

@ -45,7 +45,6 @@ extern const char *g_pszLogFile;
#ifdef RELOCATE_PROJECTROOT
extern Bool g_fLogFileChanged;
#endif
extern int g_iLogVerbose;
extern Bool g_fLogInited;
extern Bool g_fAuthEnabled;

View File

@ -36,8 +36,9 @@ from The Open Group.
#endif
#include "os/cmdline.h"
#include "os/osdep.h"
#include "os/ddx_priv.h"
#include "os/log_priv.h"
#include "os/osdep.h"
#include <../xfree86/common/xorgVersion.h>
#include "win.h"
@ -996,7 +997,7 @@ ddxProcessArgument(int argc, char *argv[], int i)
*/
if (IS_OPTION("-logverbose")) {
CHECK_ARGS(1);
g_iLogVerbose = atoi(argv[++i]);
logVerbosity = atoi(argv[++i]);
return 2;
}

View File

@ -333,15 +333,6 @@ conf_data.set('WSCONS_SUPPORT', supports_wscons ? '1' : false)
conf_data.set('XSERVER_LIBPCIACCESS', get_option('pciaccess') ? '1' : false)
conf_data.set('XSERVER_PLATFORM_BUS', build_udev_kms ? '1' : false)
configure_file(output : 'dix-config.h',
configuration : conf_data)
configure_file(output : 'xorg-server.h',
input : 'xorg-server.h.meson.in',
configuration : conf_data,
install: build_xorg,
install_dir: xorgsdkdir)
version_data = configuration_data()
version_data.set('VENDOR_RELEASE', '@0@'.format(release))
version_data.set_quoted('VENDOR_NAME', get_option('vendor_name'))

View File

@ -280,14 +280,6 @@ extern _X_EXPORT int
timingsafe_memcmp(const void *b1, const void *b2, size_t len);
#endif
/* Logging. */
typedef enum _LogParameter {
XLOG_FLUSH,
XLOG_SYNC,
XLOG_VERBOSITY,
XLOG_FILE_VERBOSITY
} LogParameter;
/* Flags for log messages. */
typedef enum {
X_PROBED, /* Value was probed */
@ -304,14 +296,6 @@ typedef enum {
X_UNKNOWN = -1 /* unknown -- this must always be last */
} MessageType;
extern _X_EXPORT const char *
LogInit(const char *fname, const char *backup);
extern void
LogSetDisplay(void);
extern _X_EXPORT void
LogClose(enum ExitCode error);
extern _X_EXPORT Bool
LogSetParameter(LogParameter param, int value);
extern _X_EXPORT void
LogVMessageVerb(MessageType type, int verb, const char *format, va_list args)
_X_ATTRIBUTE_PRINTF(3, 0);
@ -322,7 +306,7 @@ extern _X_EXPORT void
LogMessage(MessageType type, const char *format, ...)
_X_ATTRIBUTE_PRINTF(2, 3);
extern _X_EXPORT void
void
LogVHdrMessageVerb(MessageType type, int verb,
const char *msg_format, va_list msg_args,
const char *hdr_format, va_list hdr_args)
@ -340,17 +324,11 @@ FatalError(const char *f, ...)
_X_ATTRIBUTE_PRINTF(1, 2)
_X_NORETURN;
#ifdef DEBUG
#define DebugF ErrorF
#else
#define DebugF(...) /* */
#endif
extern _X_EXPORT void
ErrorF(const char *f, ...)
_X_ATTRIBUTE_PRINTF(1, 2);
extern _X_EXPORT void
LogPrintMarkers(void);
void LogPrintMarkers(void);
extern _X_EXPORT void
xorg_backtrace(void);

View File

@ -924,3 +924,14 @@ if build_docs or build_docs_devel
configuration: docxmlconfig
)
endif
# finally write config files. doing that very late, so other subdirs still
# have a change to add config items
configure_file(output : 'dix-config.h',
configuration : conf_data)
configure_file(output : 'xorg-server.h',
input : 'include/xorg-server.h.meson.in',
configuration : conf_data,
install: build_xorg,
install_dir: xorgsdkdir)

View File

@ -87,6 +87,7 @@
#endif
#include "os/auth.h"
#include "os/log_priv.h"
/**
* Try to determine a PID for a client from its connection

32
os/cmdline.c Normal file
View File

@ -0,0 +1,32 @@
/* SPDX-License-Identifier: MIT OR X11
*
* Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
*
* @brief command line helper functions
*/
#include <dix-config.h>
#include <string.h>
#include <stdlib.h>
#include "os/cmdline.h"
int ProcessCmdLineMultiInt(int argc, char *argv[], int *idx, const char* name, int *value)
{
if (strcmp(argv[*idx], name))
return 0;
int i2 = *idx+1;
if (i2 < argc && argv[i2]) {
char *end;
long val = strtol(argv[i2], &end, 0);
if (*end == '\0') {
(*idx)++;
(*value) = val;
return 1;
}
}
(*value)++;
return 1;
}

View File

@ -17,4 +17,19 @@ void UseMsg(void);
void ProcessCommandLine(int argc, char * argv[]);
void CheckUserParameters(int argc, char **argv, char **envp);
/*
* @brief check for and parse an counting-flag or value-flag option
*
* Parses an option that may either be used for setting an integer value or
* given one or multiple times (without argument) to increase an value
*
* @param argc total number of elements in argv
* @param argv array of pointers to cmdline argument strings
* @param idx pointer to current index in argv -- eventually will be modified
* @param name the command line argument name
* @param value pointer to the field holding the setting value
* @return non-zero if the flag was found and parsed
*/
int ProcessCmdLineMultiInt(int argc, char *argv[], int *idx, const char* name, int *value);
#endif /* _XSERVER_OS_CMELINE_H */

View File

@ -98,6 +98,7 @@ SOFTWARE.
#include "os/audit.h"
#include "os/auth.h"
#include "os/client_priv.h"
#include "os/log_priv.h"
#include "os/osdep.h"
#include "misc.h" /* for typedef of pointer */

View File

@ -35,6 +35,7 @@
#include "dix/input_priv.h"
#include "os/ddx_priv.h"
#include "os/log_priv.h"
#include "inputstr.h"
#include "opaque.h"

118
os/log.c
View File

@ -88,12 +88,17 @@ OR PERFORMANCE OF THIS SOFTWARE.
#include <X11/Xfuncproto.h>
#include <X11/Xos.h>
#ifdef CONFIG_SYSLOG
#include <syslog.h>
#endif
#include "dix/dix_priv.h"
#include "dix/input_priv.h"
#include "os/audit.h"
#include "os/bug_priv.h"
#include "os/ddx_priv.h"
#include "os/fmt.h"
#include "os/log_priv.h"
#include "os/osdep.h"
#include "opaque.h"
@ -109,13 +114,18 @@ OR PERFORMANCE OF THIS SOFTWARE.
/* Default logging parameters. */
#define DEFAULT_LOG_VERBOSITY 0
#define DEFAULT_LOG_FILE_VERBOSITY 3
#define DEFAULT_SYSLOG_VERBOSITY 0
Bool logSync = FALSE;
int logVerbosity = DEFAULT_LOG_VERBOSITY;
int logFileVerbosity = DEFAULT_LOG_FILE_VERBOSITY;
#ifdef CONFIG_SYSLOG
int xorgSyslogVerbosity = DEFAULT_SYSLOG_VERBOSITY;
const char *xorgSyslogIdent = "X";
#endif
static FILE *logFile = NULL;
static int logFileFd = -1;
static Bool logFlush = FALSE;
static Bool logSync = FALSE;
static int logVerbosity = DEFAULT_LOG_VERBOSITY;
static int logFileVerbosity = DEFAULT_LOG_FILE_VERBOSITY;
/* Buffer to information logged before the log file is opened. */
static char *saveBuffer = NULL;
@ -201,6 +211,24 @@ LogFilePrep(const char *fname, const char *backup, const char *idstring)
}
#pragma GCC diagnostic pop
static inline void doLogSync(void) {
#ifndef WIN32
fsync(logFileFd);
#endif
}
static void initSyslog(void) {
#ifdef CONFIG_SYSLOG
char buffer[4096];
strcpy(buffer, xorgSyslogIdent);
snprintf(buffer, sizeof(buffer), "%s :%s", xorgSyslogIdent, (display ? display : "<>"));
/* initialize syslog */
openlog(buffer, LOG_PID, LOG_LOCAL1);
#endif
}
/*
* LogInit is called to start logging to a file. It is also called (with
* NULL arguments) when logging to a file is not wanted. It must always be
@ -236,19 +264,14 @@ LogInit(const char *fname, const char *backup)
saved_log_backup = strdup(backup);
} else
logFileName = LogFilePrep(fname, backup, display);
if ((logFile = fopen(logFileName, "w")) == NULL)
FatalError("Cannot open log file \"%s\"\n", logFileName);
setvbuf(logFile, NULL, _IONBF, 0);
logFileFd = fileno(logFile);
if ((logFileFd = open(logFileName, O_WRONLY | O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP)) == -1)
FatalError("Cannot open log file \"%s\": %s\n", logFileName, strerror(errno));
/* Flush saved log information. */
if (saveBuffer && bufferSize > 0) {
fwrite(saveBuffer, bufferPos, 1, logFile);
fflush(logFile);
#ifndef WIN32
fsync(fileno(logFile));
#endif
write(logFileFd, saveBuffer, bufferPos);
doLogSync();
}
}
@ -263,6 +286,7 @@ LogInit(const char *fname, const char *backup)
}
needBuffer = FALSE;
initSyslog();
return logFileName;
}
@ -294,44 +318,23 @@ LogSetDisplay(void)
free(saved_log_fname);
free(saved_log_backup);
}
initSyslog();
}
void
LogClose(enum ExitCode error)
{
if (logFile) {
if (logFileFd != -1) {
int msgtype = (error == EXIT_NO_ERROR) ? X_INFO : X_ERROR;
LogMessageVerb(msgtype, -1,
"Server terminated %s (%d). Closing log file.\n",
(error == EXIT_NO_ERROR) ? "successfully" : "with error",
error);
fclose(logFile);
logFile = NULL;
close(logFileFd);
logFileFd = -1;
}
}
Bool
LogSetParameter(LogParameter param, int value)
{
switch (param) {
case XLOG_FLUSH:
logFlush = value ? TRUE : FALSE;
return TRUE;
case XLOG_SYNC:
logSync = value ? TRUE : FALSE;
return TRUE;
case XLOG_VERBOSITY:
logVerbosity = value;
return TRUE;
case XLOG_FILE_VERBOSITY:
logFileVerbosity = value;
return TRUE;
default:
return FALSE;
}
}
enum {
LMOD_LONG = 0x1,
LMOD_LONGLONG = 0x2,
@ -550,6 +553,19 @@ vpnprintf(char *string, int size_in, const char *f, va_list args)
return s_idx;
}
static void
LogSyslogWrite(int verb, const char *buf, size_t len, Bool end_line) {
#ifdef CONFIG_SYSLOG
if (inSignalContext) // syslog() ins't signal-safe yet :(
return; // shall we try syslog(2) syscall instead ?
if (verb >= 0 && xorgSyslogVerbosity < verb)
return;
syslog(LOG_PID, "%.*s", (int)len, buf);
#endif
}
/* This function does the actual log message writes. It must be signal safe.
* When attempting to call non-signal-safe functions, guard them with a check
* of the inSignalContext global variable. */
@ -559,37 +575,31 @@ LogSWrite(int verb, const char *buf, size_t len, Bool end_line)
static Bool newline = TRUE;
int ret;
LogSyslogWrite(verb, buf, len, end_line);
if (verb < 0 || logVerbosity >= verb)
ret = write(2, buf, len);
if (verb < 0 || logFileVerbosity >= verb) {
if (inSignalContext && logFileFd >= 0) {
ret = write(logFileFd, buf, len);
#ifndef WIN32
if (logFlush && logSync)
fsync(logFileFd);
#endif
if (logSync)
doLogSync();
}
else if (!inSignalContext && logFile) {
else if (!inSignalContext && logFileFd != -1) {
if (newline) {
time_t t = time(NULL);
struct tm tm;
char fmt_tm[32];
localtime_r(&t, &tm);
strftime(fmt_tm, sizeof(fmt_tm) - 1, "%Y-%m-%d %H:%M:%S", &tm);
fprintf(logFile, "[%s] ", fmt_tm);
strftime(fmt_tm, sizeof(fmt_tm) - 1, "[%Y-%m-%d %H:%M:%S] ", &tm);
write(logFileFd, fmt_tm, strlen(fmt_tm));
}
newline = end_line;
fwrite(buf, len, 1, logFile);
if (logFlush) {
fflush(logFile);
#ifndef WIN32
if (logSync)
fsync(fileno(logFile));
#endif
}
write(logFileFd, buf, len);
if (logSync)
doLogSync();
}
else if (!inSignalContext && needBuffer) {
if (len > bufferUnused) {

95
os/log_priv.h Normal file
View File

@ -0,0 +1,95 @@
/* SPDX-License-Identifier: MIT OR X11
*
* Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
*/
#ifndef _XSERVER_LOG_PRIV_H
#define _XSERVER_LOG_PRIV_H
#include <sys/types.h>
#include <X11/Xdefs.h>
#include "include/os.h"
/**
* @brief force fsync() on each log write
*
* If set to TRUE, force fsync() on each log write.
*/
extern Bool logSync;
/**
* @brief console log verbosity (stderr)
*
* The verbosity level of logging to console. All messages with verbosity
* level below this one will be written to stderr
*/
extern int logVerbosity;
/**
* @brief log file verbosity
*
* The verbosity level of logging to per-display file. All messages with
* verbosity level below this one will be written to the log file.
*/
extern int logFileVerbosity;
/**
* @brief syslog verbosity
*
* The verbosity level of logging to syslog. All messages with
* verbosity level below this one will be sent to local syslog daemon.
*/
extern int xorgSyslogVerbosity;
/**
* @brief syslog identifier
*
* The identifier prefix used for syslog logging.
* Per default will be filled with basename(argv[0]). DDX'es can override
* this before calling LogInit()
*/
extern const char *xorgSyslogIdent;
/**
* @brief initialize logging and open log files
*
* Make backup of existing log file, create a new one and open it for logging.
*
* - May be called with NULL or "", if no logging is desired.
*
* - Must always be called, otherwise log messages will fill up the buffer and
* let it grow infinitely.
*
* - if "%s" is present in fname, it will be replaced with the display string or pid
*
* @param fname log file name template. if NULL, dont write any log.
* @param backup name for the old logfile.
* @return new log file name
*/
const char* LogInit(const char *fname, const char *backup);
/**
* @brief rename the current log file according display name
*
* Renames the current log file with per display prefix (e.g. "Xorg.log.0")
*
*/
void LogSetDisplay(void);
/**
* @brief log exit code, then flush and close log file and write
*
* Logs the exit code (and success/error state), then flush and close log file.
*/
void LogClose(enum ExitCode error);
#ifdef DEBUG
/**
* @brief log debug messages (like errors) if symbol DEBUG is defined
*/
#define DebugF ErrorF
#else
#define DebugF(...) /* */
#endif
#endif /* _XSERVER_LOG_PRIV_H */

View File

@ -5,6 +5,7 @@ srcs_os = [
'auth.c',
'backtrace.c',
'client.c',
'cmdline.c',
'connection.c',
'fmt.c',
'inputthread.c',
@ -22,6 +23,8 @@ srcs_os = [
'log.c',
]
conf_data.set('CONFIG_SYSLOG', cc.has_header('syslog.h') ? '1' : false)
# Wrapper code for missing C library functions. Note that conf_data contains either '1' or false.
srcs_libc = []
if conf_data.get('HAVE_REALLOCARRAY').to_int() == 0

View File

@ -60,6 +60,7 @@ SOFTWARE.
#include "dix/dix_priv.h"
#include "os/busfault.h"
#include "os/log_priv.h"
#include "os/osdep.h"
#include "os/serverlock.h"

View File

@ -77,8 +77,7 @@ __stdcall unsigned long GetTickCount(void);
#define TRANS_REOPEN
#include <X11/Xtrans/Xtrans.h>
#include "os/audit.h"
#include "os/client_priv.h"
#include <libgen.h>
#include "input.h"
#include "dixfont.h"
@ -106,10 +105,13 @@ __stdcall unsigned long GetTickCount(void);
#include "dix/dix_priv.h"
#include "dix/input_priv.h"
#include "os/audit.h"
#include "os/auth.h"
#include "os/bug_priv.h"
#include "os/client_priv.h"
#include "os/cmdline.h"
#include "os/ddx_priv.h"
#include "os/log_priv.h"
#include "os/osdep.h"
#include "os/serverlock.h"
@ -439,6 +441,12 @@ ProcessCommandLine(int argc, char *argv[])
}
SeatId = getenv("XDG_SEAT");
#ifdef CONFIG_SYSLOG
xorgSyslogIdent = getenv("SYSLOG_IDENT");
if (!xorgSyslogIdent)
xorgSyslogIdent = strdup(basename(argv[0]));
#endif
for (i = 1; i < argc; i++) {
/* call ddx first, so it can peek/override if it wants */
if ((skip = ddxProcessArgument(argc, argv, i))) {
@ -805,6 +813,9 @@ ProcessCommandLine(int argc, char *argv[])
else
UseMsg();
}
#ifdef CONFIG_SYSLOG
else if (ProcessCmdLineMultiInt(argc, argv, &i, "-syslogverbose", &xorgSyslogVerbosity));
#endif
else {
ErrorF("Unrecognized option: %s\n", argv[i]);
UseMsg();

View File

@ -30,6 +30,7 @@
#include <unistd.h>
#include "os/fmt.h"
#include "os/log_priv.h"
#include "assert.h"
#include "misc.h"
@ -149,7 +150,7 @@ number_formatting(void)
-0x7FFFFFFFFFFFFFFF, /* Maximum 64-bit signed number */
} ;
LogSetParameter(XLOG_VERBOSITY, -1);
logVerbosity = -1;
for (i = 0; i < ARRAY_SIZE(unsigned_tests); i++)
assert(check_number_format_test(unsigned_tests[i]));
@ -181,7 +182,7 @@ static void logging_format(void)
uintptr_t ptr;
char *fname = NULL;
LogSetParameter(XLOG_VERBOSITY, -1);
logVerbosity = -1;
/* set up buf to contain ".....end" */
memset(buf, '.', sizeof(buf));

View File

@ -29,9 +29,12 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <stdio.h>
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include "os/log_priv.h"
#include "misc.h"
#include "inputstr.h"
#include <X11/keysym.h>
#include <xkbsrv.h>
/***====================================================================***/

View File

@ -39,6 +39,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <X11/extensions/XKM.h>
#include "dix/dix_priv.h"
#include "os/log_priv.h"
#include "os/osdep.h"
#include "xkb/xkbfile_priv.h"
#include "xkb/xkbfmisc_priv.h"

View File

@ -41,6 +41,7 @@
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include "os/log_priv.h"
#include "xkb/xkbrules_priv.h"
#include "misc.h"

View File

@ -37,6 +37,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <X11/extensions/XIproto.h>
#include "dix/input_priv.h"
#include "os/log_priv.h"
#include "xkb/xkbsrv_priv.h"
#include "exglobals.h"

View File

@ -34,6 +34,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <X11/extensions/XIproto.h>
#include "dix/exevents_priv.h"
#include "os/log_priv.h"
#include "inputstr.h"
#include "exglobals.h"

View File

@ -41,6 +41,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "os/bug_priv.h"
#include "os/cmdline.h"
#include "os/log_priv.h"
#include "xkb/xkbsrv_priv.h"
#include "misc.h"

View File

@ -34,6 +34,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <X11/keysym.h>
#include "dix/input_priv.h"
#include "os/log_priv.h"
#include "xkb/xkbsrv_priv.h"
#include "misc.h"

View File

@ -58,6 +58,7 @@ DEALINGS IN THE SOFTWARE.
#define XK_CYRILLIC
#include <X11/keysym.h>
#include "os/log_priv.h"
#include "xkb/xkbsrv_priv.h"
#include "os.h"

View File

@ -34,6 +34,7 @@
#include <X11/keysym.h>
#include <X11/extensions/XKMformat.h>
#include "os/log_priv.h"
#include "xkb/xkbfile_priv.h"
#include "xkb/xkbfmisc_priv.h"