ndmpd_main.c revision 1e05b03fa76ee89d509f0c461b36cb865f1e6794
/*
*/
/*
* BSD 3 Clause License
*
* Copyright (c) 2007, The Storage Networking Industry Association.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* - Neither the name of The Storage Networking Industry Association (SNIA)
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */
#include <errno.h>
#include <signal.h>
#include <libgen.h>
#include <libscf.h>
#include <libintl.h>
#include <zone.h>
#include <dlfcn.h>
#include "ndmpd.h"
#include "ndmpd_common.h"
/* zfs library handle & mutex */
void *mod_plp;
static void ndmpd_sig_handler(int sig);
typedef struct ndmpd {
int s_shutdown_flag; /* Fields for shutdown control */
int s_sigval;
} ndmpd_t;
/*
* Load and initialize the plug-in module
*/
static int
mod_init()
{
char *plname;
ndmp_plugin_t *(*plugin_init)(int);
return (0);
return (0);
}
if (plugin_init == NULL) {
return (0);
}
return (-1);
}
return (0);
}
/*
* Unload
*/
static void
mod_fini()
{
return;
void (*plugin_fini)(ndmp_plugin_t *);
if (plugin_fini == NULL) {
return;
}
}
static void
daemonize_init(char *arg)
{
/*
* Set effective sets privileges to 'least' required. If fails, send
* error messages to log file and proceed.
*/
}
"the service.");
}
/*
* Block all signals prior to the fork and leave them blocked in the
* parent so we don't get in a situation where the parent gets SIGINT
* and returns non-zero exit status and the child is actually running.
* In the child, restore the signal mask once we've done our setsid().
*/
(void) sigfillset(&set);
}
/* If we're the parent process, exit. */
if (pid != 0) {
_exit(0);
}
(void) setsid();
(void) chdir("/");
(void) umask(0);
}
static void
daemonize_fini(void)
{
int fd;
}
}
/*
* main
*
* The main NDMP daemon function
*
* Parameters:
* argc (input) - the argument count
* argv (input) - command line options
*
* Returns:
* 0
*/
int
{
char c;
void *arg = 0;
/*
* Check for existing ndmpd door server (make sure ndmpd is not already
* running)
*/
if (ndmp_door_check()) {
/* ndmpd is already running, exit. */
return (0);
}
/* load ENVs */
if (ndmpd_load_prop()) {
"%s SMF properties initialization failed.", argv[0]);
}
/* Global zone check */
if (getzoneid() != GLOBAL_ZONEID) {
}
/* Trusted Solaris check */
if (is_system_labeled()) {
}
opterr = 0;
switch (c) {
case 'd':
(void) set_debug_level(TRUE);
break;
default:
}
}
closelog();
/*
* close any open file descriptors which are greater
* than STDERR_FILENO
*/
/* set up signal handler */
(void) sigfillset(&set);
(void) daemonize_init(argv[0]);
if (mod_init() != 0) {
}
/* libzfs init */
}
/* initialize and start the door server */
if (ndmp_door_init()) {
}
if (tlm_init() == -1) {
}
/*
* Prior to this point, we are single-threaded. We will be
* multi-threaded from this point on.
*/
(void *)&arg);
while (!ndmpd.s_shutdown_flag) {
(void) sigsuspend(&set);
case 0:
break;
case SIGPIPE:
break;
case SIGHUP:
/* Refresh SMF properties */
if (ndmpd_load_prop())
"Service properties initialization "
"failed.");
break;
default:
/*
* Typically SIGINT or SIGTERM.
*/
break;
}
}
(void) mutex_destroy(&ndmpd_zfs_fd_lock);
(void) mutex_destroy(&log_lock);
mod_fini();
return (SMF_EXIT_OK);
}
static void
ndmpd_sig_handler(int sig)
{
}
/*
* Enable libumem debugging by default on DEBUG builds.
*/
#ifdef DEBUG
const char *
_umem_debug_init(void)
{
return ("default,verbose"); /* $UMEM_DEBUG setting */
}
const char *
_umem_logging_init(void)
{
return ("fail,contents"); /* $UMEM_LOGGING setting */
}
#endif