2 /* metMain contains the functions that are called by the parser to support the
3 * configuration language. The functions are:
4 * metProcess(..) - build the process list
5 * metDaemon (..) - build the daemon list
6 * metTunable(..) - build the tunable constant list
7 * metVisi(..) - build the visi list
9 * metDoProcess(..) - start a process
10 * metDoDaemon (..) - start a daemon
11 * metDoTunable(..) - set a tunable constant value
12 * metDoVisi(..) - declare a visi
17 * Revision 1.2 1994/07/07 13:10:41 markc
18 * Turned off debugging printfs.
20 * Revision 1.1 1994/07/07 03:25:25 markc
21 * Configuration language parser.
25 #include "paradyn/src/met/metParse.h"
31 #include "util/h/list.h"
32 #include "paradyn/src/pdMain/paradyn.h"
33 #include "util/h/tunableConst.h"
36 int gethostname(char*, int);
39 #define CONFIG_NAME "sample.psdl"
40 #define CONFIG_SLASH "/sample.psdl"
41 #define ROOT_NAME "/p/paradyn/sample.psdl"
44 extern int yyrestart(FILE *);
46 int open_N_parse(char *file);
48 List<tunableStruct*> globalTunable;
49 List<processStruct*> globalProcess;
50 List<visiStruct*> globalVisi;
51 List<daemonStruct*> globalDaemon;
53 // open the config file and parse it
54 // return -1 on failure to open file
55 // else return yyparse result
57 int open_N_parse (char *file)
61 static int been_here = 0;
63 f = fopen (file, "r");
86 static char *convert_local(char *old_host)
93 if (!strcmp("localhost", old_host))
95 if(!gethostname(holder, 99))
96 return(strdup(holder));
101 return strdup(old_host);
105 // parse the 3 files (system, user, application)
110 int yy1, yy2, yy3, hlen;
111 char *home, *homecat;
113 home = getenv("HOME");
115 globalTunable.removeAll();
116 globalProcess.removeAll();
117 globalDaemon.removeAll();
119 yy1 = open_N_parse(ROOT_NAME);
123 hlen += (1 + strlen(CONFIG_NAME));
124 homecat = new char[hlen];
125 strcpy(homecat, home);
126 strcat(homecat, CONFIG_SLASH);
127 yy2 = open_N_parse(homecat);
132 yy3 = open_N_parse(CONFIG_NAME);
134 return (yy1 + yy2 + yy3);
137 void dumpProcess(processStruct ps)
139 List<char*> tempList;
143 printf("DUMPING THE PROCESS\n");
144 printf(" COMMAND: %s\n", ps.command ? ps.command : " ");
145 printf(" NAME: %s\n", ps.name ? ps.name : " ");
148 for (tempList=ps.args; val = *tempList; tempList++)
149 printf("arg %d: %s ", i++, val);
151 printf(" HOST: %s\n", ps.host ? ps.host : " ");
152 printf(" DAEMON: %s\n", ps.daemon ? ps.daemon : " ");
153 printf(" FLAVOR: %d\n", ps.flavor);
156 int metProcess (processStruct ps)
158 processStruct *new_ps;
160 printf("metProcess\n");
161 if (!ps.command || !ps.host || !ps.daemon)
163 printf("for a process, command, daemon, and host must be defined\n");
169 new_ps = new processStruct;
170 new_ps->name = ps.name;
171 new_ps->command = ps.command;
172 new_ps->args = ps.args;
173 new_ps->host = convert_local(ps.host);
174 new_ps->daemon = ps.daemon;
175 new_ps->flavor = ps.flavor;
176 globalProcess.add(new_ps);
182 void dumpVisi (visiStruct vs)
184 List<char*> tempList;
188 printf("DUMPING THE VISI\n");
189 printf(" COMMAND: %s\n", vs.command ? vs.command : " ");
190 printf(" NAME: %s\n", vs.name ? vs.name : " ");
193 for (tempList=vs.args; val = *tempList; tempList++)
194 printf("arg %d: %s ", i++, val);
196 printf(" HOST: %s\n", vs.host ? vs.host : " ");
199 int metVisi(visiStruct vs)
204 if (!vs.command || !vs.name)
206 printf("for a visi, command and name must be defined\n");
212 new_vs = new visiStruct;
213 new_vs->name = vs.name;
214 new_vs->command = vs.command;
215 new_vs->args = vs.args;
216 new_vs->host = convert_local(vs.host);
217 globalVisi.add(new_vs);
222 void dumpTunable (char *name, float value)
224 printf("DUMPING THE TUNABLE\n");
225 printf(" NAME: %s\n", name ? name : " ");
226 printf(" VALUE: %f\n", value);
229 int metTunable (char *name, float value)
233 printf("metTunable\n");
236 printf("for a tunable constant, name must be defined\n");
237 dumpTunable(name, value);
242 ts = new tunableStruct;
245 globalTunable.add(ts);
246 // dumpTunable(name, value);
251 void dumpDaemon (daemonStruct ds)
253 printf("DUMPING THE DAEMON\n");
254 printf(" COMMAND: %s\n", ds.command ? ds.command : " ");
255 printf(" NAME: %s\n", ds.name ? ds.name : " ");
256 printf(" HOST: %s\n", ds.host ? ds.host : " ");
257 printf(" FLAVOR: %d\n", ds.flavor);
260 int metDaemon (daemonStruct ds)
262 daemonStruct *new_ds;
264 printf("metDaemon\n");
265 if (!ds.command || !ds.host)
267 printf("for a daemon, command and host must be defined\n");
273 new_ds = new daemonStruct;
274 new_ds->name = ds.name;
275 new_ds->command = ds.command;
276 new_ds->host = convert_local(ds.host);
277 new_ds->flavor = ds.flavor;
278 globalDaemon.add(new_ds);
286 daemonStruct *the_ds;
287 List<daemonStruct*> dl;
289 for (dl = globalDaemon; the_ds = *dl; dl++)
291 // dumpDaemon(*the_ds);
292 if (dataMgr->addDaemon(context, the_ds->host, (char *) 0,
294 ; //printf("Start daemon %s on %s succeeded\n", the_ds->command,
297 ; //printf("Start daemon %s on %s failed\n", the_ds->command,
306 List<visiStruct*> vl;
307 List <char*> tempList;
312 for (vl = globalVisi; the_vs = *vl; vl++)
314 argc = the_vs->args.count() + 1;
315 argv = new char*[argc+1];
318 argv[0] = strdup(the_vs->command);
319 for (tempList = the_vs->args; val = *tempList; tempList++)
321 argv[i] = strdup(val);
324 // dumpVisi(*the_vs);
325 vmMgr->VMAddNewVisualization(the_vs->name, argc, argv);
326 for (i=0; i<argc; ++i)
327 if (argv[i]) delete argv[i];
335 processStruct *the_ps;
336 List<processStruct*> pl;
337 List <char*> tempList;
342 for (pl = globalProcess; the_ps = *pl; pl++)
344 argc = the_ps->args.count() + 1;
345 argv = new char*[argc+1];
348 argv[0] = strdup(the_ps->command);
349 for (tempList = the_ps->args; val = *tempList; tempList++)
351 argv[i] = strdup(val);
354 // dumpProcess(*the_ps);
355 if (dataMgr->addExecutable(context, the_ps->host, (char*) 0,
356 the_ps->daemon, argc, argv))
357 ; // printf("Start process %s succeeded on %s\n", the_ps->command,
360 ; //printf("Start process %s failed on %s\n", the_ps->command,
363 for (i=0; i<argc; ++i)
364 if (argv[i]) delete argv[i];
372 tunableStruct *the_ts;
373 List<tunableStruct*> tl;
374 tunableConstant* curr;
377 if (!tunableConstant::allConstants)
380 for (tl = globalTunable; the_ts = *tl; tl++)
382 // dumpTunable(the_ts->name, the_ts->value);
383 sp = tunableConstant::pool->findAndAdd(the_ts->name);
384 curr = tunableConstant::allConstants->find(sp);
388 if (!curr->setValue(the_ts->value))
389 ; // printf("Can't set value of tunable constant\n");
391 ; //printf("Set Tunable Constant: %s = %f\n", the_ts->name,