DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T o

⟦4e34574e4⟧ TextFile

    Length: 15520 (0x3ca0)
    Types: TextFile
    Names: »osimon.c«

Derivation

└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦e83f91978⟧ »EurOpenD22/isode/osimis-2.0.tar.Z« 
        └─⟦d846658bd⟧ 
            └─⟦this⟧ »osimis/smap/osimon.c« 

TextFile

/*
 * Copyright (c) 1988 University College London
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * by the Department of Computer Science, University College London.
 * The name of the University may not be used to
 * endorse or promote products derived from this software without
 * specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

/* osimon main program */

/*
 * By George Pavlou, October 1988
 */

#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include "isode/psap.h"
#include "isode/rosap.h"
#include "msap.h"
#include "disp.h"
#include "recs.h"
#include "objectS.h"
#include "report.h"
#include "config.h"
#include "defs.h"


/* DATA */

char *progname = "osimon";


static char *tent_hdr1a [] =
{
	"Conns",
	"TPDUs",
	"ConnReqs",
	"CrErrs",
	"Prot",
	"Csum"
};


static char *tent_hdr1b [] =
{
	"host",
	"boot time",
	"actv prev",
	"sent recv retr",
	"succ unsc",
	"cgst cfig",
	"errs",
	"errs"
};


static char *einv_hdr1a [] =
{
	"Process",
	"Conns",
	"CrSucsful",
	"CrUnscful",
	"CrErrs",
	"Prot",
	"Cksum"
};


static char *einv_hdr1b [] =
{
	"id",
	"since",
	"active",
	"in  out",
	"in  out",
	"cgst cfig",
	"errs",
	"errs"
};


static char *cept_hdr1a [] =
{
	"CeptId",
	"TPDUs",
	"Bytes"
};


static char *cept_hdr1b [] =
{
	"pid  fd",
	"since",
	"remote host",
	"sent recv retr",
	"sent recv retr",
	"tprot"
};


static char  *ttltxt[] =
{
	"Management information for Transport layer activity at host ",
	"Management information for Transport layer activity on all hosts"
};


static char  *msgs[] =
{
	"no entity invocations",
	"no connection endpoints",
	"no connection",
	"broken connection, SMA down?"
};




/* Global Variables */


int  terminate(), setpoll(), setwinchange();            /* signal handlers */
int  idcmp(), timecmp();


ManagedSystemS  *parseManagedSystem();
T_LayerEntityS  *parseTLayerEntity();
T_EntityInvocationS  *parseTEntityInvocation();
T_ConnectionEndpointS  *parseTConnectionEndpoint();
MO_ID  *objid2inst();
FREC  *wfrec();


extern int  errno;
extern int  winchange, poll;


static char  ttlfmt   [140];    /* format for printing title */
static char  hdr1afmt [140];    /* format for printing hdr 1a */
static char  hdr1bfmt [140];    /* format for printing hdr 1b */
static char  hdr2afmt [140];    /* format for printing hdr 2a */
static char  hdr2bfmt [140];    /* format for printing hdr 2b */

static char  title [LNLEN];     /* title buffer */


static DISFL disfl[] =
{
	{NULLIFP,    NULLIFP,    NULLIFP, idcmp,  einv_hdr1a, einv_hdr1b,
	 cept_hdr1a, cept_hdr1b, NULLCP,  NULLCP, msgs,       title},

	{NULLIFP,    NULLIFP,    NULLIFP, idcmp,  tent_hdr1a, tent_hdr1b,
	 NULLVP,     NULLVP,     NULLCP,  NULLCP, msgs,       title}
};

DISFL  *dfp;


int  msd[MAXHOSTS];		/* management connection fds */
int  disptype;

int  mask, nfds;

char host[HOSTLEN+1];		/* local host name */

char *hosts[MAXHOSTS];		/* hosts where SMAs run */
int   NofHosts;			/* how many */



/* MAIN */

main (argc, argv)
int  argc;
char **argv;
{
    isodesetailor("./smaptailor");

    if (getconfig(hosts, &NofHosts) == NOTOK)
	advise(NULLCP, "Warning: failed to read configuration file");

    if ((disptype = parse_args(argc, argv)) == NOTOK)
	error(NULLCP, "host %s not supported", host);

    dfp = (disptype == HOST ? &disfl[HOST] : &disfl[ALL]);

    getfmt(disptype);                   /* get title and header formats */
    mktitle(disptype);                  /* make title */

    if (disptype == HOST)               /* get management information */
	initialise_host(host, msd);
    else        /* ALL */
	initialise_all(hosts, msd);

    display(disptype, msd);             /* maintain the real-time display */

    terminate(OK);			/* NOTREACHED */

}

static  terminate (sig)
int  sig;
{
    if (sig != NOTOK) {
	unset_reports(msd, disptype);
	close_connections(msd, NofHosts);
    }

    clrup();
    exit(sig);
}


static  unset_reports (msd, disptype)
int  msd[], disptype;
{
    int  i;

    if (disptype == HOST) {
	ReportSetRequest(TEINV_REP, m_removeValue, msd[0]);
	ReportSetRequest(TCEPT_REP, m_removeValue, msd[0]);
    }
    else
	for (i = 0; i < NofHosts; i++)
	    if (msd[i] > 0)
		ReportSetRequest(TENT_REP, m_removeValue, msd[i]);
}


static int  display (disptype, msd)
int  disptype, msd[];
{
    struct MSAPindication  mis;
    int  ifds, fds;
    char c;

    signal (SIGHUP,  terminate);
    signal (SIGINT,  terminate);
    signal (SIGQUIT, terminate);
    signal (SIGTERM, terminate);
    signal (SIGALRM, setpoll);

    if (disptype == ALL)
	alarm(WAIT);

#ifdef SUNWIN
    signal (SIGWINCH, setwinchange);
    setupwindow();
#endif

    startdisplay(dfp, GAP);     /* do first page */

    mask |= 1;
    if (!nfds)
	nfds = 1;

    /* check stdin and management connection(s) */

    for (EVER) {
	if (poll)
	    do_poll(msd);
#ifdef SUNWIN
	if (winchange) {
	    winchange = NO;
	    getwinsize();
	    winredraw();                /* redraw screen */
	}
#endif
	ifds = mask;
	switch (fds = xselect(nfds, &ifds, NULLIP, NULLIP, 1)) {
	    case OK:
		continue;

	    case NOTOK:
		if (errno != EINTR) {
		    advise(NULLCP, "xselect failed");
		    terminate(NOTOK);
		}
		continue;               /* select interrupted by signal */

	    default:
		break;
	}

	if (ifds & 1) {
	    switch (c = (char) checkcmd(getchar())) {
		case EOF:
		    terminate(0);
		case ESCAPE:
		    break;
		default:
		    docmd(c);           /* process input */
	    }

	    if (fds == 1)
		continue;               /* keyboard activity only */
	}


	if (disptype == HOST) {
	    if (ifds & (1 << msd[0])) {
		if (M_WaitReq(msd[0], NOTOK, &mis) == NOTOK) {
		    advise(NULLCP, "M_WaitReq failed, SMA down?");
		    terminate(NOTOK);
		}

		if (mis.mi_type != MI_EVENT_REP) {
		    advise(NULLCP, "unknown mi_type = %d, should be \
MI_EVENT_REP", mis.mi_type);
		    continue;
		}

		process_evrep_host(&mis.mi_eventrepv);
		mifree(&mis);

		redisplay();
	    }
	}
	else {          /* ALL */
	    int  i;

	    for (i = 0; i < NofHosts; i++)
		if (msd[i] > 0 && ifds & (1 << msd[i])) {
		    if (M_WaitReq(msd[i], NOTOK, &mis) == NOTOK) {
			MO_ID  sysid;

			if (nfds == msd[i] + 1)
			   nfds--;
			mask &= ~(1 << msd[i]);
			msd[i] = -1;

			sysid.rdnlen = i;
			overwriterec(wfrec(CONN_BROKEN, NULL, &sysid), i+4);
			redisplay();
			continue;
		    }

		    switch (mis.mi_type) {
			case MI_EVENT_REP:
			    process_evrep_all(&mis.mi_eventrepv, i);
			    redisplay();
			    break;

			case MI_GET_RES:
			    if (process_getr_all(&mis.mi_getr) == DONE)
				redisplay();
			    break;

			default:
			    advise(NULLCP, "unknown mi_type = %d",
								mis.mi_type);
			    continue;
		    }
		    mifree(&mis);
		}
	}
    }
}


/* construct title and header formats */

static  getfmt (disptype)
int  disptype;
{
    gettitlefmt(disptype);                      /* title */

    gethdrfmt(disptype, HDR1A, hdr1afmt);       /* hdr 1a */
    gethdrfmt(disptype, HDR1B, hdr1bfmt);       /* hdr 1b */

    if (disptype == HOST) {
	gethdrfmt(disptype, HDR2A, hdr2afmt);   /* hdr 2a */
	gethdrfmt(disptype, HDR2B, hdr2bfmt);   /* hdr 2b */
    }
}


static  gettitlefmt (disptype)
int  disptype;
{
    int  w;

    switch (disptype) {
	case HOST:
	    if ((w = strlen(ttltxt[0])) >= 70)
		sprintf(ttlfmt, "%%-70.70s%%-8.8s");
	    else
	        sprintf(ttlfmt, "%%-%d.%ds%%-%d.%ds",
				w, w, LNLEN-2-w, LNLEN-2-w);
	    break;

	case ALL:
	    sprintf (ttlfmt, "%%-%d.%ds", LNLEN-2, LNLEN-2);
	    break;

	default:
	    error(NULLCP, "gettitlefmt: unknown display type %d", disptype);
    }
}


static  gethdrfmt (disptype, hdrln, hdrfmt)
int  disptype, hdrln;
char  hdrfmt[];
{
    switch (disptype) {
	case HOST:
	    switch (hdrln) {
		case HDR1A:
		    strcpy(hdrfmt, "%-8s|            |%-6.5s| %-10.9s\
| %-10.9s|  %-9.6s| %-5.4s| %.5s");
		    break;

		case HDR1B:
		    strcpy(hdrfmt, "   %-5.2s|   %-9.5s|%.6s|  %-9.7s\
|  %-9.7s| %-10.9s| %-5.4s| %-5.4s");
		    break;

		case HDR2A:
		    strcpy(hdrfmt, " %-7.6s|            |             \
|      %-10.5s|      %-10.5s|        ");
		    break;

		case HDR2B:
		    strcpy (hdrfmt, "%-8.7s|   %-9.5s| %-12.11s| %-15.14s\
| %-15.14s| %-7.5s");
		    break;

		default:
		    error(NULLCP, "gethdrfmt: unknown hdrln %d", hdrln);
	    }
	    break;

	case ALL:
	    switch (hdrln) {
		case HDR1A:
		    strcpy(hdrfmt, "          |            |  %-7.5s|     \
%-9.5s|%-9.8s| %-8.6s|%.4s|%.4s");
		    break;

		case HDR1B:
		    strcpy(hdrfmt, "   %-7.4s| %-11.9s|%.9s|%14.14s|%.9s|%.9s\
|%.4s|%.4s");
		    break;

		default:
		    error(NULLCP, "gethdrfmt: illegal hdrln %d", hdrln);
	    }
	    break;

	default:
	    error(NULLCP, "unknown display type %d", disptype);
    }
}


/* make title */

static  mktitle (disptype)
int  disptype;
{
    switch (disptype) {
	case HOST:
	    sprintf (title, ttlfmt, ttltxt[0], host);
	    break;

	case ALL:
	    sprintf (title, ttlfmt, ttltxt[1]);
	    break;

	default:
	    error(NULLCP, "unknown display type %d", disptype);
    }
}


static FREC  frec;
static char  buf[512];


FREC  *wfrec (mode, mobj, objinst)
int  mode;
ManagedObjectS  *mobj;
MO_ID  *objinst;
{
    static char bootTime [MAXHOSTS] [TIMELEN+1];
    int  i, pid, fd;
    char *time, *tprot2str(), *cept2rhost(), *utct2disptime();

    switch (mode) {
	case T_EINV:
	    if (objinst2id(objinst, T_EINV, NULLIP, &pid) == NOTOK) {
		advise(NULLCP, "wfrec: bad objinst");
		return ((FREC *) NULL);
	    }

	    time = utct2disptime(&mobj->einv->creationTime);
	    *(time+12) = '\0';

	    sprintf(buf, "%-8d|%.12s|%4d  |%4d%5d  |%4d%5d  |%4d%5d  |%4d  \
|%4d  ",
				pid, time,
				mobj->einv->activeConnections,
				mobj->einv->crTPDUSuccessfulIn,
				mobj->einv->crTPDUSuccessfulOut,
				mobj->einv->crTPDUUnsuccessfulIn,
				mobj->einv->crTPDUUnsuccessfulOut,
				mobj->einv->crTPDUCongestion,
				mobj->einv->crTPDUConfigurationError,
				mobj->einv->tProtocolError,
				mobj->einv->tPDUChecksumError);
	    frec.f_compid.id1 = pid;
	    frec.f_compid.id2 = GRP1;
	    break;

	case T_CEPT:
	    if (objinst2id(objinst, T_CEPT, NULLIP, &pid, &fd) == NOTOK) {
		advise(NULLCP, "wfrec: bad objinst");
		return ((FREC *) NULL);
	    }

	    time = utct2disptime(&mobj->cept->creationTime);
	    *(time+15) = '\0';

	    sprintf(buf, "%-5d%2d |  %-10.8s| %-12.12s|%5d%5d%5d \
|%5d%5d%5d |  %-6.5s",
				pid, fd, time+7,
				cept2rhost(mobj->cept, host),
				mobj->cept->numberTPDUSent,
				mobj->cept->numberTPDUReceived,
				mobj->cept->numberTPDURetransmitted,
				mobj->cept->numberBytesSent,
				mobj->cept->numberBytesReceived,
				mobj->cept->numberBytesRetransmitted,
				tprot2str(mobj->cept->tProtocol));
	    frec.f_compid.id1 = pid;
	    frec.f_compid.id2 = fd;
	    break;

	case M_SYSTEM:
	    /* it only saves system boot time here */

	    time = utct2disptime(&mobj->einv->creationTime);
	    *(time+12) = '\0';
	    strncpy (bootTime[objinst->rdnlen], time, TIMELEN);
	    bootTime[objinst->rdnlen][TIMELEN] = '\0';

	    return ((FREC *) NULL);

	case T_ENTITY:
	    i = objinst->rdnlen;
	    sprintf(buf, "%-10.10s|%.12s|%3d%5d |%4d %4d %4d|%4d%4d |%4d%4d \
|%3d |%3d ",
				hosts[i], bootTime[objinst->rdnlen],
				mobj->tent->activeConnections,
				mobj->tent->previousConnections,
				mobj->tent->numberTPDUSent,
				mobj->tent->numberTPDUReceived,
				mobj->tent->numberTPDURetransmitted,
				mobj->tent->crTPDUSuccessfulIn +
				mobj->tent->crTPDUSuccessfulOut,
				mobj->tent->crTPDUUnsuccessfulIn +
				mobj->tent->crTPDUUnsuccessfulOut,
				mobj->tent->crTPDUCongestion,
				mobj->tent->crTPDUConfigurationError,
				mobj->tent->tProtocolError,
				mobj->tent->tPDUChecksumError);
	    frec.f_compid.id1 = i;
	    frec.f_compid.id2 = GRP1;
	    break;

	case NO_EINVS:
	    sprintf(buf, "%-78.78s", dfp->df_msg[0]);
	    frec.f_compid.id1 = 0;      /* 'pid' = 0 */
	    frec.f_compid.id2 = GRP1;
	    break;

	case NO_CEPTS:
	    sprintf(buf, "%-78.78s", dfp->df_msg[1]);
	    frec.f_compid.id1 = 0;      /* 'pid' = 0 */
	    frec.f_compid.id2 = 0;      /* 'fd'  = 0 */
	    break;

	case NO_CONN:
	    i = objinst->rdnlen;        /* sysid */
	    sprintf(buf, "%-10.10s|%-68.68s", hosts[i], dfp->df_msg[2]);
	    frec.f_compid.id1 = i;
	    frec.f_compid.id2 = GRP1;
	    break;

	case CONN_BROKEN:
	    i = objinst->rdnlen;        /* sysid */
	    sprintf(buf, "%-8.8s| %-68.68s", hosts[i], dfp->df_msg[3]);
	    frec.f_compid.id1 = i;
	    frec.f_compid.id2 = GRP1;
	    break;

	default:
	    error(NULLCP, "wfrec: bad mode %d", mode);
    }

    frec.f_len  = strlen(buf);
    frec.f_text = buf;
    /* frec.f_time not used */

    return (&frec);
}


FREC  *whdr (mode, hdrline)
int  mode, hdrline;
{
    register char  *bp = buf;
    int  i;

    switch (hdrline) {
	case HDR1A:
	    frec.f_compid.id2 = HDR1A;
	    switch (mode) {
		case T_EINV:
		    sprintf(buf, hdr1afmt,
				dfp->df_hdr1a[0], dfp->df_hdr1a[1],
				dfp->df_hdr1a[2], dfp->df_hdr1a[3],
				dfp->df_hdr1a[4], dfp->df_hdr1a[5],
				dfp->df_hdr1a[6]);
		    break;

		case T_ENTITY:
		    sprintf(buf, hdr1afmt,
				dfp->df_hdr1a[0], dfp->df_hdr1a[1],
				dfp->df_hdr1a[2], dfp->df_hdr1a[3],
				dfp->df_hdr1a[4], dfp->df_hdr1a[5]);
		    break;

		default:
		    error(NULLCP, "whdr: illegal mode %d", mode);
	    }
	    break;

	case HDR1B:
	    frec.f_compid.id2 = HDR1B;
	    switch (mode) {
		case T_EINV:
		    sprintf(buf, hdr1bfmt,
				dfp->df_hdr1b[0], dfp->df_hdr1b[1],
				dfp->df_hdr1b[2], dfp->df_hdr1b[3],
				dfp->df_hdr1b[4], dfp->df_hdr1b[5],
				dfp->df_hdr1b[6], dfp->df_hdr1b[7]);
		    break;

		case T_ENTITY:
		    sprintf(buf, hdr1bfmt,
				dfp->df_hdr1b[0], dfp->df_hdr1b[1],
				dfp->df_hdr1b[2], dfp->df_hdr1b[3],
				dfp->df_hdr1b[4], dfp->df_hdr1b[5],
				dfp->df_hdr1b[6], dfp->df_hdr1b[7]);
		    break;

		default:
		    error(NULLCP, "whdr: illegal mode %d", mode);
	    }
	    break;

	case HDR2A:
	    frec.f_compid.id2 = HDR2A;
	    switch (mode) {
		case T_CEPT:
		    sprintf(buf, hdr2afmt,
				dfp->df_hdr2a[0], dfp->df_hdr2a[1],
				dfp->df_hdr2a[2]);
		    break;

		default:
		    error(NULLCP, "whdr: illegal mode %d", mode);
	    }
	    break;

	case HDR2B:
	    frec.f_compid.id2 = HDR2B;
	    switch (mode) {
		case T_CEPT:
		    sprintf(buf, hdr2bfmt,
				dfp->df_hdr2b[0], dfp->df_hdr2b[1],
				dfp->df_hdr2b[2], dfp->df_hdr2b[3],
				dfp->df_hdr2b[4], dfp->df_hdr2b[5]);
		    break;

		default:
		    error(NULLCP, "whdr: illegal mode %d", mode);
	    }
	    break;

	case BLANK:
	    for (i = 0; i < LNLEN-2; i++)
		*bp++ = ' ';
	    *bp = '\0';
	    frec.f_compid.id2 = (mode == T_CEPT ? HDR2_BLANK : HDR1_BLANK);
	    break;

	case UNDLN:
	    for (i = 0; i < LNLEN-2; i++)
		*bp++ = '-';
	    *bp = '\0';
	    frec.f_compid.id2 = (mode == T_CEPT ? HDR2_UNDLN : HDR1_UNDLN);
	    break;

	default:
	    error(NULLCP, "whdr: illegal hdrline %d", hdrline);
    }

    frec.f_compid.id1 = (mode == T_CEPT ? HDR2 : HDR1);
    frec.f_len  = strlen(buf);
    frec.f_text = buf;
    /* frec.f_time not used */

    return (&frec);
}