Spawn a screen session from launch daemon
I've written a launchd .plist which should attach a debugger to the WindowServer when it launches. The main part of the script looks like
screen -D -m -S "WindowServer Debugger" \
gdb \
-x $GDBSCRIPT \
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/Resources/WindowServer \
$WSPID
This starts a detached screen s开发者_运维问答ession in which gdb is attached to WindowServer.
However, this seems to trigger an error condition in launchd under Snow Leopard, causing it to spout out error messages to the log:
com.apple.launchd[1] (0x10011c070.anonymous.screen[961]) Bug: launchd_core_logic.c:8250 (23932):0
com.apple.launchd[1] (0x10011c070.anonymous.screen[961]) Switching sessions is not allowed in the system Mach bootstrap.
com.apple.launchd[1] (0x10011c070.anonymous.screen[961]) _vprocmgr_switch_to_session(): kr = 0x44c
I should note that the "... not allowed in the system Mach bootstrap" messages occur regardless of how long it has been since system boot.
Is there a workaround to this so that I can spawn my screen session?
According to the manpage for launchd,
Daemons should not attempt to display UI or interact directly with a user's login session.
This might suggest that launchd is seeing this behavior as interacting with another session and denying it. The code is here but I'm not familiar with it: http://launchd.macosforge.org/trac/browser/trunk/launchd/src/launchd_core_logic.c#L8250
Apparently you can't detach (using -D) in the system bootstrap. You could do this in a launchagent (or otherwise within your user bootstrap).
I was experiencing this problem using screen version 4.0.3. I built the latest version available (4.1.dev) on git://git.sv.gnu.org/screen.git and that fixed the problem for me.
精彩评论