Bug 73339

Summary: libwayland: the library should not print anything to stderr
Product: Wayland Reporter: nfxjfg
Component: waylandAssignee: Wayland bug list <wayland-bugs>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description nfxjfg 2014-01-07 00:14:18 UTC
For example, the library prints a message to stderr if the XDG_RUNTIME_DIR envrionment variable is not set:

http://cgit.freedesktop.org/wayland/wayland/tree/src/wayland-client.c?id=cd0dccd01e16fa404e03974d30ded3aebdb1c4bc#n636

There are other cases.

A library should normally never print anything, unless it can be overridden by setting a message callback. Outputting something, even to stderr, can cause for terminal programs which want to keep their output clean, especially in case of non-fatal errors, or for example catch the error message and send it somewhere else.
Comment 1 Pekka Paalanen 2014-02-21 06:44:17 UTC
http://cgit.freedesktop.org/wayland/wayland/commit/?id=52a77fca573705b6ac9b0e23747feea83740ab2f
should fix part of the prints, but I guess the message you referred to is still there?

OTOH, see
http://cgit.freedesktop.org/wayland/wayland/commit/?id=a7524ed0d4cc4fcf8a0c5201618a4dfcd20f9499
which is going the opposite way. Is that ok?

libwayland has at least 3 different libraries.
Comment 2 nfxjfg 2014-02-21 07:53:53 UTC
Well, you're almost there.

Remember how xlib had only a process wide error handler, and everyone hated it? You're making the same mistake.

This is a very common mistake library designers do, and many libraries suffer from this mistake - or rather, libraries using other libraries suffer from it, because now they have to fight with other libraries for the log callback. That everyone makes this error doesn't make it any less wrong.

I suggest that wl_log gets a context argument, and that the wl_log_handler can be set per-context by the library user.

(Maybe this is less severe than the xlib issue, because wl_log_handler really is only a log function and not more, but still.)
Comment 3 Kristian Høgsberg 2014-04-30 19:20:46 UTC
wl_log is only for logging not for handling protocol errors.  If we add
a mechanism for handling protocol errors, it will be a per-object handler.

With that, this handles the remaining stderr printing:

commit 88f3bd84c8ea8f0b3526f970388ef76baa231fe2
Author: Kristian Høgsberg <krh@bitplanet.net>
Date:   Wed Apr 30 12:18:52 2014 -0700

    Avoid printing to stderr
    
    Use wl_log in the last few places where we print to stderr.  Remove
    logging in a couple of places where we properly return an error code.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=73339

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.