From ef462ab57f0ba739629194e6c071815d521c7955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 11 May 2015 09:16:07 +0200 Subject: [PATCH] libroot: ensure that the launch_daemon doesn't wait for itself. * The launch_daemon might indirectly call get_launch_daemon_port() which may cause a deadlock. Just fail in this case. --- src/system/libroot/os/launch.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/system/libroot/os/launch.cpp b/src/system/libroot/os/launch.cpp index d3812e1fd1..025cbc6523 100644 --- a/src/system/libroot/os/launch.cpp +++ b/src/system/libroot/os/launch.cpp @@ -16,9 +16,18 @@ static port_id sLaunchDaemonPort = -1; port_id BPrivate::get_launch_daemon_port() { - if (sLaunchDaemonPort < 0) + if (sLaunchDaemonPort < 0) { sLaunchDaemonPort = find_port(B_LAUNCH_DAEMON_PORT_NAME); + port_info info; + if (get_port_info(sLaunchDaemonPort, &info) == B_OK + && info.team == find_thread(NULL)) { + // Make sure that the launch_daemon doesn't wait on itself + sLaunchDaemonPort = -1; + return -1; + } + } + return sLaunchDaemonPort; }