Peter Memishian writes:
> > > It was unclear to me why contract_latest() needed to be called before
> > > those two things while contract_abandon_id() could be done afterwards --
> > > but I didn't dig into the libcontract API details.
> >
> > We're all building those grass runways on the island.
>
> Does that mean the current structure is necessary?
I based it on the other code I'd seen. I'll admit that I don't really
fully understand the private contract interfaces.
I spent some time testing this, and I found that I don't need to do
that at all. Both the contract_latest() and the contract_abandon_id()
work fine if done after the child has exited. I used 'ps -o ctid' to
show that I still had a separate contract for dhcpagent, and 'ctstat'
to show that the contract parameters were all the same.
My update for this review comment (simplifying the code) is:
diff -r 14c9daa6faaf usr/src/lib/libdhcpagent/common/dhcpagent_util.c
--- a/usr/src/lib/libdhcpagent/common/dhcpagent_util.c Fri May 15 08:41:49
2009 -0400
+++ b/usr/src/lib/libdhcpagent/common/dhcpagent_util.c Fri May 15 09:52:38
2009 -0400
@@ -152,10 +152,6 @@
childpid = fork();
- /* parent needs contract id */
- if (childpid != 0 && childpid != (pid_t)-1 &&
- contract_latest(&ct) == -1)
- ct = -1;
(void) ct_tmpl_clear(ctfd);
(void) close(ctfd);
@@ -173,7 +169,8 @@
/* wait for the daemon to run and then abandon the contract */
(void) waitpid(childpid, NULL, 0);
- if (ct != -1)
+
+ if (contract_latest(&ct) != -1)
(void) contract_abandon_id(ct);
while ((timeout != -1) && (time(NULL) - start_time < timeout)) {
--
James Carlson, Solaris Networking <james.d.carlson at sun.com>
Sun Microsystems / 35 Network Drive 71.232W Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677