Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/coshell/service.h
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 Bell Laboratories
24
*
25
* remote coshell service definitions
26
*/
27
28
#define LABELLEN 64 /* max label string length */
29
#define NAMELEN 64 /* max name string length */
30
#define TYPELEN 64 /* max type string length */
31
#define MISCLEN 256 /* max misc string length */
32
33
#define _CO_JOB_PRIVATE_ /* Cojob_t private additions */ \
34
char label[LABELLEN];/* optional label */ \
35
int pid; /* pid */ \
36
int rid; /* user request id */ \
37
int sig; /* last signal sent to job */ \
38
int fd; /* con USER fd */ \
39
int ref; /* drop reference count */ \
40
char* cmd; /* cmd msg text */ \
41
Coshell_t* shell; /* controlling shell */ \
42
unsigned long busy; /* time when job becomes hog */ \
43
unsigned long lost; /* time when job is lost */ \
44
unsigned long start; /* start time */ \
45
/* end of private additions */
46
47
#define _CO_SHELL_PRIVATE_ /* Coshell_t private additions */ \
48
Coshell_t* next; /* next in ring */ \
49
char name[NAMELEN]; /* host name */ \
50
char type[TYPELEN]; /* host type */ \
51
char misc[MISCLEN]; /* host misc attributes */ \
52
char remote[MISCLEN];/* remote shell path */ \
53
char shell[MISCLEN]; /* shell path */ \
54
char* access; /* host access expression */ \
55
char* bypass; /* idle bypass expression */ \
56
unsigned long addr; /* host address */ \
57
unsigned long rank; /* scheduling rank */ \
58
unsigned long temp; /* scheduling temperature */ \
59
int mode; /* extra flags */ \
60
int bias; /* scheduling bias */ \
61
int cpu; /* cpu count */ \
62
int errors; /* csstat() error count */ \
63
int fd; /* con SHELL fd */ \
64
int home; /* # users calling this home */ \
65
int idle; /* min # login idle secs */ \
66
int idle_override; /* restore idle override */ \
67
int pid; /* shell pid */ \
68
int open; /* number of successful opens */ \
69
int rating; /* cpu rating */ \
70
int scale; /* load average scale */ \
71
Cs_stat_t stat; /* csstat() status */ \
72
unsigned long override; /* override expiration */ \
73
unsigned long start; /* connect start time */ \
74
unsigned long update; /* time stat last updated */ \
75
/* end of private additions */
76
77
#include <ast.h>
78
#include <cs.h>
79
#include <coshell.h>
80
#include <ctype.h>
81
#include <debug.h>
82
#include <error.h>
83
#include <sig.h>
84
#include <tm.h>
85
#include <tok.h>
86
#include <wait.h>
87
88
#define match(p,a,o) ((!((a)->set&SETNAME)||strmatch((p)->name,(a)->name))&&((((a)->set|o)&(SETMISC|DEF|NEW|SET))==SETMISC?miscmatch(p,(a)->misc):((a)->set&SETNAME)?1:streq((p)->type,state.home->type)))
89
90
#define SHELL_CLOSE (1<<0) /* marked for close */
91
#define SHELL_DENIED (1<<1) /* access denied */
92
#define SHELL_DISABLE (1<<2) /* disabled for UPDATE */
93
#define SHELL_OVERRIDE (1<<3) /* override on open */
94
95
#define ACCESS_SEARCH (60*60) /* CS_SVC_ACCESS search */
96
#define ACCESS_UPDATE (10*60) /* CS_SVC_ACCESS update */
97
#define BIAS 100 /* default bias */
98
#define BUSY ((UPDATE)*2) /* default max busy */
99
#define CHUNK 1024 /* allocation chunk */
100
#define ERRORS 8 /* max csstat() errors */
101
#define FORGET (5*LOST) /* forget lost shell */
102
#define GRACE BUSY /* default busy grace */
103
#define HOG (~0L) /* hog job busy time */
104
#define HOME (3*OVERRIDE) /* home host reprieve */
105
#define LOAD 100 /* default load */
106
#define LOST (1*60) /* job/shell lost secs */
107
#define OVERRIDE (2*60) /* override reprieve */
108
#define POOL 8 /* default proc pool */
109
#define RANK 30000 /* worst rank w/o toss */
110
#define RATING 100 /* default rating */
111
#define TEMPBASE 32 /* temp file name base */
112
#define TOSS CSTOSS(state.toss,0) /* tiebreaker */
113
#define UPDATE ((6*CS_STAT_FREQ)/5) /* csstat() update freq */
114
115
#define COMMAND 1
116
#define DEFER 2
117
#define SERVER 3
118
119
#define ANON 1
120
#define DEST 2
121
#define IDENT 3
122
#define INIT 4
123
#define MESG 5
124
#define PASS 6
125
#define POLL 7
126
#define PUMP 8
127
#define SCHED 9
128
#define SHELL 10
129
#define UCMD 11
130
#define UERR 12
131
#define UOUT 13
132
#define USER 14
133
134
#define USER_DUP (1<<0) /* Couser_t stdout==stderr */
135
#define USER_IDENT (1<<1) /* Couser_t INIT needs ident */
136
#define USER_INIT (1<<2) /* Couser_t INIT hit once */
137
138
#define DEF (1<<0) /* default attributes */
139
#define GET (1<<1) /* get existing shell */
140
#define IGN (1<<2) /* ignore pool member */
141
#define JOB (1<<3) /* schedule job */
142
#define NEW (1<<4) /* make new shell if not found */
143
#define SET (1<<5) /* set attributes */
144
145
#define SETACCESS (1<<6) /* access was set */
146
#define SETBIAS (1<<7) /* bias was set */
147
#define SETBYPASS (1<<8) /* bypass was set */
148
#define SETCPU (1<<9) /* cpu count was set */
149
#define SETIDLE (1<<10) /* idle was set */
150
#define SETIGNORE (1<<11) /* ignore was set */
151
#define SETLABEL (1<<12) /* label was set */
152
#define SETMISC (1<<13) /* misc attribute was set */
153
#define SETNAME (1<<14) /* name was set */
154
#define SETRATING (1L<<15) /* rating was set */
155
#define SETSCALE (1L<<16) /* scale was set */
156
#define SETTYPE (1L<<17) /* type was set */
157
158
#define SETBUSY (1<<0) /* global.busy was set */
159
#define SETDEBUG (1<<1) /* global.debug was set */
160
#define SETDISABLE (1<<2) /* global.disable was set */
161
#define SETFILE (1<<3) /* global.file was set */
162
#define SETGRACE (1<<4) /* global.grace was set */
163
#define SETIDENTIFY (1<<5) /* global.identify was set */
164
#define SETLOAD (1<<6) /* stat.load was set */
165
#define SETMAXIDLE (1<<7) /* global.maxidle was set */
166
#define SETMAXLOAD (1<<8) /* global.maxload was set */
167
#define SETMIGRATE (1<<9) /* global.migrate was set */
168
#define SETPERCPU (1<<10) /* global.percpu was set */
169
#define SETPERHOST (1<<11) /* global.perhost was set */
170
#define SETPERSERVER (1<<12) /* global.perserver was set */
171
#define SETPERUSER (1<<13) /* global.peruser was set */
172
#define SETPOOL (1<<14) /* global.pool was set */
173
#define SETPROFILE (1L<<15) /* global.profile was set */
174
#define SETSCHEDULE (1L<<16) /* global.schedule was set */
175
#define SETUPDATE (1L<<17) /* stat.update was set */
176
#define SETUSERS (1L<<18) /* stat.users was set */
177
178
#define SETREMOTE (1L<<29) /* (global) remote was set */
179
#define SETSHELL (1L<<30) /* (global) shell was set */
180
181
#define QUEUE (-1) /* waiting for shell to open */
182
#define START (-2) /* started but no pid */
183
#define WARP (-3) /* exit before start message */
184
185
typedef struct
186
{
187
char name[NAMELEN];
188
char type[TYPELEN];
189
char misc[MISCLEN];
190
char label[LABELLEN];
191
char remote[MISCLEN];
192
char shell[MISCLEN];
193
char* access;
194
char* bypass;
195
int bias;
196
int cpu;
197
int idle;
198
int ignore;
199
int rating;
200
int scale;
201
unsigned long set;
202
203
struct
204
{
205
char* file;
206
char* identify;
207
char* migrate;
208
char* profile;
209
char* remote;
210
char* schedule;
211
char* shell;
212
int busy;
213
int debug;
214
unsigned long disable;
215
int grace;
216
int maxidle;
217
int maxload;
218
int percpu;
219
int perhost;
220
int perserver;
221
int peruser;
222
int pool;
223
unsigned long set;
224
} global;
225
226
Cs_stat_t stat;
227
} Coattr_t;
228
229
typedef struct
230
{
231
Coshell_t* shell;
232
int pid;
233
} Coident_t;
234
235
typedef struct
236
{
237
Cojob_t* job;
238
Sfio_t* serialize;
239
short fd;
240
} Copass_t;
241
242
typedef struct
243
{
244
Coshell_t* home;
245
char* pump;
246
char* expr;
247
Coattr_t attr;
248
short fds[3];
249
short flags;
250
short pid;
251
short running;
252
short total;
253
} Couser_t;
254
255
typedef struct
256
{
257
union
258
{
259
Coident_t ident;
260
Copass_t pass;
261
Coshell_t* shell;
262
Couser_t user;
263
} info;
264
short type;
265
short error;
266
short flags;
267
} Connection_t;
268
269
typedef struct
270
{
271
int con;
272
int cmd;
273
int err;
274
int msg;
275
int out;
276
char* pump;
277
} Indirect_t;
278
279
typedef struct
280
{
281
unsigned long access;
282
char** argv;
283
char* buf;
284
int buflen;
285
unsigned long busy;
286
Pathcheck_t check;
287
unsigned long clock;
288
int cmds;
289
Connection_t* con;
290
int connect;
291
unsigned long disable;
292
int fdtotal;
293
gid_t* gids;
294
unsigned long grace;
295
Coshell_t* home;
296
char* identify;
297
Indirect_t indirect;
298
Cojob_t* job;
299
Cojob_t* jobmax;
300
Cojob_t* jobnext;
301
int jobs;
302
int joblimit;
303
int jobwait;
304
int maxidle;
305
int maxload;
306
char* mesg;
307
char* migrate;
308
int open;
309
int override;
310
int percpu;
311
int perhost;
312
int perserver;
313
int peruser;
314
int pool;
315
char* profile;
316
char* pump;
317
unsigned long real;
318
char* remote;
319
int running;
320
struct
321
{
322
char* name;
323
int fd;
324
} scheduler;
325
char* service;
326
int set;
327
char* sh;
328
Coshell_t* shell;
329
Coshell_t* shellnext;
330
int shellc;
331
int shelln;
332
int shells;
333
Coshell_t** shellv;
334
int shellwait;
335
unsigned long start;
336
Sfio_t* string;
337
unsigned long sys;
338
unsigned long toss;
339
unsigned long user;
340
unsigned long wakeup;
341
Tm_t* tm;
342
uid_t uid;
343
int users;
344
char* version;
345
Coshell_t wait;
346
} State_t;
347
348
/*
349
* coshell specific globals
350
*/
351
352
extern const char corinit[];
353
extern State_t state;
354
355
extern void attributes(char*, Coattr_t*, Coattr_t*);
356
extern int byname(const char*, const char*);
357
extern int byrank(const char*, const char*);
358
extern int bytemp(const char*, const char*);
359
extern int command(int, char**);
360
extern void drop(int);
361
extern char* fmtfloat(int);
362
extern Coshell_t* info(int, char*);
363
extern void jobcheck(Coshell_t*);
364
extern void jobdone(Cojob_t*);
365
extern void jobkill(Cojob_t*, int);
366
extern void miscadd(Coshell_t*, char*);
367
extern int miscmatch(Coshell_t*, char*);
368
extern Coshell_t* search(int, char*, Coattr_t*, Coattr_t*);
369
extern void server(int, int, int, int, char*);
370
extern void shellcheck(void);
371
extern void shellclose(Coshell_t*, int);
372
extern void shellexec(Cojob_t*, char*, int);
373
extern int shellopen(Coshell_t*, int);
374
extern char* stream(int, char*);
375
extern void update(Coshell_t*);
376
377