Big Sur - LaunchAgents - Load error 5: input/output error

Hi all,

I am having a mysterious problem trying to load a user LaunchAgent under Big Sur - It is the .plist of gniemetz's automount.sh
Code Block
 https://github.com/gniemetz/automount
for mounting SMB shares via pwd access from the Keychain -

Placed the .sh into /usr/local/bin, chmod 644 and chown user:staff

Placed the LaunchAgent .plist into ~/Library/LaunchAgents (created LaunchAgents it as it didn't exist), same chmod/chown.

Code Block ~/Library
drwxr-xr-x 3 users 96 Nov 1 22:13 LaunchAgents
~/Library/LaunchAgents
-rw-r--r-- 1 users 1038 Nov 1 22:13 it.niemetz.automount.plist
/usr/local
drwxr-xr-x 4 root wheel 128 Nov 1 21:52 bin
/usr/local/bin
-rwxr-xr-x 1 root wheel 30310 Oct 29 21:58 automount.sh

then the following:
Code Block launchctl load -w ~/Library/LaunchAgents/it.niemetz.automount.plist
Load failed: 5: Input/output error

For the life of me, I cannot find anywhere what this means...

Code Block
launchctl start ~/Library/LaunchAgents/it.niemetz.automount.plist

completes with no errors, syntax also parses OK

Code Block plutil -lint ~/Library/LaunchAgents/it.niemetz.automount.plist
/Users//Library/LaunchAgents/it.niemetz.automount.plist: OK

I have added Terminal and /bin/bash to Full Disk Access under Security...

Launching the script manually as /usr/local/bin/automount.sh works fine.

Console shows

Code Block launchctl load:
system.log shows this when load -w is run:
00:27:14 mac-mini-Big-Sur com.apple.xpc.launchd[1] (com.apple.xpc.launchd.user.domain.1000002.100006.Aqua): entering bootstrap mode
Nov 3 00:27:14 mac-mini-Big-Sur com.apple.xpc.launchd[1] (com.apple.xpc.launchd.user.domain.1000002.100006.Aqua): exiting bootstrap mode


For easy reference the .plist is pasted at the end -

Anyone seen this error before?

Thanks!
  • ++

Code Block
Label
it.niemetz.automount
LimitLoadToSessionType
Aqua
RunAtLoad
WatchPaths
/etc/resolv.conf
/Library/Preferences/SystemConfiguration/NetworkInterfaces.plist
/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist
ProgramArguments
/usr/local/bin/automount.sh
--mountall

Answered by DTS Engineer in 807389022
It's like they don't want developers to use it.

Actually, that’s kinda right. We always intended to create a proper API for managing launchd jobs it’s just that for… well… reasons… it took a long time coming. In the meantime, the only alternative was to mess around with launchd property lists and launchctl )-:

The good news is that there are much better options these days:

  • Many of the things that you’d previously did with a launchd daemon are now done with a system extension, managed via the System Extensions framework.

  • For other stuff, you have the SMAppService API.

In both cases the system is responsible for managing the launchd property list, which avoids many of the issues being discussed in this thread. If you can adopt these APIs, I recommend that you do so.

Share and Enjoy

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

Hello, Discovering my plist was not working since the Big Sur update, it seems the issue was my shell script was located in the ~/Documents/ folder, and seen as forbidden for security reasons. I moved my script in another folder (in ~/ ), unload and load again, and it worked.

Hello, the same happened to my system. I placed a small shell script in /usr/local/bin and it worked fine when I call it from the Terminal. After trying to load the launchctl command I got the "Load failed: 5: Input/output error" My plist file was very simple and plutil check was w/o any complains.

[mf@Server]:/Users/xyz/Library/LaunchAgents $ launchctl load local.demo.plist Load failed: 5: Input/output error Try running launchctl bootstrap as root for richer errors.




[mf@Server]:/Users/xyz/Library/LaunchAgents $ plutil local.demo.plist local.demo.plist: OK

After moving this script into /Users/xyz/ it worked fine.

Consider this small script:

% cat /usr/local/bin/greetings.sh 
#! /bin/sh

logger 'Hello Cruel World!'

It’s marked as executable:

% ls -l /usr/local/bin/greetings.sh 
-rwxr-xr-x  1 root  wheel  40  9 Jul 12:23 /usr/local/bin/greetings.sh

Now consider this launchd property list file:

% cat com.example.test665661.plist 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.example.test665661</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/greetings.sh</string>
    </array>
</dict>
</plist>

You can load this as a job:

% launchctl load com.example.test665661.plist 

IMPORTANT Because I didn’t use sudo, this is loaded as a launchd agent in the current session.

And then start it:

% launchctl start com.example.test665661     

And in console you see this:

type: default
time: 12:32:02.647234+0100
process: logger
category: -
message: Hello Cruel World!

I ran this all on macOS 13.4.1 but it should work this way on any version of macOS that supports launchd (so 10.5 and later).

Oh, and to tidy up:

% launchctl unload com.example.test665661.plist
% rm com.example.test665661.plist 
% sudo rm /usr/local/bin/greetings.sh

Share and Enjoy

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

For me, the plist having write access for everyone was the problem. I did chmod go-w on it and it worked.

Why is the launchd system so fragile and uncommunicative? It's like they don't want developers to use it. I've raised a bug with Apple.

https://feedbackassistant.apple.com/feedback/15371740

It's like they don't want developers to use it.

Actually, that’s kinda right. We always intended to create a proper API for managing launchd jobs it’s just that for… well… reasons… it took a long time coming. In the meantime, the only alternative was to mess around with launchd property lists and launchctl )-:

The good news is that there are much better options these days:

  • Many of the things that you’d previously did with a launchd daemon are now done with a system extension, managed via the System Extensions framework.

  • For other stuff, you have the SMAppService API.

In both cases the system is responsible for managing the launchd property list, which avoids many of the issues being discussed in this thread. If you can adopt these APIs, I recommend that you do so.

Share and Enjoy

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

Big Sur - LaunchAgents - Load error 5: input/output error
 
 
Q