socket_address_listen - do not rely on errno
authorPetr Lautrbach <plautrba@redhat.com>
Thu, 10 Mar 2016 09:19:56 +0000 (10:19 +0100)
committerPetr Lautrbach <plautrba@redhat.com>
Thu, 10 Mar 2016 09:34:37 +0000 (10:34 +0100)
commita0c9496cc826957fe0f3926f619e073f17a9ab4d
tree1f4fc19ef7cef27fdf851af386338418ff14c1d8
parentc41d3b3a0ca1c53cbf05563f00bcef72db58d9b0
socket_address_listen - do not rely on errno

Currently socket_address_listen() calls mac_selinux_bind() to bind a UNIX
socket and checks its return value and errno for EADDRINUSE. This is not
correct. When there's an SELinux context change made for the new socket,
bind() is not the last function called in mac_selinux_bind(). In that
case the last call is setfscreatecon() from libselinux which can change
errno as it uses access() to check if /proc/thread-self is available.
It fails on kernels before 3.17 and errno is set to ENOENT.

It's safe to check only the return value at it's set to -errno.
src/basic/socket-label.c