Re: Questions about launchd
Re: Questions about launchd
- Subject: Re: Questions about launchd
- From: Terry Lambert <email@hidden>
- Date: Sat, 25 Aug 2007 04:30:56 -0700
On Aug 25, 2007, at 2:10 AM, Finlay Dobbie wrote:
On 25/08/07, Terry Lambert <email@hidden> wrote:
The point of forcing you to write wrappers around standard tools
instead of doing what the tool does is to ensure you that when the
system is updated, you are guaranteed that the tools are updated at
the same time that the kernel and other system components are
updated,
so your code will continue working, even if we change the system
interface used by the tool.
However, I'm fairly sure you don't provide any guarantees that the
arguments or output of the tool will remain the same across releases,
so surely this is just moving the fragility to a different layer?
Certain command conform to standards, and for those commands, we more
or less say we expect that they will continue to conform to standards.
For the "ps" example I gave, that means that the "-p" and "-o"
arguments will be supported, and they will behave as written, so long
as there is no overriding reason for that to stay true. So even if
the default display output changes, there are command line options to
get you output in the same format each time that most likely won't.
-
If you really find this concerning in more than a "We Fear Change"
sort of way, then all you need to do is support putting a command
format string with arguments in your plist file, along with a command
parsing format string, and a line number in the output (or a regex,
etc.).
For the output formatting of your command, you include everything you
thing is relevant as arguments to the sprintf() that creates the
command string to the popen(), and then use the positional argument
qualifiers to select which one(s) to include, e.g.:
char *proc_name = "launchd";
pid_t proc_pid = 1;
/*
* load format string from plist...
* use "%1$d" for proc_pid parameter
* use "%2$s" for proc_name parameter
*/
...
/*
* build command line using positional parameter format strings
* to let us pick and choose which parameters we want to pass
* to the actual command we're going to use to get the data.
*/
sprintf(cmdbuf, fmtstring, proc_pid, proc_name);
...pretty trivial.
If you're looking for me to guarantee thing won't change, well, you're
looking to the wrong person. But if I had to guess, I'd guess on the
side of commands that have to conform to standards changing a lot less
often the data interfaces to kernel data that could change on every
software update.
Obviously, the best possible scenario for the original question would
be to remember whether or not you opened the file in the first place,
rather than depending on being able to ask the system if you called
open earlier in your own operation.
-- Terry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden