diff options
author | James Carlson <james.d.carlson@sun.com> | 2009-05-15 10:13:42 -0400 |
---|---|---|
committer | James Carlson <james.d.carlson@sun.com> | 2009-05-15 10:13:42 -0400 |
commit | a1196271e1d6e6ce9cc40c8b94f5b659935e82bc (patch) | |
tree | f345df14d95b5eaa43386947c7829e04afbda5af /usr/src/lib/libdhcpagent/common/dhcpagent_util.c | |
parent | 738c43b514a3570e657652233a5a19291a328a28 (diff) | |
download | illumos-gate-a1196271e1d6e6ce9cc40c8b94f5b659935e82bc.tar.gz |
PSARC 2009/285 DHCP Client Updates
4783123 dhcp client should allow option names in PARAM_REQUEST_LIST
6553194 nwamd-configured interface is not "primary"; dhcpinfo fails
6667011 DHCP client should have a way to ignore unwanted options
6696321 libdhcpagent needs to use a new contract
6785119 svcs -x output for nwam points users to old phase0 page
6787310 in.ndpd amassing dhcpagent zombie army
6823679 ifconfig hangs when dhcpagent has gone nuts, harming nwamd
6834140 nwam unable to select a known wireless network due to a strong unknown one
6835298 nwam+dhcp keep old lease even though RELEASE_ON_SIGTERM is set
Diffstat (limited to 'usr/src/lib/libdhcpagent/common/dhcpagent_util.c')
-rw-r--r-- | usr/src/lib/libdhcpagent/common/dhcpagent_util.c | 64 |
1 files changed, 54 insertions, 10 deletions
diff --git a/usr/src/lib/libdhcpagent/common/dhcpagent_util.c b/usr/src/lib/libdhcpagent/common/dhcpagent_util.c index e6d95cd0d1..1c381fa08f 100644 --- a/usr/src/lib/libdhcpagent/common/dhcpagent_util.c +++ b/usr/src/lib/libdhcpagent/common/dhcpagent_util.c @@ -19,19 +19,24 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <sys/types.h> +#include <sys/ctfs.h> +#include <sys/contract/process.h> #include <sys/socket.h> #include <sys/time.h> +#include <sys/wait.h> +#include <fcntl.h> +#include <libcontract.h> +#include <libcontract_priv.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> + #include "dhcpagent_ipc.h" #include "dhcpagent_util.h" @@ -78,6 +83,31 @@ dhcp_state_to_string(DHCPSTATE state) return (states[state]); } +static int +init_template(void) +{ + int fd; + int err = 0; + + fd = open64(CTFS_ROOT "/process/template", O_RDWR); + if (fd == -1) + return (-1); + + /* + * Deliver no events, don't inherit, and allow it to be orphaned. + */ + err |= ct_tmpl_set_critical(fd, 0); + err |= ct_tmpl_set_informative(fd, 0); + err |= ct_pr_tmpl_set_fatal(fd, CT_PR_EV_HWERR); + err |= ct_pr_tmpl_set_param(fd, CT_PR_PGRPONLY | CT_PR_REGENT); + if (err != 0 || ct_tmpl_activate(fd) != 0) { + (void) close(fd); + return (-1); + } + + return (fd); +} + /* * dhcp_start_agent(): starts the agent if not already running * @@ -92,6 +122,9 @@ dhcp_start_agent(int timeout) time_t start_time = time(NULL); dhcp_ipc_request_t *request; dhcp_ipc_reply_t *reply; + int ctfd; + pid_t childpid; + ctid_t ct; /* * just send a dummy request to the agent to find out if it's @@ -111,16 +144,20 @@ dhcp_start_agent(int timeout) free(request); return (0); } - if (error != DHCP_IPC_E_CONNECT) { - free(request); - return (-1); - } + if (error != DHCP_IPC_E_CONNECT) + goto fail; + + if ((ctfd = init_template()) == -1) + goto fail; - switch (fork()) { + childpid = fork(); + (void) ct_tmpl_clear(ctfd); + (void) close(ctfd); + + switch (childpid) { case -1: - free(request); - return (-1); + goto fail; case 0: (void) execl(DHCP_AGENT_PATH, DHCP_AGENT_PATH, (char *)0); @@ -130,6 +167,12 @@ dhcp_start_agent(int timeout) break; } + /* wait for the daemon to run and then abandon the contract */ + (void) waitpid(childpid, NULL, 0); + + if (contract_latest(&ct) != -1) + (void) contract_abandon_id(ct); + while ((timeout != -1) && (time(NULL) - start_time < timeout)) { error = dhcp_ipc_make_request(request, &reply, 0); if (error == 0) { @@ -141,6 +184,7 @@ dhcp_start_agent(int timeout) (void) sleep(1); } +fail: free(request); return (-1); } |