fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
3f1da666124ac25caadfacd3f2a361d4a41268a8wl * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iSNS Server administrative settings.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortepthread_mutex_t ctrl_node_mtx = PTHREAD_MUTEX_INITIALIZER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* semaphore for handling exit */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Globals for singal handling. time_to_exit is set by sig_handle()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * when set the main thread(daemon) and othere threads should exit.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * semaphone is used to make sure all threads that are created
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by isns_port_watcher and esi.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic pthread_mutex_t thr_count_mtx = PTHREAD_MUTEX_INITIALIZER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_RETRY_COUNT 10 /* for checking remaining threads before exit. */
3f1da666124ac25caadfacd3f2a361d4a41268a8wl * Door creation flag.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * global system message queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void sigalrm(int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sigusr2_handler -- SIGUSR2 Handler
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sigusr2 is exepected only when child is running okay.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* post okay status. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "SIGUSR@ is received. Parent is existing...");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sigchld_handler -- SIGCHLD Handler
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sigchld is exepected only when there is an error.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This is the default code. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret_pid = waitpid(isns_child_pid, &status, WNOHANG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "SIGHUP is received. Reloading config...");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) queue_msg_set(sys_q, CONFIG_RELOAD, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Signal: %d received and sending server exit.", sig);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "increase thread reference count(%d).", thr_ref_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "decrease thread reference count(%d).", thr_ref_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "shutdown", "raise exit flag.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED E_FUNC_ARG_UNUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED E_FUNC_ARG_UNUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set locale */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte openlog(ISNS_DAEMON_SYSLOG_PP, LOG_PID | LOG_CONS, LOG_DAEMON);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* load administative settings. pick up data location. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_ERR, "main", "administrative settings load error.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* A signal handler is set for SIGCHLD. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "main", "now forking... pid %d", getpid());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* daemonlize */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cannot fork(), terminate the server.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * terminate parent.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * redirect stdout, and stderr to /dev/null.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* end of daemonlize */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize object hash table */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cache_init() != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "object hash table initialization error.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize event list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "ESI event list initialization error.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize iSNS database */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (init_data() != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "internal database initialization error");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (load_data() != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_ERR, "main", "loading data store failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t, c / (double)CLOCKS_PER_SEC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create a message queue for system control */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create a message queue for scn thread */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create scn thread */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check for Default DD/DD-set existence and */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create them if they are not there. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (verify_ddd() != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup and verify the portal(s) for scn(s) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* after scn registry is loaded from data store. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup and verify the portal(s) for esi(s) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* after esi list is loaded from data store. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create scn thread */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pthread_create(&scn_tid, NULL, scn_proc, NULL) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_ERR, "main", "SCN thread creating error.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup a door for management interface */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create server port watcher */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_ERR, "main", "iSNS port thread creating error.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create entity status inquiry thread */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_ERR, "main", "ESI thread creating error.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "main", "issuing SIGUSR2.. parent pid %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* registration expiring */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* graceful exit. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "wake up ESI and stop it.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "sending SCN stop msg.");
3f1da666124ac25caadfacd3f2a361d4a41268a8wl "closing the door.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* now check any remaining threads. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "main thread %d is done.",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "main thread %d existing ...",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* load config again. don't pick data store. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED E_STMT_NOT_REACHED */