/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* sun4v DR daemon
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <fcntl.h>
#include <errno.h>
#include <libgen.h>
#include <syslog.h>
#include <door.h>
#include <assert.h>
#include <sys/drctl_impl.h>
#include "drd.h"
static char *cmdname;
static int drctl_fd;
/*
* Currently, the only supported backend is for the Reconfiguration
* Coordination Manager (RCM). When there are other backends, this
* variable should be set dynamically.
*/
static void drd_daemonize(void);
int
{
int opt;
/*
* Process command line arguments
*/
opterr = 0; /* disable getopt error messages */
switch (opt) {
case 'd':
break;
case 's':
standalone = B_TRUE;
break;
default:
exit(1);
}
}
/* must be root */
if (geteuid() != 0) {
drd_err("permission denied: must run as root");
exit(1);
}
/* open the drctl device */
if (drd_init_drctl_dev(standalone) != 0) {
drd_err("unable to initialize drctl device");
exit(1);
}
/* daemonize */
if (!standalone) {
}
/* initialize door server */
if (drd_init_door_server(standalone) != 0) {
drd_err("unable to initialize door server");
exit(1);
}
/* initialize the backend */
if ((*drd_backend->init)() != 0) {
drd_err("unable to initialize backend processor");
exit(1);
}
/* loop forever */
for (;;) {
pause();
}
/*NOTREACHED*/
return (0);
}
static void
drd_daemonize(void)
{
exit(1);
}
if (pid != 0) {
/* parent */
exit(0);
}
/*
* Initialize child process
*/
(void) setsid();
(void) chdir("/");
(void) umask(0);
/*
* Initialize file descriptors. Do not touch stderr
* which is initialized by SMF to point to the drd
* specific log file.
*/
(void) close(STDIN_FILENO);
/* initialize logging */
}
static int
{
void (*drd_output)(char *, ...);
/* open the drctl device */
return ((standalone) ? 0 : -1);
}
return (0);
}
static int
{
int door_fd;
int dbg_fd;
/* create the door */
return (-1);
}
if (drctl_fd != -1) {
/* send the door descriptor to drctl */
(void) door_revoke(door_fd);
return (-1);
}
drd_dbg("connection to drctl established");
/* setup is complete in daemon mode */
if (!standalone) {
return (0);
}
}
/*
* At this point, the daemon is running in standalone
* mode for testing purposes. This allows the daemon
* to be controlled directly through a door exported
* to the filesystem. No drctl device is required in
* this mode.
*/
/* create the door file */
drd_err("failed to create door file '%s': %s",
(void) door_revoke(door_fd);
return (-1);
}
/* attach the door file to the door descriptor */
drd_err("failed to fattach door file '%s': %s",
(void) door_revoke(door_fd);
return (-1);
}
return (0);
}
static size_t
{
void *resizep;
char *str;
char *off;
int idx;
drd_dbg("drd_pack_response...");
/*
* Deallocate the global response buffer if it is
* in use. This assumes that there will only ever
* be one pending operation in the daemon. This is
* enforced by the kernel.
*/
/*
* Loop through all the resources and concatenate
* all the error strings to the end of the resource
* array. Also, update the offset field of each
* resource.
*/
/* skip if no error string */
continue;
/* increase the size of the buffer */
/* clean up any remaining strings */
}
return (0);
}
/* copy the error string into the response */
/*
* Now that the error string has been copied
* into the response message, the memory that
* was allocated for it is no longer needed.
*/
/* update size and offset */
}
return (osize);
}
/*ARGSUSED*/
static void
{
int nrsrc;
drd_dbg("drd_door_server...");
/* sanity check incoming arg */
/* pass off to backend for processing */
case DRCTL_CPU_CONFIG_REQUEST:
break;
case DRCTL_CPU_CONFIG_NOTIFY:
break;
break;
break;
case DRCTL_MEM_CONFIG_REQUEST:
break;
case DRCTL_MEM_CONFIG_NOTIFY:
break;
break;
break;
case DRCTL_IO_CONFIG_REQUEST:
break;
case DRCTL_IO_CONFIG_NOTIFY:
break;
break;
case DRCTL_IO_UNCONFIG_NOTIFY:
break;
default:
break;
}
if (osize == 0)
}