NetworkManager Dispatcher Scripts
I ran into a perplexing problem with NetworkManager dispatcher scripts. The solution was straightforward but finding that solution was frustrating.
The dispatcher allows users to run scripts when toggling the network connection. For example, in one network location a user wants to mount certain shares and in another location not mount those shares and likely mount different shares.
The dispatcher works as planned, but there are caveats associated with any script stored in /etc/NetworkManager/dispatcher.d
. Scripts must be:
- A regular file.
- Owned by root.
- Executable by the owner.
- Writable only by the owner.
- Not set-uid.
Only Linux developers conceive such rules for a directory that can be modified only with administrator privileges.
The puzzle for me is some of my dispatcher scripts run other scripts. Some of those dispatcher scripts ran without incident and others did not. While monitoring /var/log/syslog
I noticed a repeating error message.
Script '/etc/NetworkManager/dispatcher.d/XX-YYYY' exited with error status 1.
Surfing the web revealed many people asking about that specific error but my searching found nothing specific.
The bash documentation provides clues about these specific error numbers. For example, 127 means the command was not found. 2 means improper use of shell built-ins.
The killer is error code 1 means general error. Basically none of the other exit codes apply. No clues are provided about the nature of the general error.
Eventually I discovered that in my case the root cause was a lack of a full path or a $PATH variable in the scripts. No, really, the infamous exited with error status 1
messages are caused by $PATH failures.
NetworkManager dispatcher scripts do not run in any defined environment. There is no predefined $PATH.
In my case, adding the full path to commands resolved my related headaches.
This is a classic example of uninformative error messages. Classic WTF.
Posted: Usability Tagged: General
Category:Next: Distraction-Free Writing
Previous: The Internet Is Becoming a Cesspool