music player daemon (fork)
Go to file
arcnmx 0a81e462db event/SocketEvent: remove FD before closing socket
SocketEvent knows the FD is still open and is about to close it, so
it's unnecessary to rely on the kernel (via AbandonFD) to clean up the
epoll_wait list.

### Why this is relevant

- `AbandonFD` assumes that upon closing the socket, the FD will be automatically removed from the epoll list. That fd is associated with a reference to the `SocketEvent`, so this is an important and dangerous assumption to get wrong. In the case that the FD isn't immediately removed from the list by the kernel, the event loop can crash due to the `SocketEvent` being destroyed and it being a use-after-free bug at that point.
- If a socket FD happens to be duplicated, then closing the SocketEvent FD will not automatically remove it from epoll, and will trigger said bug/crash. It is only automatically removed when all FD references to the underlying socket/resource are closed?
- A `fork()` is one example where a socket FD can be duplicated and result in this situation.
    - `CLOEXEC` might be considered mitigation for this but also introduces a race condition where the crash can occur between a `fork()` and `exec()` without additional synchronization to freeze the event loop.

One could argue the mpd event loop isn't fork-safe, and thus should be allowed to use `AbandonFD` however it likes. A decision on whether this is intended should probably be declared; but either way this fix seems appropriate in cases where `Abandon` isn't actually necessary. It also might be possible to fix `AbandonFD` to mark the `SocketEvent` as removed without using `EPOLL_CTL_DEL`?

[edit: made this dependent on HAVE_THREADED_EVENT_LOOP which is always
true for MPD, but not for ncmpc, for example - mk]
2020-12-04 10:32:46 +01:00
.github Create FUNDING.yml 2020-01-20 14:30:52 +01:00
android increment version number to 0.22.1 2020-09-23 16:15:44 +02:00
build build/pkg-config.sh: add comment 2019-02-22 12:39:59 +01:00
doc Merge branch 'v0.22.x' into master 2020-11-11 12:43:50 +01:00
python/build lib/nfs/patches: disable the snprintf->sprintf_s alias 2020-10-17 13:56:02 +02:00
src event/SocketEvent: remove FD before closing socket 2020-12-04 10:32:46 +01:00
subprojects test/meson.build: install GTest from fallback Meson wrap 2020-06-04 14:56:43 +02:00
systemd systemnd: configure LimitMEMLOCK for io_uring 2020-06-09 21:09:00 +02:00
test test/util/TestException: new unit test 2020-12-02 15:09:47 +01:00
win32 win32/build.py: add -D_FORTIFY_SOURCE=0 2020-09-04 14:33:11 +02:00
.clang-format Add .clang-format 2020-05-27 18:58:55 +08:00
.gitignore .gitignore: add emacs lsp-mode files 2020-05-26 21:07:56 +02:00
.travis.yml macos: change CI xcode to 10.3 for c++17 support 2020-06-04 08:35:02 +08:00
AUTHORS copyright year 2020 2020-01-18 19:23:49 +01:00
COPYING Update the text of the GPLv2, this fixes the address and a few other oddities. 2008-12-20 19:02:09 -08:00
meson_options.txt meson_options.txt: disable the "smbclient" plugin by default 2020-10-28 17:21:27 +01:00
meson.build increment version number to 0.22.4 2020-11-06 16:14:23 +01:00
mpd.svg import MPD SVG icon 2014-07-14 19:04:46 +02:00
NEWS Merge branch 'v0.22.x' 2020-11-16 09:41:20 +01:00
README.md release v0.20.7 2017-05-15 23:01:49 +02:00
valgrind.suppressions valgrind.suppressions: add GObject/libgcrypt/libsmbclient suppressions 2019-02-05 22:53:02 +01:00

Music Player Daemon

http://www.musicpd.org

A daemon for playing music of various formats. Music is played through the server's audio device. The daemon stores info about all available music, and this info can be easily searched and retrieved. Player control, info retrieval, and playlist management can all be managed remotely.

For basic installation instructions read the manual.

Users

Developers

Legal

MPD is released under the GNU General Public License version 2, which is distributed in the COPYING file.