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 <gsf@research.att.com> *
18 * *
19 ***********************************************************************/
20 #pragma prototyped
21 /*
22 * coshell attribute expression test
23 */
24
25 #include <service.h>
26
27 State_t state;
28
29 void
shellclose(Coshell_t * a,int b)30 shellclose(Coshell_t* a, int b)
31 {
32 NoP(a);
33 NoP(b);
34 }
35
36 void
jobcheck(Coshell_t * a)37 jobcheck(Coshell_t* a)
38 {
39 NoP(a);
40 }
41
42 static void
init(void)43 init(void)
44 {
45 register int n;
46 register char* s;
47
48 message((-1, "init"));
49 state.toss = state.start = cs.time;
50 for (n = 0; n < 10; n++) TOSS;
51 state.fdtotal = (int)strtol(astconf("OPEN_MAX", NiL, NiL), NiL, 0);
52 if (!(state.con = newof(0, Connection_t, state.fdtotal, 0)))
53 error(3, "out of space [con]");
54 state.con[0].type = POLL;
55 if (!(state.job = state.jobnext = newof(0, Cojob_t, state.fdtotal / 2, 0)))
56 error(3, "out of space [job]");
57 state.jobmax = state.jobnext += state.fdtotal / 2 - 1;
58
59 /*
60 * initialze the shell table
61 */
62
63 state.busy = BUSY;
64 state.grace = GRACE;
65 state.pool = ((s = getenv(CO_ENV_PROC)) && *s) ? (int)strtol(s, NiL, 0) : POOL;
66 if (!(state.home = search(DEF|NEW, csname(0), NiL, NiL)))
67 error(3, "cannot get local host address");
68 state.shell = state.shellnext = state.home;
69 message((-1, "local name is %s", state.home->name));
70
71 /*
72 * load the local net configuration
73 */
74
75 info(DEF|NEW, NiL);
76
77 /*
78 * bias the local host so it can generate more work
79 */
80
81 if (state.home->idle)
82 {
83 state.home->idle = 0;
84 if (!(state.home->flags & SETBIAS)) state.home->bias *= 4;
85 }
86 }
87
88 int
main(int argc,char ** argv)89 main(int argc, char** argv)
90 {
91 register Coshell_t* sp;
92 register char* s;
93 register int op;
94 Coattr_t attr;
95
96 NoP(argc);
97 NoP(argv);
98 error(-1, "debug");
99 init();
100 while ((s = sfgetr(sfstdin, '\n', 0)) && sfvalue(sfstdin) > 1) switch (s[sfvalue(sfstdin) - 1] = 0, op = *s == ':' ? (s++, *s++) : '?')
101 {
102 case '#':
103 break;
104 case '?':
105 case ':':
106 attributes(s, &attr, NiL);
107 sp = state.shell;
108 do
109 {
110 if (match(sp, &attr, 0))
111 {
112 if (op == '?') sfputr(sfstdout, sp->name, '\n');
113 else
114 {
115 sfputr(sfstdout, sp->name, '\t');
116 sfputr(sfstdout, sp->misc, '\n');
117 }
118 }
119 } while ((sp = sp->next) != state.shell);
120 break;
121 case '=':
122 if (!search(SET, s, NiL, NiL))
123 error(2, "%s: invalid host name", s);
124 break;
125 default:
126 error(2, "`%s': invalid command", s - 2);
127 break;
128 }
129 exit(0);
130 }
131