[launchd-dev] A process is started by root (daemon). Can it unload a background process, started by an ordinary user? (agent)

Nick eveningnick at gmail.com
Mon Jun 13 15:34:07 PDT 2011


Hello!
I have a daemon, that is launched with root privileges and works with the
network.
And I would like this daemon to be able to unload an agent, that is started
by a user.

I have read about bootstrap namespaces, but I am not sure I have understood
correctly what was meant.
Can you please point me on how (if it is possible) to do this?

I tried the following:
first, i listed all the background apps that are loaded by launchd into the
current user's bootstrap namespace
$ launchctl list
among other lines, i got the output:
# com.eveningnick.myagent

then i typed:
$ sudo launchctl list
and, as expected, I haven't got my "com.eveningnick.myagent" there, instead
i have a daemon
# com.eveningnick.mydaemon

there is a command that allows to let an another command be executed "from a
bootstrap namespace":
(quote from "man launchctl"):
     bsexec PID command [args]
              This executes the given command in the same Mach bootstrap
              namespace hierachy as the given PID.

i found that my agent has PID which equals to 4724
so, I have typed:
$ sudo launchctl bsexec 4724 launchctl list
I have noticed the daemon, but not an agent in the output.

I tried the same with Finder's PID - and got the daemon again.
Why does this happen?
How should one use this bsexec option? Or a different approach should be
used here?
(I need a daemon to be able  to enumerate all users bootstrap spaces and
unload an agent from each of them, if it had been previously loaded)

Thank you
Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/launchd-dev/attachments/20110614/bc8eac14/attachment.html>


More information about the launchd-dev mailing list