4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <sys/types.h>
30 #include <libinetutil.h>
31 #include <dhcpagent_util.h>
35 #include "interface.h"
36 #include "script_handler.h"
40 * async_start(): starts an asynchronous command on a state machine
42 * input: dhcp_smach_t *: the state machine to start the async command on
43 * dhcp_ipc_type_t: the command to start
44 * boolean_t: B_TRUE if the command was started by a user
45 * output: boolean: B_TRUE on success, B_FALSE on failure
49 async_start(dhcp_smach_t
*dsmp
, dhcp_ipc_type_t cmd
, boolean_t user
)
51 if (dsmp
->dsm_async
.as_present
) {
54 dsmp
->dsm_async
.as_cmd
= cmd
;
55 dsmp
->dsm_async
.as_user
= user
;
56 dsmp
->dsm_async
.as_present
= B_TRUE
;
62 * async_finish(): completes an asynchronous command
64 * input: dhcp_smach_t *: the state machine with the pending async command
66 * note: should only be used when the command has no residual state to
71 async_finish(dhcp_smach_t
*dsmp
)
74 * be defensive here. the script may still be running if
75 * the asynchronous action times out before it is killed by the
76 * script helper process.
79 if (dsmp
->dsm_script_pid
!= -1)
81 dsmp
->dsm_async
.as_present
= B_FALSE
;
85 * async_cancel(): cancels a pending asynchronous command
87 * input: dhcp_smach_t *: the state machine with the pending async command
88 * output: boolean: B_TRUE if cancellation was successful, B_FALSE on failure
92 async_cancel(dhcp_smach_t
*dsmp
)
94 if (!dsmp
->dsm_async
.as_present
)
96 if (dsmp
->dsm_async
.as_user
) {
98 "async_cancel: cannot abort command %d from user",
99 (int)dsmp
->dsm_async
.as_cmd
);
103 dhcpmsg(MSG_DEBUG
, "async_cancel: command %d aborted",
104 (int)dsmp
->dsm_async
.as_cmd
);