dlmgmt_main.c revision d62bc4badc1c1f1549c961cfb8b420e650e1272b
/*
* 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.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* 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
* dlmgmtd exits for some reason (e.g., when dlmgmtd is accidentally killed).
*/
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <priv.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 char dlmgmt_door_file[] = DLMGMT_DOOR;
static int dlmgmt_door_fd = -1;
static int
{
int fd;
int err = 0;
return (EINVAL);
return (err);
}
static int
{
int err;
return (err);
}
goto fail;
}
goto fail;
}
return (0);
fail:
if (dlmgmt_door_fd != -1) {
(void) door_revoke(dlmgmt_door_fd);
dlmgmt_door_fd = -1;
}
(void) fdetach(DLMGMT_DOOR);
return (err);
}
static void
{
(void) dlmgmt_set_doorfd(B_FALSE);
}
(void) fdetach(DLMGMT_DOOR);
}
static int
{
int 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)
{
}
static int
{
char *p;
priv_set = priv_allocset();
return (-1);
}
free(p);
return (-1);
}
return (-1);
}
return (-1);
}
return (0);
}
/*
* 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);
goto child_out;
}
if (dlmgmt_init() != 0)
goto child_out;
if (dlmgmt_setup_privs() != 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);
}