Greetings,
I'm working on a MacOS preference pane that is used to configure
the options of a faceless background process (a music server).
This process is a BSD process for historical reasons, but will
run under the privileges of a particular user, and not as root.
I want to have a pop-up in the prefs pane that allows the user
to choose to manually launch the server (by clicking a "Start"
button in the pane, or to have the server launch at startup.
Either way, I want to be sure that the server quits when they
log out.
It seems like launchd is likely to be what I want, but there are
a few things I could use some help with.
I have figured out how to create the appropriate plist to make
the server launch at login and quit at shutdown, and that seems
to work fine.
So, I have two questions:
1) Is it possible to set up launchd to not launch the process at
login, but to shut it down at logout?
2) I want this all to be controlled by my preference pane.
Obviously, it's no trouble to get it to write out the required
plist file, but the part I'm not sure about is how to do the
equivalent of a "launchctl load" or "launchctl unload"
operation. I could exec this, I guess, but I prefer to use a
proper C API rather than the exec mechanism whenever I can. I
couldn't make heads or tails out of launch.h, I'm afraid.
Thanks in advance,
--Mike