Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libcs/csnote.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1990-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* Glenn Fowler
23
* AT&T Research
24
*
25
* note host status change for name
26
* this is the daemon side of csstat()
27
*
28
* NOTE: name must already exist and pwd must be CS_STAT_DIR
29
*/
30
31
#include "cslib.h"
32
33
/*
34
* encode 4 byte int into 2 bytes
35
*/
36
37
static unsigned short
38
encode(register unsigned long n)
39
{
40
register int e;
41
42
e = 0;
43
while (n > 03777)
44
{
45
n >>= 1;
46
e++;
47
}
48
return n | (e << 11);
49
}
50
51
int
52
csnote(register Cs_t* state, const char* name, register Csstat_t* sp)
53
{
54
unsigned long idle;
55
long up;
56
57
if (sp->up < 0)
58
{
59
idle = -sp->up;
60
up = 0;
61
}
62
else
63
{
64
idle = sp->idle;
65
up = sp->up;
66
}
67
#if 0
68
{
69
unsigned long a;
70
unsigned long m;
71
72
a = (encode(up) << 16) | encode(idle);
73
m = (((sp->load >> 3) & 0377) << 24) | ((sp->pctsys & 0377) << 16) | ((sp->pctusr & 0377) << 8) | (sp->users & 0377);
74
error(-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);
75
}
76
#endif
77
return touch(name, (encode(up) << 16) | encode(idle), (((sp->load >> 3) & 0377) << 24) | ((sp->pctsys & 0377) << 16) | ((sp->pctusr & 0377) << 8) | (sp->users & 0377), -1);
78
}
79
80
int
81
_cs_note(const char* name, Csstat_t* sp)
82
{
83
return csnote(&cs, name, sp);
84
}
85
86