]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
server: Fix race condition in afs startup.
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 23 Aug 2016 20:58:46 +0000 (22:58 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Tue, 4 Oct 2016 10:21:15 +0000 (12:21 +0200)
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.


No differences found