/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1990-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* *18***********************************************************************/19#pragma prototyped20/*21* Glenn Fowler22* AT&T Research23*24* note host status change for name25* this is the daemon side of csstat()26*27* NOTE: name must already exist and pwd must be CS_STAT_DIR28*/2930#include "cslib.h"3132/*33* encode 4 byte int into 2 bytes34*/3536static unsigned short37encode(register unsigned long n)38{39register int e;4041e = 0;42while (n > 03777)43{44n >>= 1;45e++;46}47return n | (e << 11);48}4950int51csnote(register Cs_t* state, const char* name, register Csstat_t* sp)52{53unsigned long idle;54long up;5556if (sp->up < 0)57{58idle = -sp->up;59up = 0;60}61else62{63idle = sp->idle;64up = sp->up;65}66#if 067{68unsigned long a;69unsigned long m;7071a = (encode(up) << 16) | encode(idle);72m = (((sp->load >> 3) & 0377) << 24) | ((sp->pctsys & 0377) << 16) | ((sp->pctusr & 0377) << 8) | (sp->users & 0377);73error(-1, "csnote: <%lu,%lu> load=%lu:%lu pctsys=%lu:%lu pctusr=%lu:%lu users=%lu:%lu idle=%lu:%lu", sp->load, ((m >> 24) & 0xff) << 3, sp->pctsys, (m >> 16) & 0xff, sp->pctusr, (m >> 8) & 0xff, sp->users, m & 0xff, sp->idle, sp->users ? ((a & 0x7ff) << ((a >> 11) & 0x1f)) : ~0, a, m);74}75#endif76return touch(name, (encode(up) << 16) | encode(idle), (((sp->load >> 3) & 0377) << 24) | ((sp->pctsys & 0377) << 16) | ((sp->pctusr & 0377) << 8) | (sp->users & 0377), -1);77}7879int80_cs_note(const char* name, Csstat_t* sp)81{82return csnote(&cs, name, sp);83}848586