[PATCH v7 04/15] Add LogMessageVerbSigSafe() for logging messages while in signal context

Jon TURNEY jon.turney at dronecode.org.uk
Fri Aug 17 06:22:06 PDT 2012


On 21/06/2012 06:56, Peter Hutterer wrote:
> From: Chase Douglas <chase.douglas-Z7WLFzj8eWMS+FvcfC7Uqw at public.gmane.org>
> 
> [whot: edited to use varargs]
> 
> Signed-off-by: Chase Douglas <chase.douglas-Z7WLFzj8eWMS+FvcfC7Uqw at public.gmane.org>
> Reviewed-by: Peter Hutterer <peter.hutterer-Pf4JEFdB4epeoWH0uzbU5w at public.gmane.org>
> ---
> Changes to previous version:
> - use varargs, not magic preprocessor expansion


> diff --git a/os/log.c b/os/log.c
> index 5394847..a3c1305 100644
> --- a/os/log.c
> +++ b/os/log.c
[...]
> +
> +/* 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. */
>  static void
>  LogSWrite(int verb, const char *buf, size_t len, Bool end_line)
>  {
>      static Bool newline = TRUE;
>  
>      if (verb < 0 || logVerbosity >= verb)
> -        fwrite(buf, len, 1, stderr);
> +        write(2, buf, len);
> +
>      if (verb < 0 || logFileVerbosity >= verb) {
> -        if (logFile) {
> +        if (inSignalContext && logFileFd >= 0) {
> +            write(logFileFd, buf, len);
> +#ifdef WIN32
> +            if (logFlush && logSync)
> +                fsync(logFileFd);
> +#endif
> +        }
> +        else if (!inSignalContext && logFile) {

Um.  I just noticed this whilst trying to build Xserver for MinGW.

Is there a typo here and this should be an #ifndef WIN32 guard around a use of
fsync(), like the other uses of fsync() in log.c?



More information about the xorg-devel mailing list