FROM : Hamish Allan
DATE : Fri Feb 15 21:52:14 2008
Hi Ishan,
On 15 Feb 2008, at 05:43, Ishan Mehta wrote:
> A daemon and an agent - both also will not solve the purpose.
>
> Because, if a system daemon listens on a single port and keeps on
> listening for the requests, and since launchd itself does not
> terminate for a logging out user - also it does not terminate my
> daemon - there would be multiple user specific daemons running on
> the system.
Firstly, let's stick to Mac OS X terminology. A daemon is a background
process not tied to any particular user (could be running as root,
nobody, _www, etc.); an agent is a background process running on
behalf of a particular user.
Your main problem is that your agent doesn't terminate. Maybe you're
running 10.4, in which launchd didn't put everything in the right
bootstrap namespace. Anyway, if you need to support 10.3 you'll need
to use startup and login items on 10.3 and you can do so on 10.4 too
(on 10.5, launchd largely works properly).
> - Suppose, we still start it by listening on a unique port (or may
> be using IPC / File communication can be used). And also have a
> separate system daemon which listens on a fixed port for the
> requests from outside.
Yes.
> Upon receiving the request from the outside user, the request would
> not have any data to determine which 'user specific daemon' to
> communicate with.
Read TN2083 again, paying particular attention to "bootstrap
namespaces". It's worth reading TN2083 several times :)
> As such, the daemon does not require any kind of request. Upon
> connection from the client, it only sends back the response based on
> the current user's login and some other related properties from
> environment and the system.
I'm not sure I understand what you mean by this.
> My daemon would function properly only if on logout some how it gets
> a notification to self terminate. Since launchd itself does not
> terminate, or send out the SIGTERM signal on logout, my daemon does
> not know of the fact that the user has logged out.
There are other ways, e.g. if your agent has a connection to the
window server, it should receive a kAEQuitApplication Apple Event.
> Some interesting things also happened yesterday.
>
> I also tried the LogoutHook. The script attached to LogoutHook used
> to send the SIGTERM signal to my daemon (using killall). This
> worked Ok for once. But, when I logged in to the system with the
> same user, since the launchd for this user was already running at
> this time, it did not start my daemon on login (my daemon is having
> RunAtLoad set to true). My daemon would only start on startup of
> the launchd itself. When user logs out - launchd does not
> terminate, so when the same user logs in again, 'RunAtLoad' would
> not be considered.
As Shawn mentioned, your agent should be running in the Aqua context.
It's probably running in the "Background" context (per-user, not per-
login).
> Another thing that I tried was putting "killall -u $USER launchd" in
> the LogoutHook script. This works a bit strange.
You shouldn't kill launchd in the normal course of things. See if
changing the context works, and see how you get on with login items
pre-Leopard.
> Sorry to keep on troubling you all.
Not at all.
Best wishes,
Hamish
DATE : Fri Feb 15 21:52:14 2008
Hi Ishan,
On 15 Feb 2008, at 05:43, Ishan Mehta wrote:
> A daemon and an agent - both also will not solve the purpose.
>
> Because, if a system daemon listens on a single port and keeps on
> listening for the requests, and since launchd itself does not
> terminate for a logging out user - also it does not terminate my
> daemon - there would be multiple user specific daemons running on
> the system.
Firstly, let's stick to Mac OS X terminology. A daemon is a background
process not tied to any particular user (could be running as root,
nobody, _www, etc.); an agent is a background process running on
behalf of a particular user.
Your main problem is that your agent doesn't terminate. Maybe you're
running 10.4, in which launchd didn't put everything in the right
bootstrap namespace. Anyway, if you need to support 10.3 you'll need
to use startup and login items on 10.3 and you can do so on 10.4 too
(on 10.5, launchd largely works properly).
> - Suppose, we still start it by listening on a unique port (or may
> be using IPC / File communication can be used). And also have a
> separate system daemon which listens on a fixed port for the
> requests from outside.
Yes.
> Upon receiving the request from the outside user, the request would
> not have any data to determine which 'user specific daemon' to
> communicate with.
Read TN2083 again, paying particular attention to "bootstrap
namespaces". It's worth reading TN2083 several times :)
> As such, the daemon does not require any kind of request. Upon
> connection from the client, it only sends back the response based on
> the current user's login and some other related properties from
> environment and the system.
I'm not sure I understand what you mean by this.
> My daemon would function properly only if on logout some how it gets
> a notification to self terminate. Since launchd itself does not
> terminate, or send out the SIGTERM signal on logout, my daemon does
> not know of the fact that the user has logged out.
There are other ways, e.g. if your agent has a connection to the
window server, it should receive a kAEQuitApplication Apple Event.
> Some interesting things also happened yesterday.
>
> I also tried the LogoutHook. The script attached to LogoutHook used
> to send the SIGTERM signal to my daemon (using killall). This
> worked Ok for once. But, when I logged in to the system with the
> same user, since the launchd for this user was already running at
> this time, it did not start my daemon on login (my daemon is having
> RunAtLoad set to true). My daemon would only start on startup of
> the launchd itself. When user logs out - launchd does not
> terminate, so when the same user logs in again, 'RunAtLoad' would
> not be considered.
As Shawn mentioned, your agent should be running in the Aqua context.
It's probably running in the "Background" context (per-user, not per-
login).
> Another thing that I tried was putting "killall -u $USER launchd" in
> the LogoutHook script. This works a bit strange.
You shouldn't kill launchd in the normal course of things. See if
changing the context works, and see how you get on with login items
pre-Leopard.
> Sorry to keep on troubling you all.
Not at all.
Best wishes,
Hamish
| Related mails | Author | Date |
|---|---|---|
| Ishan Mehta | Feb 13, 11:19 | |
| Finlay Dobbie | Feb 13, 18:15 | |
| Ishan Mehta | Feb 14, 06:16 | |
| Hamish Allan | Feb 15, 00:15 | |
| Ishan Mehta | Feb 15, 06:43 | |
| Shawn Erickson | Feb 15, 18:45 | |
| Hamish Allan | Feb 15, 21:52 | |
| Finlay Dobbie | Feb 18, 10:12 | |
| Ishan Mehta | Feb 18, 12:16 |






Cocoa mail archive

