Using BundleProgram key and changing executable path

Hello! Here is some simple scenario:

  1. There is an app installed, let's say /Applications/Xcode.app
  2. That app hosts a LaunchAgent, which is using new BundleProgram key, e.g. Contents/MacOS/helper
  3. User decides to rename the app to Xcode14.2.app
  4. When the time comes for helper to run, it can't

It looks like launchd still tries to access helper by its old path, not new one (/Applications/Xcode12.4.app/Contents/MacOS/helper)

From launchd.log:

<Warning>: Could not find and/or execute program specified by service: 2: No such file or directory: Contents/MacOS/helper
<Error>: Service could not initialize: access(/Applications/Xcode.app/Contents/MacOS/helper, X_OK) failed with errno 2 - No such file or directory, error 0x6f - Invalid or missing Program/ProgramArguments
...
<Notice>: exited due to exit(78)
...
<Notice>: cannot spawn: service is in penalty box

Then this cannot spawn spams a lot in launchd.log

Also I noticed one thing with KeepAlive agents. After renaming to Xcode14.2.app I can run sudo launchctl procinfo $pid and see that program path is new, but responsible path is still old.

I've tried to fight it by calling unregister() async and then register(), but it doesn't help at all. The behavior persists even if I uninstall the app, clean up manually by launchctl bootout and install again! Reboot doesn't help also. Crazy.

The only solution I see is to rollback to Program/ProgramArguments. In case the bundle path somehow changes, my script was doing launchctl bootout, sed plists with new paths, launchctl bootstrap.

Is it a bug? or some sort of misunderstanding from my side?

There is an app installed, let's say /Applications/Xcode.app

I’m confused. Are you just using Xcode as an example here? Or are you working with same app service within Xcode?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Sorry, you can read it as "MyApp" or "ExampleApp". No relation to Xcode, just a poor choice of example name

OK, thanks for clarifying.

Earlier you wrote:

Is it a bug?

It certainly seems that way to me. The whole point of BundleProgram is that it’s supposed to handle the bundle moving. Please re-test on the latest macOS 13.2 beta (currently 22D5027d) and, if you still see the problem, file a bug.

I’d appreciate you posting your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Using BundleProgram key and changing executable path
 
 
Q