How does :kill work?
The :kill method token is kind of cool. Rather than maintaining a pid file or using some grungy invocation of pkill (which almost always is incorrect for services that may run on a system with zones) to find all the processes required to stop your service, you can use the :kill token in your method to simply say "kill off all the processes in this service". Works great with contract type services in startd (but not so much with transient services). You can see smf_method(5) and the developer intro for more details about :kill from the service developer's point of view.
I found out recently that I didn't talk about how the :kill method token works when I talked about general fault isolation in smf(5). It's just so simple that I forgot to mention it. But still, you need to know the key...
Since contracts already take care of grouping the processes for us into services, and extended the appropriate kernel interfaces to allow operations on contracts, we can actually just send a signal to all processes in the contract easily with sigsend(2). So, the contract kill function in svc.startd(1M) is mind-bogglingly simple. All you need is a contract id.
int
contract_kill(ctid_t ctid, int sig, const char *fmri)
{
if (sigsend(P_CTID, ctid, sig) == -1 && errno != ESRCH) {
log_error(LOG_WARNING,
"%s: Could not signal all contract members: %s\n", fmri,
strerror(errno));
return (-1);
}
return (0);
}
Nice, huh? Having contracts as a well-supported kernel feature makes some previously impossible things now possible, and generally makes the life of the restarter author easier. This is, to me, one of the truly significant benefits of having a kernel that evolves in concert with its userland tools.
Technorati Tags: OpenSolaris, Solaris, and smf.
Posted by PJ on August 26, 2005 at 06:46 AM PDT #
Posted by Liane Praza on August 26, 2005 at 02:36 PM PDT #
Posted by vincetang on December 20, 2005 at 07:26 AM PST #