fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
3f1da666124ac25caadfacd3f2a361d4a41268a8wl * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <pthread.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <libscf.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <time.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <signal.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <semaphore.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/wait.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_server.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_dseng.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_msgq.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_log.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_cfg.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_utils.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_cache.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_obj.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_dd.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_scn.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_sched.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_esi.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_mgmt.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iSNS Server administrative settings.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint8_t daemonlize = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint dbg_level = 7;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint64_t esi_threshold;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint8_t mgmt_scn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortectrl_node_t *control_nodes = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortepthread_mutex_t ctrl_node_mtx = PTHREAD_MUTEX_INITIALIZER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar data_store[MAXPATHLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* semaphore for handling exit */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic sem_t isns_child_sem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int isns_child_smf_exit_code;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic pid_t isns_child_pid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if !defined(SMF_EXIT_ERR_OTHER)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SMF_EXIT_ERR_OTHER -1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * semaphone is used to make sure all threads that are created
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by isns_port_watcher and esi.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteboolean_t time_to_exit = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint32_t thr_ref_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic pthread_mutex_t thr_count_mtx = PTHREAD_MUTEX_INITIALIZER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_RETRY_COUNT 10 /* for checking remaining threads before exit. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3f1da666124ac25caadfacd3f2a361d4a41268a8wl/*
3f1da666124ac25caadfacd3f2a361d4a41268a8wl * Door creation flag.
3f1da666124ac25caadfacd3f2a361d4a41268a8wl */
3f1da666124ac25caadfacd3f2a361d4a41268a8wlboolean_t door_created = B_FALSE;
3f1da666124ac25caadfacd3f2a361d4a41268a8wl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * global system message queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemsg_queue_t *sys_q = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemsg_queue_t *scn_q = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void *cli_test(void *argv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern dump_db(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void sigalrm(int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sigusr2_handler -- SIGUSR2 Handler
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sigusr2 is exepected only when child is running okay.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesigusr2_handler(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sig
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* post okay status. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "sigusr2_handler",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "SIGUSR@ is received. Parent is existing...");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_child_smf_exit_code = SMF_EXIT_OK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sem_post(&isns_child_sem);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sigchld_handler -- SIGCHLD Handler
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sigchld is exepected only when there is an error.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesigchld_handler(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sig
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pid_t ret_pid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This is the default code. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_child_smf_exit_code = SMF_EXIT_ERR_OTHER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret_pid = waitpid(isns_child_pid, &status, WNOHANG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret_pid == isns_child_pid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (WIFEXITED(status)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_child_smf_exit_code = WEXITSTATUS(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sem_post(&isns_child_sem);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesighup_handler(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sig
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "sighup_handle",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "SIGHUP is received. Reloading config...");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) queue_msg_set(sys_q, CONFIG_RELOAD, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesigexit_handler(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sig
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "sigexit_handler",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Signal: %d received and sending server exit.", sig);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte shutdown_server();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteinc_thr_count(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) pthread_mutex_lock(&thr_count_mtx);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "inc_thr_count",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "increase thread reference count(%d).", thr_ref_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte thr_ref_count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) pthread_mutex_unlock(&thr_count_mtx);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedec_thr_count(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) pthread_mutex_lock(&thr_count_mtx);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "dec_thr_count",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "decrease thread reference count(%d).", thr_ref_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte thr_ref_count--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) pthread_mutex_unlock(&thr_count_mtx);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint32_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_thr_count(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t ref;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) pthread_mutex_lock(&thr_count_mtx);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ref = thr_ref_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) pthread_mutex_unlock(&thr_count_mtx);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "get_thr_count",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "checking thread reference count %d.", ref);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ref);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteshutdown_server(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "shutdown", "raise exit flag.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte time_to_exit = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) queue_msg_set(sys_q, SERVER_EXIT, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemain(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED E_FUNC_ARG_UNUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int argc,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED E_FUNC_ARG_UNUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *argv[]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int opt_i = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pthread_t port_tid, esi_tid, scn_tid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t thr_cnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte time_t t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clock_t c;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (getopt(argc, argv, "i") == 'i') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte opt_i = 1; /* interactive mode */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set locale */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte openlog(ISNS_DAEMON_SYSLOG_PP, LOG_PID | LOG_CONS, LOG_DAEMON);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* load administative settings. pick up data location. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (load_config(B_TRUE) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_ERR, "main", "administrative settings load error.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(SMF_EXIT_ERR_OTHER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* A signal handler is set for SIGCHLD. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) signal(SIGCHLD, sigchld_handler);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) signal(SIGUSR2, sigusr2_handler);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sigset(SIGALRM, sigalrm);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printf("start daemon\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (opt_i == 0 || daemonlize) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "main", "now forking... pid %d", getpid());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte daemonlize = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* daemonlize */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_child_pid = fork();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_child_pid < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cannot fork(), terminate the server.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(SMF_EXIT_ERR_CONFIG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_child_pid > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * terminate parent.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sem_wait(&isns_child_sem);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sem_destroy(&isns_child_sem);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "main", "exiting with %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_child_smf_exit_code);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(isns_child_smf_exit_code);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * redirect stdout, and stderr to /dev/null.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i = open("/dev/null", O_RDWR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) dup2(i, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) dup2(i, 2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* end of daemonlize */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printf("calling cache init\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize object hash table */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cache_init() != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_ERR, "main",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "object hash table initialization error.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(SMF_EXIT_ERR_OTHER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize event list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (el_init(10, 60, 6) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_ERR, "main",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "ESI event list initialization error.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(SMF_EXIT_ERR_OTHER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize iSNS database */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (init_data() != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_ERR, "main",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "internal database initialization error");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(SMF_EXIT_ERR_OTHER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printf("calling load_data\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t = time(NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = clock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (load_data() != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_ERR, "main", "loading data store failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(SMF_EXIT_ERR_OTHER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t = time(NULL) - t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = clock() - c;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printf("time %d clock %.4lf -loading data\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t, c / (double)CLOCKS_PER_SEC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printf("sys queue creating...\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create a message queue for system control */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sys_q = queue_calloc();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!sys_q) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(SMF_EXIT_ERR_OTHER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create a message queue for scn thread */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scn_q = queue_calloc();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!scn_q) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(SMF_EXIT_ERR_OTHER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
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 exit(SMF_EXIT_ERR_OTHER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup and verify the portal(s) for scn(s) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* after scn registry is loaded from data store. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (verify_scn_portal() != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(SMF_EXIT_ERR_OTHER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup and verify the portal(s) for esi(s) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* after esi list is loaded from data store. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (verify_esi_portal() != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(SMF_EXIT_ERR_OTHER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printf("scn queue creating...\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sigset(SIGHUP, sighup_handler);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sigset(SIGINT, sigexit_handler);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sigset(SIGTERM, sigexit_handler);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sigset(SIGQUIT, sigexit_handler);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
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 exit(SMF_EXIT_ERR_OTHER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup a door for management interface */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (setup_mgmt_door(sys_q) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(SMF_EXIT_ERR_OTHER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create server port watcher */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pthread_create(&port_tid, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_port_watcher, (void *)sys_q) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_ERR, "main", "iSNS port thread creating error.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(SMF_EXIT_ERR_OTHER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create entity status inquiry thread */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pthread_create(&esi_tid, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte esi_proc, NULL) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_ERR, "main", "ESI thread creating error.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(SMF_EXIT_ERR_OTHER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!daemonlize) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) pthread_create(&tid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cli_test,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)sys_q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (opt_i == 0 || daemonlize) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "main", "issuing SIGUSR2.. parent pid %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte getppid());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) kill(getppid(), SIGUSR2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* pause */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (;;) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg_text_t *msg = queue_msg_get(sys_q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (msg->id) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case DATA_ADD:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case DATA_UPDATE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case DATA_DELETE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case DATA_DELETE_ASSOC:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case DATA_COMMIT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case DATA_RETREAT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case REG_EXP:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* registration expiring */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_expiring(msg->data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case DEAD_PORTAL:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portal_dies((uint32_t)msg->data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case SERVER_EXIT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* graceful exit. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) queue_msg_free(msg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "main",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "wake up ESI and stop it.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) get_stopwatch(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "main",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "sending SCN stop msg.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) queue_msg_set(scn_q, SCN_STOP, NULL);
3f1da666124ac25caadfacd3f2a361d4a41268a8wl if (door_created) {
3f1da666124ac25caadfacd3f2a361d4a41268a8wl isnslog(LOG_DEBUG, "main",
3f1da666124ac25caadfacd3f2a361d4a41268a8wl "closing the door.");
3f1da666124ac25caadfacd3f2a361d4a41268a8wl (void) fdetach(ISNS_DOOR_NAME);
3f1da666124ac25caadfacd3f2a361d4a41268a8wl }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) pthread_join(esi_tid, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "main",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "esi thread %d exited.", esi_tid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) pthread_join(port_tid, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "main",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "port watcher thread %d exited.", port_tid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) pthread_join(scn_tid, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "main",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "scn thread %d exited.", scn_tid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* now check any remaining threads. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte thr_cnt = get_thr_count();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (thr_cnt == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "main",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "main thread %d is done.",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pthread_self());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (MAX_RETRY_COUNT > i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "main",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "main thread %d existing ...",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pthread_self());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case CONFIG_RELOAD:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* load config again. don't pick data store. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) load_config(B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case SYS_QUIT_OK:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) queue_msg_free(msg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) queue_msg_free(msg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED E_STMT_NOT_REACHED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}