/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include "ttymon.h"
#include "tmextern.h"
#include "sac.h"
/*
* openpid - open the pid and put ttymon's pid in it
* - put an advisory lock on the file
* - to prevent another instance of ttymon in same directory
* - SAC also makes use of the lock
* - fd 0 is reserved for pid file
*/
void
openpid()
{
extern int Lckfd;
(void)close(0);
/* open for read first, otherwise, may delete the pid already there*/
fatal("pid file is locked. ttymon may already be "
"running!");
}
#ifdef DEBUG
#endif
}
/*
* openpipes() -- open pmpipe and sacpipe to communicate with SAC
* -- Pfd, Sfd are global file descriptors for pmpipe, sacpipe
*/
void
{
if (Sfd < 0)
if (Pfd < 0)
#ifdef DEBUG
#endif
}
/*
* remove_env(env) - remove an environment variable from the environment
*/
static void
char *env;
{
extern char **environ;
char **p;
p = environ;
if (p == NULL)
return;
while (*p) {
rp = p;
p++;
}
if (rp) {
*rp = *--p;
*p = NULL;
}
}
/*
* get_environ() -- get env variables PMTAG, ISTATE
* -- set global variables Tag, State
*/
void
{
fatal("PMTAG is missing");
fatal("ISTATE is missing");
/*
* remove the environment variables so they will not
* be passed to the children
*/
remove_env("ISTATE");
remove_env("PMTAG");
}
/*
* sacpoll - the event handler when sac event is posted
*/
void
sacpoll()
{
int ret;
char oldState;
#ifdef DEBUG
debug("in sacpoll");
#endif
/* we don't want to be interrupted by sigchild now */
/*
* read sac messages, one at a time until no message
* is left on the pipe.
* the pipe is open with O_NONBLOCK, read will return -1
* and errno = EAGAIN if nothing is on the pipe
*/
for (;;) {
if (ret < 0) {
switch(errno) {
case EAGAIN:
/* no more data on the pipe */
return;
case EINTR:
break;
default:
fatal("pmpipe read failed: %s",
break; /*NOTREACHED*/
}
}
else if (ret == 0) {
/* no more data on the pipe */
return;
}
else {
case SC_STATUS:
break;
case SC_ENABLE:
log("Got SC_ENABLE message");
State = PM_ENABLED;
#ifdef DEBUG
debug("state changed to ENABLED");
#endif
state_change();
}
break;
case SC_DISABLE:
log("Got SC_DISABLE message");
State = PM_DISABLED;
#ifdef DEBUG
debug("state changed to DISABLED");
#endif
state_change();
}
break;
case SC_READDB:
log("Got SC_READDB message");
Reread_flag = 1;
break;
default:
break;
} /* end switch */
continue;
log("sanity response to SAC failed: %s",
break;
}
}
} /* end for loop */
}