From: Florian Forster Date: Wed, 30 Sep 2009 20:49:16 +0000 (+0200) Subject: unixsock plugin: Fix a (well hidden) race condition. X-Git-Tag: collectd-4.7.4~3 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=5b5fff5bbdc5515d7f4c2a01df47373f4ac44847;hp=5b5fff5bbdc5515d7f4c2a01df47373f4ac44847;p=collectd.git unixsock plugin: Fix a (well hidden) race condition. Within the client handling thread, fdopen is called twice on the file descriptor passed to the thread. Later those file handles are closed like: fclose (fhin); fclose (fhout); This is a race condition, because the first call to fclose will close the file descriptor. The second call to fclose will try the same. Usually, it would fail silently and all is well. On a busy machine, however, another thread may just have opened a file or accepted a socket. In that case an arbitrary file descriptor is closed. If the file descriptor is opened yet again fast enough, data may even end up in a totally wrong location. As a work-around the file descriptor is not dup'ed so each fdopen operates on its own file descriptor. As an alternative the "r+" mode and a single file handle may be suitable, too. Many thanks to Sven Trenkel for pointing me into the right directioin :) ---