Consistently save and restore errno
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 8 Sep 2014 19:18:22 +0000 (20:18 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 29 Oct 2014 14:02:37 +0000 (14:02 +0000)
commitc7fdbe77ddd3d5dee4e0b9d3f88a338ef4812f42
tree033aa4389c3dfa9150403d1cd25566b26c48b62d
parent7bcfcec523324fbe38e00f705833aecbe62d8408
Consistently save and restore errno

Some functions in dbus-transport-socket.c make a (wrapped)
socket syscall, then call other APIs, then test the result and
errno of the socket syscall.

This would break horribly if those "other APIs" overwrote errno with
their own value (... and this is part of why errno is an awful API).

Notably, if running under DBUS_VERBOSE, _dbus_verbose() is basically
fprintf(), which sets errno; and our Unix fd-passing support
makes calls of the form _dbus_verbose ("Read/wrote %i unix fds\n", n)
between the syscall and the result processing.

Maybe one day we'll convert all of dbus' syscall wrappers to either
raise a DBusError, or use the "negative errno" convention that systemd
borrowed from the Linux kernel, and in particular, we would need to
do that if we ever ported it to a platform where socket error reporting
was not basically errno. However, in practice everyone uses something
derived from BSD sockets, so "this sets errno, you know what errno is"
is a good enough internal API if we make sure to use it correctly.

Nothing calls _dbus_get_is_errno_nonzero(), so I just removed it instead
of converting it to the new calling convention.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83625
dbus/dbus-nonce.c
dbus/dbus-server-socket.c
dbus/dbus-sysdeps-unix.c
dbus/dbus-sysdeps-win.c
dbus/dbus-sysdeps.c
dbus/dbus-sysdeps.h
dbus/dbus-transport-socket.c