dlmgmt_main.c revision 0dc974a9a2e66d676505db23524ebff105fb36a9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* The dlmgmtd daemon is started by the datalink-management SMF service.
* This daemon is used to manage <link name, linkid> mapping and the
* persistent datalink configuration.
*
* Today, the <link name, linkid> mapping and the persistent configuration
* of datalinks is kept in /etc/dladm/datalink.conf, and the daemon keeps
* a copy of the datalinks in the memory (see dlmgmt_id_avl and
* dlmgmt_name_avl). The active <link name, linkid> mapping is kept in
* when dlmgmtd exits for some reason (e.g., when dlmgmtd is accidentally
* killed).
*/
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <priv_utils.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <stropts.h>
#include <strings.h>
#include <syslog.h>
#include <unistd.h>
#include <libdlmgmt.h>
#include "dlmgmt_impl.h"
const char *progname;
static int pfds[2];
static int dlmgmt_door_fd = -1;
static int dld_control_fd = -1;
static void dlmgmtd_exit(int);
static int dlmgmt_init();
static void dlmgmt_fini();
static int dlmgmt_init_privileges();
static void dlmgmt_fini_privileges();
static int
{
int err = 0;
return (err);
}
static int
{
int fd;
int err;
/*
* Create the door file for dlmgmtd.
*/
return (err);
}
return (err);
}
goto fail;
}
(void) fdetach(DLMGMT_DOOR);
goto fail;
}
return (0);
fail:
(void) door_revoke(dlmgmt_door_fd);
dlmgmt_door_fd = -1;
return (err);
}
static void
{
if (dlmgmt_door_fd == -1)
return;
}
(void) fdetach(DLMGMT_DOOR);
(void) dlmgmt_set_doorfd(B_FALSE);
}
static int
{
int err;
return (err);
}
if ((err = dlmgmt_linktable_init()) != 0)
return (err);
return (err);
}
static void
{
}
/*
* This is called by the child process to inform the parent process to
* exit with the given return value.
*/
static void
{
if (debug)
return;
}
}
/*ARGSUSED*/
static void
dlmgmtd_exit(int signo)
{
dlmgmt_fini();
}
static void
usage(void)
{
}
/*
* Set the uid of this daemon to the "dladm" user. Finish the following
* operations before setuid() because they need root privileges:
*
* - open the dld control node
*/
static int
{
/*
* Create the DLMGMT_TMPFS_DIR directory.
*/
return (errno);
} else {
return (ENOTDIR);
}
return (EPERM);
}
/*
* When dlmgmtd is started at boot, "ALL" privilege is required
* to open the dld control node.
*/
return (errno);
/*
* The PRIV_SYS_CONFIG privilege is needed to post sysevents.
*/
(void) close(dld_control_fd);
dld_control_fd = -1;
return (EPERM);
}
return (0);
}
static void
{
if (dld_control_fd != -1) {
(void) close(dld_control_fd);
dld_control_fd = -1;
}
}
/*
* Keep the pfds fd open, close other fds.
*/
/*ARGSUSED*/
static int
{
return (0);
}
static boolean_t
dlmgmt_daemonize(void)
{
int rv;
}
} else if (pid > 0) { /* Parent */
/*
* Read the child process's return value from the pfds.
* If the child process exits unexpected, read() returns -1.
*/
rv = EXIT_FAILURE;
}
}
/* Child */
(void) setsid();
/*
* Close all files except pfds[1].
*/
(void) chdir("/");
return (B_TRUE);
}
int
{
int opt;
progname++;
else
/*
* Process options.
*/
switch (opt) {
case 'd':
break;
default:
usage();
}
}
if (!debug && !dlmgmt_daemonize())
return (EXIT_FAILURE);
if ((errno = dlmgmt_init_privileges()) != 0) {
goto child_out;
}
if (dlmgmt_init() != 0) {
goto child_out;
}
/*
* Inform the parent process that it can successfully exit.
*/
for (;;)
(void) pause();
/* return from main() forcibly exits an MT process */
return (EXIT_FAILURE);
}