From: Andre Noll Date: Tue, 23 Aug 2016 20:58:46 +0000 (+0200) Subject: server: Fix race condition in afs startup. X-Git-Tag: v0.5.7~16^2 X-Git-Url: http://git.tuebingen.mpg.de/?a=commitdiff_plain;h=2e415410fc22b15d789b87b034c30bf8a998b5da;hp=2e415410fc22b15d789b87b034c30bf8a998b5da;p=paraslash.git server: Fix race condition in afs startup. After server_init() returns, the server accepts connections on the TCP command socket. If an afs command arrives on the command socket, the server process forks and the resulting child process (the command handler) connects to the local afs socket. However, this socket is created by the afs process which was forked from the server process in server_init(). It is therefore possible that the command handler connects before the afs process started to listen on the local afs socket. In this case, the connection, hence the command fails. This commit fixes the race condition by letting the parent process block on read(2) on the afs socket. The afs process writes a byte to the other end of the socket after it has completed its setup, causing the parent process to resume. For this to work, we need a connection-mode byte stream for the communication between the server and the afs process, rather than the connectionless datagram socket we have now. There is no particular reason to prefer a datagram socket here, so let's switch to SOCK_STREAM. ---