From: Petr Lautrbach Date: Thu, 10 Mar 2016 09:19:56 +0000 (+0100) Subject: socket_address_listen - do not rely on errno X-Git-Tag: v230~279^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a0c9496cc826957fe0f3926f619e073f17a9ab4d;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/basic/socket-label.c b/src/basic/socket-label.c index 35e9573aa4a..65509be901f 100644 --- a/src/basic/socket-label.c +++ b/src/basic/socket-label.c @@ -122,7 +122,7 @@ int socket_address_listen( r = mac_selinux_bind(fd, &a->sockaddr.sa, a->size); - if (r < 0 && errno == EADDRINUSE) { + if (r == -EADDRINUSE) { /* Unlink and try again */ unlink(a->sockaddr.un.sun_path); r = bind(fd, &a->sockaddr.sa, a->size);