Spawn a screen session from launch daemon

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-13 11:52:31

问题


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 session 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


回答1:


Apparently you can't detach (using -D) in the system bootstrap. You could do this in a launchagent (or otherwise within your user bootstrap).




回答2:


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.



来源:https://stackoverflow.com/questions/2304847/spawn-a-screen-session-from-launch-daemon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!