Compare commits

...

6 Commits

Author SHA1 Message Date
Enrico Weigelt, metux IT consult cc4e5d08d3 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-02-11 15:53:52 +01:00
Enrico Weigelt, metux IT consult 003c171f0b 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-02-11 15:53:52 +01:00
Enrico Weigelt, metux IT consult f24f0e5864 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-02-11 15:53:52 +01:00
Enrico Weigelt, metux IT consult 33fa580900 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-02-11 15:53:52 +01:00
Enrico Weigelt, metux IT consult 8f173a92f8 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-02-11 15:53:52 +01:00
Enrico Weigelt, metux IT consult db94b86a21 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-02-11 15:53:52 +01:00
13 changed files with 83 additions and 62 deletions

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

@ -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

@ -39,6 +39,7 @@
#include "dix/screenint_priv.h"
#include "os/cmdline.h"
#include "os/ddx_priv.h"
#include "os/log_priv.h"
#include "os/osdep.h"
#include "os/xserver_poll.h"
@ -132,7 +133,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)
@ -235,12 +235,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

@ -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

@ -324,7 +324,6 @@ timingsafe_memcmp(const void *b1, const void *b2, size_t len);
/* Logging. */
typedef enum _LogParameter {
XLOG_FLUSH,
XLOG_SYNC,
XLOG_VERBOSITY,
XLOG_FILE_VERBOSITY

View File

@ -109,12 +109,11 @@ OR PERFORMANCE OF THIS SOFTWARE.
#define DEFAULT_LOG_VERBOSITY 0
#define DEFAULT_LOG_FILE_VERBOSITY 3
static FILE *logFile = NULL;
Bool logSync = FALSE;
int logVerbosity = DEFAULT_LOG_VERBOSITY;
int logFileVerbosity = DEFAULT_LOG_FILE_VERBOSITY;
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;
@ -200,6 +199,12 @@ LogFilePrep(const char *fname, const char *backup, const char *idstring)
}
#pragma GCC diagnostic pop
static inline void doLogSync(void) {
#ifndef WIN32
fsync(logFileFd);
#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
@ -235,19 +240,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();
}
}
@ -298,14 +298,13 @@ LogSetDisplay(void)
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;
}
}
@ -314,9 +313,6 @@ 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;
@ -563,31 +559,23 @@ LogSWrite(int verb, const char *buf, size_t len, Bool end_line)
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) {

34
os/log_priv.h Normal file
View File

@ -0,0 +1,34 @@
/* 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>
/**
* @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;
#endif /* _XSERVER_LOG_PRIV_H */

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));