fmd_main.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
0N/A * The contents of this file are subject to the terms of the 0N/A * Common Development and Distribution License, Version 1.0 only 0N/A * (the "License"). You may not use this file except in compliance 0N/A * See the License for the specific language governing permissions 0N/A * and limitations under the License. 0N/A * When distributing Covered Code, include this CDDL HEADER in each 0N/A * If applicable, add the following below this CDDL HEADER, with the 0N/A * fields enclosed by brackets "[]" replaced with your own identifying 0N/A * information: Portions Copyright [yyyy] [name of copyright owner] 0N/A * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 0N/A * Use is subject to license terms. 0N/A#
pragma ident "%Z%%M% %I% %E% SMI" 0N/A * For DEBUG builds, we define a set of hooks for libumem that provide useful 0N/A * default settings for the allocator's debugging facilities. 1400N/A return (
"default,verbose");
/* $UMEM_DEBUG setting */ 0N/A return (
"fail,contents");
/* $UMEM_LOGGING setting */ 0N/A * We use a two-phase algorithm for becoming a daemon because we want the 0N/A * daemon process (the child) to do the work of becoming MT-hot and opening our 0N/A * event transport. Since these operations can fail and need to result in the 0N/A * daemon failing to start, the parent must wait until fmd_run() completes to 0N/A * know whether it can return zero or non-zero status to the invoking command. 0N/A * The parent waits on a pipe inside this function to read the exit status. 0N/A * The child gets the write-end of the pipe returned by daemonize_init() and 0N/A * then fmd_run() uses the pipe to set the exit status and detach the parent. 0N/A * Set our per-process core file path to leave core files in our 0N/A * var/fm/fmd directory, named after the PID to aid in debugging, 0N/A * and make sure that there is no restriction on core file size. 0N/A * Reset all of our privilege sets to the minimum set of required 0N/A * privileges. We continue to run as root so that files we create 0N/A * such as logs and checkpoints are secured in the /var filesystem. 0N/A 0, 0,
/* run as uid 0 and gid 0 */ 0N/A * Block all signals prior to the fork and leave them blocked in the 0N/A * parent so we don't get in a situation where the parent gets SIGINT 0N/A * and returns non-zero exit status and the child is actually running. 0N/A * In the child, restore the signal mask once we've done our setsid(). 0N/A * If we're the parent process, wait for either the child to send us 0N/A * the appropriate exit status over the pipe or for the read to fail 0N/A * (presumably with 0 for EOF if our child terminated abnormally). 0N/A * If the read fails, exit with either the child's exit status if it 0N/A * exited or with FMD_EXIT_ERROR if it died from a fatal signal. 0N/A "Usage: %s [-V] [-f file] [-o opt=val] [-R dir]\n",
arg0);
0N/A * Parse the command-line once to validate all options and retrieve 0N/A * any overrides for our configuration file and root directory. 0N/A break;
/* handle -o below */ 0N/A * Now that we've initialized our global state, parse the command-line 0N/A * again for any configuration options specified using -o and set them. 0N/A "option -o %s: option requires value\n",
0N/A *p++ =
'\0';
/* strike out the delimiter */ 0N/A if (p[0] ==
'"' && p[
strlen(p) -
1] ==
'"') {
0N/A "%s: failed to set option -o %s: %s\n",
* Update the value of fmd.d_fg based on "fg" in case it changed. We * use this property to decide whether to daemonize below. * Once we're done setting our global state up, set up signal handlers * for ensuring orderly termination on SIGTERM. If we are starting in * the foreground, we also use the same handler for SIGINT and SIGHUP. * Prior to this point, we are single-threaded. Once fmd_run() is * called, we will be multi-threaded from this point on. The daemon's * main thread will wait at the end of this function for signals.