Revert "os: log: replace LogMessageVerbSigSafe() by LogMessageVerb()"

This reverts commit dd37cc4855.

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2036>
This commit is contained in:
Alan Coopersmith 2025-06-23 16:25:31 -07:00 committed by Marge Bot
parent 8ff12a8e53
commit 6a9b2f37bb
8 changed files with 57 additions and 43 deletions

View File

@ -805,7 +805,7 @@ glxDRILeaveVT(ScrnInfoPtr scrn)
__GLXDRIscreen *screen = (__GLXDRIscreen *) __GLXDRIscreen *screen = (__GLXDRIscreen *)
glxGetScreen(xf86ScrnToScreen(scrn)); glxGetScreen(xf86ScrnToScreen(scrn));
LogMessageVerb(X_INFO, -1, "AIGLX: Suspending AIGLX clients for VT switch\n"); LogMessageVerbSigSafe(X_INFO, -1, "AIGLX: Suspending AIGLX clients for VT switch\n");
glxSuspendClients(); glxSuspendClients();

View File

@ -126,9 +126,9 @@ notify_sync_finished(ClientPtr ptr, void *closure)
already shut down and the descriptor is closed. already shut down and the descriptor is closed.
*/ */
if (write(fd, &response, response.header.length) != response.header.length) { if (write(fd, &response, response.header.length) != response.header.length) {
LogMessageVerb(X_ERROR, 0, LogMessageVerbSigSafe(X_ERROR, 0,
"inputtest: Failed to write sync response: %s\n", "inputtest: Failed to write sync response: %s\n",
strerror(errno)); strerror(errno));
} }
input_unlock(); input_unlock();
return TRUE; return TRUE;

View File

@ -141,7 +141,7 @@ LoaderSymbolFromModule(void *handle, const char *name)
void void
LoaderUnload(const char *name, void *handle) LoaderUnload(const char *name, void *handle)
{ {
LogMessageVerb(X_INFO, 1, "Unloading %s\n", name); LogMessageVerbSigSafe(X_INFO, 1, "Unloading %s\n", name);
if (handle) if (handle)
dlclose(handle); dlclose(handle);
} }

View File

@ -854,9 +854,9 @@ UnloadModule(void *_mod)
const char *name = mod->VersionInfo->modname; const char *name = mod->VersionInfo->modname;
if (mod->parent) if (mod->parent)
LogMessageVerb(X_INFO, 3, "UnloadSubModule: \"%s\"\n", name); LogMessageVerbSigSafe(X_INFO, 3, "UnloadSubModule: \"%s\"\n", name);
else else
LogMessageVerb(X_INFO, 3, "UnloadModule: \"%s\"\n", name); LogMessageVerbSigSafe(X_INFO, 3, "UnloadModule: \"%s\"\n", name);
if (mod->TearDownData != ModuleDuplicated) { if (mod->TearDownData != ModuleDuplicated) {
if ((mod->TearDownProc) && (mod->TearDownData)) if ((mod->TearDownProc) && (mod->TearDownData))

View File

@ -324,6 +324,9 @@ _X_ATTRIBUTE_PRINTF(3, 4);
extern _X_EXPORT void extern _X_EXPORT void
LogMessage(MessageType type, const char *format, ...) LogMessage(MessageType type, const char *format, ...)
_X_ATTRIBUTE_PRINTF(2, 3); _X_ATTRIBUTE_PRINTF(2, 3);
extern _X_EXPORT void
LogMessageVerbSigSafe(MessageType type, int verb, const char *format, ...)
_X_ATTRIBUTE_PRINTF(3, 4);
extern _X_EXPORT void extern _X_EXPORT void
LogVHdrMessageVerb(MessageType type, int verb, LogVHdrMessageVerb(MessageType type, int verb,
@ -375,7 +378,6 @@ typedef _sigset_t sigset_t;
/* should not be used anymore, just for backwards compat with drivers */ /* should not be used anymore, just for backwards compat with drivers */
#define LogVMessageVerbSigSafe(...) LogVMessageVerb(__VA_ARGS__) #define LogVMessageVerbSigSafe(...) LogVMessageVerb(__VA_ARGS__)
#define LogMessageVerbSigSafe(...) LogMessageVerb(__VA_ARGS__)
/* only for backwards compat with drivers that haven't kept up yet /* only for backwards compat with drivers that haven't kept up yet
(xf86-video-intel) (xf86-video-intel)

View File

@ -302,7 +302,7 @@ LogClose(enum ExitCode error)
{ {
if (logFile) { if (logFile) {
int msgtype = (error == EXIT_NO_ERROR) ? X_INFO : X_ERROR; int msgtype = (error == EXIT_NO_ERROR) ? X_INFO : X_ERROR;
LogMessageVerb(msgtype, -1, LogMessageVerbSigSafe(msgtype, -1,
"Server terminated %s (%d). Closing log file.\n", "Server terminated %s (%d). Closing log file.\n",
(error == EXIT_NO_ERROR) ? "successfully" : "with error", (error == EXIT_NO_ERROR) ? "successfully" : "with error",
error); error);
@ -695,7 +695,7 @@ LogVMessageVerb(MessageType type, int verb, const char *format, va_list args)
writeLog(verb, buf, len); writeLog(verb, buf, len);
} }
/* Log message with verbosity level specified. -- signal safe */ /* Log message with verbosity level specified. */
void void
LogMessageVerb(MessageType type, int verb, const char *format, ...) LogMessageVerb(MessageType type, int verb, const char *format, ...)
{ {
@ -717,6 +717,16 @@ LogMessage(MessageType type, const char *format, ...)
va_end(ap); va_end(ap);
} }
/* Log a message using only signal safe functions. */
void
LogMessageVerbSigSafe(MessageType type, int verb, const char *format, ...)
{
va_list ap;
va_start(ap, format);
LogVMessageVerb(type, verb, format, ap);
va_end(ap);
}
void void
LogVHdrMessageVerb(MessageType type, int verb, const char *msg_format, LogVHdrMessageVerb(MessageType type, int verb, const char *msg_format,
va_list msg_args, const char *hdr_format, va_list hdr_args) va_list msg_args, const char *hdr_format, va_list hdr_args)

View File

@ -119,8 +119,10 @@ OsSigHandler(int signo)
if (signo == SIGNAL_FOR_RTLD_ERROR) { if (signo == SIGNAL_FOR_RTLD_ERROR) {
const char *dlerr = dlerror(); const char *dlerr = dlerror();
if (dlerr) if (dlerr) {
LogMessageVerb(X_ERROR, 1, "Dynamic loader error: %s\n", dlerr); LogMessageVerbSigSafe(X_ERROR, 1,
"Dynamic loader error: %s\n", dlerr);
}
} }
#endif /* RTLD_DI_SETSIGNAL */ #endif /* RTLD_DI_SETSIGNAL */

View File

@ -202,59 +202,59 @@ static void logging_format(void)
} while (0) } while (0)
/* boring test message */ /* boring test message */
LogMessageVerb(X_ERROR, 1, "test message\n"); LogMessageVerbSigSafe(X_ERROR, 1, "test message\n");
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, "(EE) test message\n") == 0); assert(strcmp(logmsg, "(EE) test message\n") == 0);
/* long buf is truncated to "....en\n" */ /* long buf is truncated to "....en\n" */
LogMessageVerb(X_ERROR, 1, buf); LogMessageVerbSigSafe(X_ERROR, 1, buf);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(&logmsg[strlen(logmsg) - 3], "en\n") == 0); assert(strcmp(&logmsg[strlen(logmsg) - 3], "en\n") == 0);
/* same thing, this time as string substitution */ /* same thing, this time as string substitution */
LogMessageVerb(X_ERROR, 1, "%s", buf); LogMessageVerbSigSafe(X_ERROR, 1, "%s", buf);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(&logmsg[strlen(logmsg) - 3], "en\n") == 0); assert(strcmp(&logmsg[strlen(logmsg) - 3], "en\n") == 0);
/* strings containing placeholders should just work */ /* strings containing placeholders should just work */
LogMessageVerb(X_ERROR, 1, "%s\n", str); LogMessageVerbSigSafe(X_ERROR, 1, "%s\n", str);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, "(EE) %s %d %u %% %p %i\n") == 0); assert(strcmp(logmsg, "(EE) %s %d %u %% %p %i\n") == 0);
/* literal % */ /* literal % */
LogMessageVerb(X_ERROR, 1, "test %%\n"); LogMessageVerbSigSafe(X_ERROR, 1, "test %%\n");
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, "(EE) test %\n") == 0); assert(strcmp(logmsg, "(EE) test %\n") == 0);
/* character */ /* character */
LogMessageVerb(X_ERROR, 1, "test %c\n", 'a'); LogMessageVerbSigSafe(X_ERROR, 1, "test %c\n", 'a');
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, "(EE) test a\n") == 0); assert(strcmp(logmsg, "(EE) test a\n") == 0);
/* something unsupported % */ /* something unsupported % */
LogMessageVerb(X_ERROR, 1, "test %Q\n"); LogMessageVerbSigSafe(X_ERROR, 1, "test %Q\n");
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strstr(logmsg, "BUG") != NULL); assert(strstr(logmsg, "BUG") != NULL);
LogMessageVerb(X_ERROR, 1, "\n"); LogMessageVerbSigSafe(X_ERROR, 1, "\n");
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
/* string substitution */ /* string substitution */
LogMessageVerb(X_ERROR, 1, "%s\n", "substituted string"); LogMessageVerbSigSafe(X_ERROR, 1, "%s\n", "substituted string");
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, "(EE) substituted string\n") == 0); assert(strcmp(logmsg, "(EE) substituted string\n") == 0);
/* Invalid format */ /* Invalid format */
LogMessageVerb(X_ERROR, 1, "%4", 4); LogMessageVerbSigSafe(X_ERROR, 1, "%4", 4);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, "(EE) ") == 0); assert(strcmp(logmsg, "(EE) ") == 0);
LogMessageVerb(X_ERROR, 1, "\n"); LogMessageVerbSigSafe(X_ERROR, 1, "\n");
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
/* %hld is bogus */ /* %hld is bogus */
LogMessageVerb(X_ERROR, 1, "%hld\n", 4); LogMessageVerbSigSafe(X_ERROR, 1, "%hld\n", 4);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strstr(logmsg, "BUG") != NULL); assert(strstr(logmsg, "BUG") != NULL);
LogMessageVerb(X_ERROR, 1, "\n"); LogMessageVerbSigSafe(X_ERROR, 1, "\n");
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
/* number substitution */ /* number substitution */
@ -262,12 +262,12 @@ static void logging_format(void)
do { do {
char expected[30]; char expected[30];
sprintf(expected, "(EE) %u\n", ui); sprintf(expected, "(EE) %u\n", ui);
LogMessageVerb(X_ERROR, 1, "%u\n", ui); LogMessageVerbSigSafe(X_ERROR, 1, "%u\n", ui);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, expected) == 0); assert(strcmp(logmsg, expected) == 0);
sprintf(expected, "(EE) %x\n", ui); sprintf(expected, "(EE) %x\n", ui);
LogMessageVerb(X_ERROR, 1, "%x\n", ui); LogMessageVerbSigSafe(X_ERROR, 1, "%x\n", ui);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, expected) == 0); assert(strcmp(logmsg, expected) == 0);
@ -281,21 +281,21 @@ static void logging_format(void)
do { do {
char expected[30]; char expected[30];
sprintf(expected, "(EE) %lu\n", lui); sprintf(expected, "(EE) %lu\n", lui);
LogMessageVerb(X_ERROR, 1, "%lu\n", lui); LogMessageVerbSigSafe(X_ERROR, 1, "%lu\n", lui);
read_log_msg(logmsg); read_log_msg(logmsg);
sprintf(expected, "(EE) %lld\n", (unsigned long long)ui); sprintf(expected, "(EE) %lld\n", (unsigned long long)ui);
LogMessageVerb(X_ERROR, 1, "%lld\n", (unsigned long long)ui); LogMessageVerbSigSafe(X_ERROR, 1, "%lld\n", (unsigned long long)ui);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, expected) == 0); assert(strcmp(logmsg, expected) == 0);
sprintf(expected, "(EE) %lx\n", lui); sprintf(expected, "(EE) %lx\n", lui);
LogMessageVerb(X_ERROR, 1, "%lx\n", lui); LogMessageVerbSigSafe(X_ERROR, 1, "%lx\n", lui);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, expected) == 0); assert(strcmp(logmsg, expected) == 0);
sprintf(expected, "(EE) %llx\n", (unsigned long long)ui); sprintf(expected, "(EE) %llx\n", (unsigned long long)ui);
LogMessageVerb(X_ERROR, 1, "%llx\n", (unsigned long long)ui); LogMessageVerbSigSafe(X_ERROR, 1, "%llx\n", (unsigned long long)ui);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, expected) == 0); assert(strcmp(logmsg, expected) == 0);
@ -310,12 +310,12 @@ static void logging_format(void)
do { do {
char expected[30]; char expected[30];
sprintf(expected, "(EE) %d\n", i); sprintf(expected, "(EE) %d\n", i);
LogMessageVerb(X_ERROR, 1, "%d\n", i); LogMessageVerbSigSafe(X_ERROR, 1, "%d\n", i);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, expected) == 0); assert(strcmp(logmsg, expected) == 0);
sprintf(expected, "(EE) %d\n", i | INT_MIN); sprintf(expected, "(EE) %d\n", i | INT_MIN);
LogMessageVerb(X_ERROR, 1, "%d\n", i | INT_MIN); LogMessageVerbSigSafe(X_ERROR, 1, "%d\n", i | INT_MIN);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, expected) == 0); assert(strcmp(logmsg, expected) == 0);
@ -329,22 +329,22 @@ static void logging_format(void)
do { do {
char expected[30]; char expected[30];
sprintf(expected, "(EE) %ld\n", li); sprintf(expected, "(EE) %ld\n", li);
LogMessageVerb(X_ERROR, 1, "%ld\n", li); LogMessageVerbSigSafe(X_ERROR, 1, "%ld\n", li);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, expected) == 0); assert(strcmp(logmsg, expected) == 0);
sprintf(expected, "(EE) %ld\n", li | LONG_MIN); sprintf(expected, "(EE) %ld\n", li | LONG_MIN);
LogMessageVerb(X_ERROR, 1, "%ld\n", li | LONG_MIN); LogMessageVerbSigSafe(X_ERROR, 1, "%ld\n", li | LONG_MIN);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, expected) == 0); assert(strcmp(logmsg, expected) == 0);
sprintf(expected, "(EE) %lld\n", (long long)li); sprintf(expected, "(EE) %lld\n", (long long)li);
LogMessageVerb(X_ERROR, 1, "%lld\n", (long long)li); LogMessageVerbSigSafe(X_ERROR, 1, "%lld\n", (long long)li);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, expected) == 0); assert(strcmp(logmsg, expected) == 0);
sprintf(expected, "(EE) %lld\n", (long long)(li | LONG_MIN)); sprintf(expected, "(EE) %lld\n", (long long)(li | LONG_MIN));
LogMessageVerb(X_ERROR, 1, "%lld\n", (long long)(li | LONG_MIN)); LogMessageVerbSigSafe(X_ERROR, 1, "%lld\n", (long long)(li | LONG_MIN));
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, expected) == 0); assert(strcmp(logmsg, expected) == 0);
@ -357,7 +357,7 @@ static void logging_format(void)
/* pointer substitution */ /* pointer substitution */
/* we print a null-pointer differently to printf */ /* we print a null-pointer differently to printf */
LogMessageVerb(X_ERROR, 1, "%p\n", NULL); LogMessageVerbSigSafe(X_ERROR, 1, "%p\n", NULL);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, "(EE) 0x0\n") == 0); assert(strcmp(logmsg, "(EE) 0x0\n") == 0);
@ -369,7 +369,7 @@ static void logging_format(void)
#else #else
sprintf(expected, "(EE) %p\n", (void*)ptr); sprintf(expected, "(EE) %p\n", (void*)ptr);
#endif #endif
LogMessageVerb(X_ERROR, 1, "%p\n", (void*)ptr); LogMessageVerbSigSafe(X_ERROR, 1, "%p\n", (void*)ptr);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, expected) == 0); assert(strcmp(logmsg, expected) == 0);
ptr <<= 1; ptr <<= 1;
@ -380,20 +380,20 @@ static void logging_format(void)
double d = float_tests[i]; double d = float_tests[i];
char expected[30]; char expected[30];
sprintf(expected, "(EE) %.2f\n", d); sprintf(expected, "(EE) %.2f\n", d);
LogMessageVerb(X_ERROR, 1, "%f\n", d); LogMessageVerbSigSafe(X_ERROR, 1, "%f\n", d);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, expected) == 0); assert(strcmp(logmsg, expected) == 0);
/* test for length modifiers, we just ignore them atm */ /* test for length modifiers, we just ignore them atm */
LogMessageVerb(X_ERROR, 1, "%.3f\n", d); LogMessageVerbSigSafe(X_ERROR, 1, "%.3f\n", d);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, expected) == 0); assert(strcmp(logmsg, expected) == 0);
LogMessageVerb(X_ERROR, 1, "%3f\n", d); LogMessageVerbSigSafe(X_ERROR, 1, "%3f\n", d);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, expected) == 0); assert(strcmp(logmsg, expected) == 0);
LogMessageVerb(X_ERROR, 1, "%.0f\n", d); LogMessageVerbSigSafe(X_ERROR, 1, "%.0f\n", d);
read_log_msg(logmsg); read_log_msg(logmsg);
assert(strcmp(logmsg, expected) == 0); assert(strcmp(logmsg, expected) == 0);
} }