4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * netcfgd - network configuration daemon. At present, this daemon implements
29 * the configuration backend for libnwam (via calls to nwam_backend_init()
30 * and nwam_backend_fini()). Initialization of the backend creates a door
31 * that libnwam calls use to read, update and destroy persistent configuration.
33 * More long-term, netcfgd will be used to manage other sources of configuration
34 * data and the backend functionality currently contained in libnwam will be
45 #include <sys/types.h>
49 #include <libnwam_priv.h>
52 static const char *progname
;
53 static boolean_t fg
= B_FALSE
;
56 * This function allows you to drop a dtrace probe here and trace
57 * complete strings (not just those containing formatting). It's
58 * important that we actually format the strings so we could trace them
59 * even if we choose not to log them.
62 log_out(int severity
, const char *str
)
65 (void) fprintf(stderr
, "%s: %s\n", progname
, str
);
67 syslog(severity
, str
);
73 nlog(int severity
, const char *fmt
, ...)
79 if (vasprintf(&vbuf
, fmt
, ap
) != -1) {
80 log_out(severity
, vbuf
);
90 openlog(progname
, LOG_PID
, LOG_DAEMON
);
92 nlog(LOG_DEBUG
, "%s started", progname
);
101 * A little bit of magic here. By the first fork+setsid, we
102 * disconnect from our current controlling terminal and become
103 * a session group leader. By forking again without calling
104 * setsid again, we make certain that we are not the session
105 * group leader and can never reacquire a controlling terminal.
107 if ((pid
= fork()) == -1) {
108 nlog(LOG_ERR
, "fork 1 failed");
113 nlog(LOG_DEBUG
, "child %ld exited, daemonizing", pid
);
116 if (setsid() == (pid_t
)-1) {
117 nlog(LOG_ERR
, "setsid");
120 if ((pid
= fork()) == -1) {
121 nlog(LOG_ERR
, "fork 2 failed");
133 graceful_shutdown(int signo
)
140 main(int argc
, char *argv
[])
145 if ((progname
= strrchr(argv
[0], '/')) == NULL
)
150 while ((c
= getopt(argc
, argv
, "f")) != -1) {
156 (void) fprintf(stderr
, "%s: unrecognized option %c\n",
166 (void) signal(SIGTERM
, graceful_shutdown
);
167 (void) signal(SIGQUIT
, graceful_shutdown
);
168 (void) signal(SIGPIPE
, SIG_IGN
);
169 (void) signal(SIGCHLD
, SIG_IGN
);
170 (void) atexit(nwam_backend_fini
);
172 if ((err
= nwam_backend_init()) != NWAM_SUCCESS
) {
174 "couldn't initialize libnwam backend: %s",
183 return (EXIT_SUCCESS
);