/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* system status daemon
* setuid to the owner of CS_STAT_DIR
* setgid to kmem for better performance
*/
#include <ast.h>
#include <cs.h>
#include <ctype.h>
#include <error.h>
#include <proc.h>
#include <sig.h>
#include <times.h>
#include <dirent.h>
#include <ast_param.h>
/*
* define enough of rwhod info to get by
*/
struct whod
{
};
#ifndef S_IXUSR
#endif
#ifndef S_IXGRP
#endif
#ifndef S_IXOTH
#endif
#include <nlist.h>
#endif
#if _sys_dk
#endif
#endif
#ifndef CPUSTATES
#endif
#ifndef CP_USER
#define CP_USER 0
#endif
#ifndef CP_NICE
#endif
#ifndef CP_SYS
#endif
#if _hdr_utmpx
#include <utmpx.h>
#if !defined(UTMP_FILE) && defined(UTMPX_FILE)
#endif
#if !defined(UTMP_PATH) && defined(UTMPX_PATH)
#endif
#if !defined(UTMP_PATHNAME) && defined(UTMPX_PATHNAME)
#endif
#if !defined(_PATH_UTMP) && defined(_PATH_UTMPX)
#endif
#else
#include <utmp.h>
#endif
static char* usrfiles[] =
{
#ifdef UTMP_FILE
#endif
#ifdef UTMP_FILENAME
#endif
#ifdef UTMP_PATH
#endif
#ifdef UTMP_PATHNAME
#endif
#ifdef _PATH_UTMP
#endif
#if _hdr_utmpx
#endif
};
static char* usrfile;
static char* devfiles[] =
{
};
#ifdef FSCALE
static unsigned long avenrun;
#else
static double avenrun;
#endif
static unsigned long boottime;
#ifdef CP_TIME
static int maxcpu;
#endif
#if NAMELIST
struct symbol
{
char* name;
char* addr;
int size;
int once;
};
/*
* and here we have the status symbols
*/
{
#ifdef CP_TIME
#else
#endif
};
#endif
static char* whofile;
static void
{
if (remote)
{
}
}
/*
* update data status checking for competing daemon
* exit on error or other daemon
*/
static void
{
unsigned long tm;
static unsigned long idle;
static unsigned long next;
static unsigned long down;
{
}
if (now)
{
{
now = 0;
}
}
if (delay)
{
}
}
int
{
register int n;
register int i;
register long v;
char* s;
char* e;
char* data;
int uf;
int wf;
int idlecmd;
int usercount;
unsigned long t;
unsigned long toss;
unsigned long usertime;
unsigned long now;
unsigned long then;
#if NAMELIST
int kf;
#endif
{
/*
* start remote status daemon
*/
exit(0);
{
}
/*
* loop until remote status daemon starts
* check for competing startup daemon
*/
if (csdaemon(0))
exit(1);
av[0] = CS_REMOTE_SHELL;
av[3] = 0;
for (;;)
{
break;
remote = 0;
}
}
for (i = 0; i < elementsof(usrfiles); i++)
if (uf < 0)
/*
* final initialization
*/
close(2);
dup(n);
close(n);
av[0] = "uptime";
av[1] = 0;
for (s = data; *s; s++)
usertime = 0;
#if NAMELIST
for (n = 0; n < elementsof(symbols); n++)
{
if (chdir("/"))
s = 0;
for (i = 0; i < elementsof(sysfiles); i++)
{
s = sysfiles[i];
break;
}
if (!s)
{
{
if ((i = strlen(entry->d_name) - 2) > 0 && entry->d_name[i] == 'i' && entry->d_name[i + 1] == 'x' && !stat(entry->d_name, &st) && (st.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)))
{
break;
}
}
}
for (n = 0; n < elementsof(symbols); n++)
{
kf = -1;
}
}
if (kf < 0)
#endif
{
{
{
wf = -1;
}
}
}
else
{
idlecmd = 1;
iv[2] = 0;
}
/*
* the daemon loop
*/
for (;;)
{
/*
* update logged in user stats
*/
{
}
/*
* count the interesting users
* find the min user idle time
*/
if (idlecmd)
{
/*
* check idle command
*/
idlecmd = 0;
else
{
idlecmd = 1;
idlecmd = 0;
else
{
if (n > 0)
n--;
buf[n] = 0;
{
}
else idlecmd = -1;
}
}
}
if (idlecmd <= 0)
for (i = 0; i < usercount; i++)
{
else
{
if (v < CS_STAT_IGNORE)
}
}
{
/*
* check devices for min idle time
*/
for (i = 0; i < elementsof(devfiles); i++)
if (devfiles[i])
{
else
{
}
}
}
/*
* get the hard stuff
*/
#if NAMELIST
if (kf >= 0)
{
/*
* update memfile symbol values
*/
for (n = 0; n < elementsof(symbols); n++)
{
}
#ifdef CP_TIME
for (i = 0; i < CPUSTATES; i++)
cp_time[i] = 0;
for (n = 0; n <= maxcpu; n++)
if (CPUFOUND(n))
for (i = 0; i < CPUSTATES; i++)
#endif
}
else
#endif
if (wf >= 0)
{
for (i = 0; i < elementsof(cp_time); i++)
cp_time[i] = 100;
}
else
{
/*
* defer to process with memfile access
*/
buf[n] = 0;
n = 0;
{
s = e;
while (isspace(*s)) s++;
if (*s == 'd')
{
n *= 24;
while (*s && !isdigit(*s)) s++;
s = e;
}
}
for (i = 0; i < elementsof(cp_time); i++)
cp_time[i] = 0;
}
/*
* finalize the new stat info
*/
t = 0;
for (i = 0; i < elementsof(cp_time); i++)
{
t += cp_diff[i];
}
if (!t) t = 1;
}
}