1/* 2 * Copyright (c) 2010 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of Apple Inc. ("Apple") nor the names of its 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * 30 * Portions of this software have been released under the following terms: 31 * 32 * (c) Copyright 1989-1993 OPEN SOFTWARE FOUNDATION, INC. 33 * (c) Copyright 1989-1993 HEWLETT-PACKARD COMPANY 34 * (c) Copyright 1989-1993 DIGITAL EQUIPMENT CORPORATION 35 * 36 * To anyone who acknowledges that this file is provided "AS IS" 37 * without any express or implied warranty: 38 * permission to use, copy, modify, and distribute this file for any 39 * purpose is hereby granted without fee, provided that the above 40 * copyright notices and this notice appears in all source code copies, 41 * and that none of the names of Open Software Foundation, Inc., Hewlett- 42 * Packard Company or Digital Equipment Corporation be used 43 * in advertising or publicity pertaining to distribution of the software 44 * without specific, written prior permission. Neither Open Software 45 * Foundation, Inc., Hewlett-Packard Company nor Digital 46 * Equipment Corporation makes any representations about the suitability 47 * of this software for any purpose. 48 * 49 * Copyright (c) 2007, Novell, Inc. All rights reserved. 50 * Redistribution and use in source and binary forms, with or without 51 * modification, are permitted provided that the following conditions 52 * are met: 53 * 54 * 1. Redistributions of source code must retain the above copyright 55 * notice, this list of conditions and the following disclaimer. 56 * 2. Redistributions in binary form must reproduce the above copyright 57 * notice, this list of conditions and the following disclaimer in the 58 * documentation and/or other materials provided with the distribution. 59 * 3. Neither the name of Novell Inc. nor the names of its contributors 60 * may be used to endorse or promote products derived from this 61 * this software without specific prior written permission. 62 * 63 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 64 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 65 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 66 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY 67 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 68 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 69 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 70 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 71 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 72 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 73 * 74 * @APPLE_LICENSE_HEADER_END@ 75 */ 76 77/* 78** 79** NAME: 80** 81** dginit.c 82** 83** FACILITY: 84** 85** Remote Procedure Call (RPC) 86** 87** ABSTRACT: 88** 89** 90** 91** 92*/ 93 94#include <dg.h> 95#include <dghnd.h> 96#include <dgcall.h> 97#include <dgslive.h> 98#include <dgxq.h> 99#include <dgrq.h> 100#include <dgpkt.h> 101#include <dgcct.h> 102#include <dgsct.h> 103#include <dgccallt.h> 104#include <dgfwd.h> 105 106#include <comprot.h> 107 108#include <comp.h> 109void rpc__dg_init_func(void) 110{ 111 static rpc_protocol_id_elt_t prot[1] = { 112 { 113 rpc__ncadg_init, /* Datagram-RPC */ 114 NULL, 115 RPC_C_PROTOCOL_ID_NCADG, 116 NULL, NULL, NULL, NULL 117 } 118 }; 119 rpc__register_protocol_id(prot, 1); 120} 121 122void rpc__ncadg_init 123( 124 rpc_prot_call_epv_t **call_epv, 125 rpc_prot_mgmt_epv_t **mgmt_epv, 126 rpc_prot_binding_epv_t **binding_epv, 127 rpc_prot_network_epv_t **network_epv, 128 rpc_prot_fork_handler_fn_t *fork_handler, 129 unsigned32 *st 130) 131{ 132 static rpc_prot_call_epv_t dg_call_epv = 133 { 134 .call_start = rpc__dg_call_start, 135 .call_transmit = rpc__dg_call_transmit, 136 .call_transceive = rpc__dg_call_transceive, 137 .call_receive = rpc__dg_call_receive, 138 .call_end = rpc__dg_call_end, 139 .call_block_until_free = rpc__dg_call_block_until_free, 140 .call_transmit_fault = rpc__dg_call_fault, 141 .call_cancel = rpc__dg_call_alert, 142 .call_receive_fault = rpc__dg_call_receive_fault, 143 .call_did_mgr_execute = rpc__dg_call_did_mgr_execute 144 }; 145 static rpc_prot_mgmt_epv_t dg_mgmt_epv = 146 { 147 .mgmt_inq_calls_sent = rpc__dg_mgmt_inq_calls_sent, 148 .mgmt_inq_calls_rcvd = rpc__dg_mgmt_inq_calls_rcvd, 149 .mgmt_inq_pkts_sent = rpc__dg_mgmt_inq_pkts_sent, 150 .mgmt_inq_pkts_rcvd = rpc__dg_mgmt_inq_pkts_rcvd 151 }; 152 static rpc_prot_binding_epv_t dg_binding_epv = 153 { 154 .binding_alloc = rpc__dg_binding_alloc, 155 .binding_init = rpc__dg_binding_init, 156 .binding_reset = rpc__dg_binding_reset, 157 .binding_changed = rpc__dg_binding_changed, 158 .binding_free = rpc__dg_binding_free, 159 .binding_inq_addr = rpc__dg_binding_inq_addr, 160 .binding_inq_client = rpc__dg_binding_inq_client, 161 .binding_copy = rpc__dg_binding_copy, 162 .binding_cross_fork = rpc__dg_binding_cross_fork 163 }; 164 static rpc_prot_network_epv_t dg_network_epv = 165 { 166 .network_use_socket = NULL, 167 .network_use_protseq = rpc__dg_network_use_protseq_sv, 168 .network_mon = rpc__dg_network_mon, 169 .network_stop_mon = rpc__dg_network_stop_mon, 170 .network_maint = rpc__dg_network_maint, 171 .network_stop_maint = rpc__dg_network_stop_maint, 172 .network_select_disp = rpc__dg_network_select_dispatch, 173 .network_inq_prot_vers =rpc__dg_network_inq_prot_vers, 174 .network_close = rpc__dg_network_close, 175 .network_getpeereid = NULL 176 }; 177 178 *call_epv = &dg_call_epv; 179 *mgmt_epv = &dg_mgmt_epv; 180 *binding_epv = &dg_binding_epv; 181 *network_epv = &dg_network_epv; 182#ifdef ATFORK_SUPPORTED 183 *fork_handler= rpc__ncadg_fork_handler; 184#else 185 *fork_handler= NULL; 186#endif 187 /* 188 * Establish a server boot time. 189 */ 190 191 if (rpc_g_dg_server_boot_time == 0) { 192 struct timeval tv; 193 194 gettimeofday(&tv, NULL); 195 rpc_g_dg_server_boot_time = (unsigned32) tv.tv_sec; 196 } 197 198 rpc__dg_pkt_pool_init(); 199 200 rpc__dg_network_init(); 201 202 rpc__dg_maintain_init(); 203 rpc__dg_monitor_init(); 204 205 rpc__dg_conv_init(); 206 rpc__dg_fwd_init(); 207 208 if (RPC_DBG(rpc_es_dbg_stats, 5)) 209 { 210 atexit(rpc__dg_stats_print); 211 } 212 213 *st = rpc_s_ok; 214} 215 216#ifdef ATFORK_SUPPORTED 217/* 218**++ 219** 220** ROUTINE NAME: rpc__ncadg_fork_handler 221** 222** SCOPE: PRIVATE - declared in comprot.h 223** 224** DESCRIPTION: 225** 226** This routine is called prior to, and immediately after, forking 227** the process's address space. The input argument specifies which 228** stage of the fork we're currently in. 229** 230** INPUTS: 231** 232** stage indicates the stage in the fork operation 233** (prefork | postfork_parent | postfork_child) 234** 235** INPUTS/OUTPUTS: none 236** 237** OUTPUTS: none 238** 239** IMPLICIT INPUTS: none 240** 241** IMPLICIT OUTPUTS: none 242** 243** FUNCTION VALUE: void 244** 245** SIDE EFFECTS: none 246** 247**-- 248**/ 249 250void rpc__ncadg_fork_handler 251( 252 rpc_fork_stage_id_t stage 253) 254{ 255 /* 256 * Pre-fork handlers are called in reverse order of rpc__ncadg_init(). 257 * Post-fork handlers are called in same order, except pkt_pool. 258 * 259 * First, call any module specific fork handlers. 260 * Next, handle any stage-specific operations for this 261 * module. 262 */ 263 switch ((int)stage) 264 { 265 case RPC_C_PREFORK: 266 rpc__dg_conv_fork_handler(stage); 267 rpc__dg_cct_fork_handler(stage); 268 rpc__dg_sct_fork_handler(stage); 269 rpc__dg_ccallt_fork_handler(stage); 270 rpc__dg_monitor_fork_handler(stage); 271 rpc__dg_maintain_fork_handler(stage); 272 rpc__dg_network_fork_handler(stage); 273 rpc__dg_pkt_pool_fork_handler(stage); 274 break; 275 case RPC_C_POSTFORK_CHILD: 276 /* 277 * Clear out statistics gathering structure 278 */ 279 /* b_z_e_r_o_((char *) &rpc_g_dg_stats, sizeof(rpc_dg_stats_t)); */ 280 281 memset( &rpc_g_dg_stats, 0, sizeof(rpc_dg_stats_t)); 282 /* 283 * Reset Server Boot Time. 284 */ 285 rpc_g_dg_server_boot_time = 0; 286 /* fall through */ 287 case RPC_C_POSTFORK_PARENT: 288 /* pkt_pool */ 289 rpc__dg_network_fork_handler(stage); 290 rpc__dg_maintain_fork_handler(stage); 291 rpc__dg_monitor_fork_handler(stage); 292 rpc__dg_ccallt_fork_handler(stage); 293 rpc__dg_sct_fork_handler(stage); 294 rpc__dg_cct_fork_handler(stage); 295 rpc__dg_conv_fork_handler(stage); 296 /* 297 * conv_fork_handler() must be called before 298 * pkt_pool_fork_handler(). 299 */ 300 rpc__dg_pkt_pool_fork_handler(stage); 301 break; 302 } 303} 304#endif /* ATFORK_SUPPORTED */ 305