3

I am developing an application for OSX that can access to WindowServer. This application (lets call it an Agent) is first loaded for every user that is currently logged in. I am searching for running loginwindow processes, and load my plist as each user (with a help of bsexec to set proper context).

  • ps -ef | grep loginwindow

501 90425 1 0 10:46AM ?? 0:01.21 /System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow console

502 90721 90426 0 10:54AM ?? 0:00.36 /System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow

0 91103 90426   0 11:01AM ??         0:02.57 /System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow

Here I have three loginwindow processes 2 for logged users (not active), one for Login Window (active).

  • I run:

      sudo launchctl bsexec 90721 sudo -u 502 launchctl load -wF -S Aqua /Library/LaunchAgents/com.myagent.plist
    

For each of logged users.

  • And

      sudo launchctl bsexec 91103 launchctl load -wF -S LoginWindow /Library/LaunchAgents/com.myagent.plist
    

For my login window.

The problem is my Agent starting on login window (as root) causing error:

May 15 15:47:01 Mac-mini.local WSagent.bin[99201]: kCGErrorFailure: This user is not allowed access to the window system right now.
May 15 15:47:01 Mac-mini.local WSagent.bin[99201]: kCGErrorInvalidConnection: CGSGetEventPort: Invalid connection
May 15 15:47:01 Mac-mini.local WSagent.bin[99201]: _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
May 15 15:47:01 Mac-mini.local WSagent.bin[99201]: CGSRegisterConnectionNotifyProc called with invalid connection
May 15 15:47:01 --- last message repeated 1 time ---
May 15 15:47:01 Mac-mini.local WSagent.bin[99201]: kCGErrorInvalidConnection: CGSSetConnectionProperty: Invalid connection
May 15 15:47:01 Mac-mini.local WSagent.bin[99201]: kCGErrorInvalidConnection: Error enabling suspendResume handling

But when I log in to user, and then log out to Login Window again, my Agent that starts then is created properly and I can access to Window Server without problems.

Problem occurs on newer OSX versions (on 10.6.8 for example it works fine).

TylerH
  • 20,799
  • 66
  • 75
  • 101
Ghulash
  • 31
  • 2

0 Answers0