main.c revision 35ce885977e493804837f2752dc19461b7817446
1N/A * The contents of this file are subject to the terms of the 1N/A * Common Development and Distribution License (the "License"). 1N/A * You may not use this file except in compliance with the License. 1N/A * See the License for the specific language governing permissions 1N/A * and limitations under the License. 1N/A * When distributing Covered Code, include this CDDL HEADER in each 1N/A * If applicable, add the following below this CDDL HEADER, with the 1N/A * fields enclosed by brackets "[]" replaced with your own identifying 1N/A * information: Portions Copyright [yyyy] [name of copyright owner] 1N/A * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 1N/A * Use is subject to license terms. #
pragma ident "%Z%%M% %I% %E% SMI" * nwamd - NetWork Auto-Magic Daemon * This is the Network Auto-Magic daemon. For further high level information * see the Network Auto-Magic project and the Approachability communities * on opensolaris.org, and nwamd(1M). * The general structure of the code is as a set of threads collecting * system events which are fed into a state machine which alters system * state based on configuration. * Due to being threaded, a simple set of signal handlers would not work * very well for nwamd. Instead nwamd blocks signals at startup and * then starts a thread which sits in sigwait(2) waiting for signals. * When a signal is received the signal handling thread dispatches it. * - shutting down, done by creating an event which is passed through the * system allowing the various subsystems to do any necessary cleanup. * - SIGHUP for instance refresh, which tells us to look up various * properties from SMF(5). * nwamd starts several different subprocesses to manage the system. Some * of those start other processes (e.g. `ifconfig <if> dhcp` ends up starting * dhcpagent if necessary). Due to the way we manage signals if we started * those up without doing anything special their signal mask would mostly * block signals. So we restore the signal mask when we start subprocesses. * This is especially important with respect to DHCP as later when we exit * we need to kill the dhcpagent process which we started; for details, see * In this file there are several utility functions which might otherwise * belong in util.c, but since they are only called from main(), they can * live here as static functions: * - looking up SMF(5) properties * - managing privileges(5) * A little bit of magic here. By the first fork+setsid, we * disconnect from our current controlling terminal and become * a session group leader. By forking again without calling * setsid again, we make certain that we are not the session * group leader and can never reacquire a controlling terminal. * Look up nwamd property values and set daemon variables appropriately. * This function will be called on startup and via the signal handling * thread on receiving a HUP (which occurs when the nwam service is dprintf(
"Read daemon configuration properties.");
* We may have multiple interfaces with * scheduled timers; walk the list and * create a timer event for each one. * Refresh action - reread configuration properties. dprintf(
"could not allocate shutdown event");
/* if we're shutting down, exit this thread */ dprintf(
"started with privs %s", p !=
NULL ? p :
"Unknown");