vlp-10 using coding style in cint.c
[vlp.git] / src / int / cint.c
1  
2
3 #include "depend.h"
4 #include "genint.h"
5 #include "int.h"
6 #include "process.h"
7 #include "intproto.h"
8 #include "socu.h"
9 #include <fcntl.h>
10 #include <sys/stat.h>
11 #include <sys/time.h>
12 #include <netinet/in.h>
13 #include <arpa/inet.h>
14 #include <errno.h>
15 #include <netdb.h>
16 #include <qthread.h>
17
18 #ifndef NO_PROTOTYPES
19 static void load(char *);
20 static void initiate(int,char **);
21 int main(int,char **);
22 #else
23 static void load();
24 static void initiate();
25 int main();
26 #endif
27
28
29
30 int internal_sock, graph_sock, net_sock, connected = 0;
31 struct sockaddr_un svr;
32 int GraphRes=-1;
33 char ProgName[255], mygname[80], gname[80], mykname[80], nname[80], mynname[80];
34 fd_set DirSet;
35 int maxDirSet;
36
37 ctx_struct my_ctx;
38 ctx_struct parent_ctx;
39
40 /* IDs of remote instances */
41 int RInstance[255];
42 /* Direct connection channels */
43 int DirConn[255];
44
45 /* graphic vars */
46 int fcol, bcol, curx=0, cury=0;
47
48
49 /* Macro to decode addressing modes : */
50 #define getargument(a, argnr)                                       \
51     switch (eop->args[ argnr ])                                     \
52     {                                                               \
53         case GLOBAL     : a = M[ ic++ ];             break;         \
54         case LOCAL      : a = c1+M[ ic++ ];          break;         \
55         case TEMPLOCAL  : a = c2+M[ ic++ ];          break;         \
56         case REMOTE     : a = M[ M[ ic+1 ] ]+M[ ic ];  ic+=2; break;\
57         case INDIRECT   : a = M[ M[ ic++ ] ];                 break;\
58         case IMMEDIATE  : a = ic++;                           break;\
59         case CONSTANT  : a = M[ ic++ ];                       break;\
60         case DOTACCESS : a = M[ display+M[ ic+1 ] ]+M[ ic ];  ic += 2; break;\
61         case NOARGUMENT : return;                          \
62     }
63
64 /**
65  * Load code and prototypes from file
66  */
67 static void load(char *_filename)
68 {
69         FILE *fp;
70         char *cp;
71         word n, left;
72         /* should suffice on all systems */
73         char filename[100];
74
75         strcpy(filename, _filename);
76         /* allocate main memory array */
77         M = mallocate(memorysize + 1);
78         if (M == NULL)
79                 abend("Memory size too large (use /m option)\n");
80
81         addext(filename, ".ccd");
82         if ((fp = fopen(filename, BINARYREAD)) == NULL) {
83                 fprintf(stderr, "Cannot open .ccd file\n");
84                 endrun(10);
85         };
86
87         /* read static data and code from .ccd file */
88         ic = 0;
89         left = memorysize + 1;
90         do {
91                 if (left == 0)
92                         abend("Memory size too small (use /m option)\n");
93                 n = min(IOBLOCK / sizeof(word), left);
94                 n = fread((char *) &M[ ic ], sizeof(word), (int) n, fp);
95                 ic += n;
96                 left -= n;
97         } while (n != 0);
98         /* now ic = number of words read */
99
100         fclose(fp);
101         
102         /* Get various addresses passed by GENERATOR */
103         
104         /* primitive type desctriptions */
105         ipradr = M[ic - 5];
106         /* global temporary variables */
107         temporary = M[ic - 4];
108         /* string constants */
109         strings = M[ic - 3];
110         /* last prototype number */
111         lastprot = M[ic - 2];
112         /* first free word in memory */
113         freem = M[ic - 1];
114
115         /* Read prototypes from .pcd file */
116         addext(filename, ".pcd");
117         if ((fp = fopen(filename, BINARYREAD)) == NULL) {
118                 fprintf(stderr,"Cannot open .pcd file\n");
119                 endrun(10); 
120         }
121         for (n = MAINBLOCK; n <= lastprot; n++) {
122                 cp = ballocate(sizeof(protdescr));
123                 if (cp == NULL)
124                         abend("Memory size too large (use /m option)\n");
125                 prototype[n] = (protdescr *) cp;
126
127                 if (fread(cp, sizeof(protdescr), 1, fp) != 1)
128                         abend("Cannot read .pcd file\n");
129         }
130         fclose(fp);
131
132         /* Open trace file */
133         if (debug) {
134                 addext(filename, ".trd");
135                 if ((tracefile = fopen(filename, "w")) == NULL)
136                         abend("Cannot open .trd file\n");
137         }
138 }
139
140 /**
141  * Establish configuration parameters
142  */
143 static void initiate(int argc, char **argv)
144 {
145         long m;
146         int len,i,on;
147         char filename[80];
148         int sock;
149         fd_set rset, wset;
150
151         ournode = 0;
152         network = TRUE;
153         if ((argc == 4) && (strcmp(argv[3], "r") == 0))
154                 remote = TRUE;
155         else
156                 remote = FALSE;
157         
158         for(i = 0; i < 255; i++) {
159                 RInstance[i] = -1;
160                 DirConn[i] = -1;
161         }
162
163         FD_ZERO(&DirSet);
164         maxDirSet = 0;
165  
166         strcpy(filename, argv[2]);
167         strcpy(ProgName, argv[2]);
168
169         strcpy(mynname, argv[1]);
170         strcat(mynname, ".net");
171         unlink(mynname);
172         sock = socket(AF_UNIX, SOCK_STREAM, 0);
173         bzero(&svr, sizeof(svr));
174         svr.sun_family = AF_UNIX;
175         strcpy(svr.sun_path, mynname);
176         len = strlen(svr.sun_path) + sizeof(svr.sun_family);
177         bind(sock, (struct sockaddr*)&svr, len);
178         listen(sock, 5);
179
180
181         /* socket for graphic requests */ 
182         strcpy(mygname, argv[1]);
183         strcat(mygname, ".gr");
184         unlink(mygname);
185
186         /* socket for KERNEL communication */  
187         internal_sock = socket(AF_UNIX, SOCK_STREAM, 0);
188         bzero(&svr, sizeof(svr));
189         svr.sun_family = AF_UNIX;
190         strcpy(svr.sun_path, argv[1]);
191         strcpy(mykname, argv[1]);
192         len = strlen(svr.sun_path) + sizeof(svr.sun_family);
193         i = connect(internal_sock, (struct sockaddr*)&svr, len);
194
195         if (i==0) {
196                 fcntl(internal_sock,F_SETFL, O_NONBLOCK |
197                                                 fcntl(internal_sock,F_GETFL,0));
198         }
199         else
200                 while (i!=0) {
201                         close(internal_sock);
202                         internal_sock = socket(AF_UNIX, SOCK_STREAM, 0);
203                         fcntl(internal_sock, F_SETFL, O_NONBLOCK |
204                                         fcntl(internal_sock, F_GETFL, 0));
205                         i = connect(internal_sock, (struct sockaddr*)&svr, len);
206                 }
207         on = 1;
208         setsockopt(internal_sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on,
209                                                                 sizeof(on));
210
211         /* socket for network requests */
212         FD_ZERO(&rset);
213         FD_ZERO(&wset);
214         FD_SET(sock, &rset);
215         if (select(sock + 1, &rset, &wset, 0, 0))
216                 net_sock = accept(sock, (struct sockaddr*)0, (int *)0);
217
218         if (net_sock > 0) {
219                 fcntl(net_sock, F_SETFL, O_NONBLOCK |
220                                                 fcntl(net_sock, F_GETFL, 0));
221                 setsockopt(net_sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on,
222                                                                 sizeof(on));
223
224         }
225         close(sock);
226
227         /* load code and prototypes */
228         if (filename != NULL)
229                 load(filename);
230         else
231                 usage();
232 }
233
234
235 void decode(){
236         extopcode *eop;
237
238         /* pointer to extended opcode in M */
239         eop = (extopcode *)(M + ic);
240         /* save ic for possible redecoding */
241         lastic = ic;
242         ic += APOPCODE;
243         opcode = ((int) eop->opcode ) & 0xFF ;
244         getargument(a1, 0);
245         getargument(a2, 1);
246         getargument(a3, 2);
247 }
248
249 /* -------------------------------------------------------------------- */
250
251
252 void send_to_graph(G_MESSAGE *msg)
253 {
254         write(graph_sock, msg, sizeof(G_MESSAGE));
255 }
256
257 int read_from_graph(G_MESSAGE *msg)
258 {
259         fd_set rset,wset;
260         struct timeval tout = {0, 0};
261
262         FD_ZERO(&rset);
263         FD_ZERO(&wset);
264         FD_SET(graph_sock, &rset);
265
266
267         if (select(graph_sock + 1, &rset, &wset, 0, (struct timeval *)&tout) > 0) {
268                 if (FD_ISSET(graph_sock, &rset))
269                         return(read(graph_sock,msg,sizeof(G_MESSAGE)));
270         }
271         return(0);
272 }
273
274 int read_from_net(MESSAGE *msg)
275 {
276         fd_set rset,wset;
277         struct timeval tout = {0, 0};
278
279         FD_ZERO(&rset);
280         FD_ZERO(&wset);
281         FD_SET(net_sock, &rset);
282
283
284         if (select(net_sock + 1, &rset, &wset, 0, (struct timeval *)&tout) > 0) {
285                 if (FD_ISSET(net_sock, &rset))
286                         return(read(net_sock, msg, sizeof(MESSAGE)));
287         }
288         return(0);
289 }
290
291
292 /* Get graphic resource number */
293 int get_graph_res()
294 {
295         MESSAGE msg;
296         int sock;
297         struct sockaddr_un svr;
298         int len, i, on;
299         fd_set rset, wset;
300
301         unlink(mygname);
302         sock = socket(AF_UNIX, SOCK_STREAM, 0);
303         bzero(&svr, sizeof(svr));
304         svr.sun_family = AF_UNIX;
305         strcpy(svr.sun_path, mygname);
306         len = strlen(svr.sun_path) + sizeof(svr.sun_family);
307         bind(sock, (struct sockaddr*)&svr, len);
308         listen(sock, 5);
309
310
311         msg.msg_type = MSG_GRAPH;
312         msg.param.pword[0] = GRAPH_ALLOCATE;
313         strcpy(msg.param.pstr, mygname);
314         write(internal_sock, &msg, sizeof(MESSAGE));
315         bzero(&msg, sizeof(MESSAGE));
316         FD_ZERO(&rset);
317         FD_ZERO(&wset);
318         FD_SET(sock, &rset);
319         if (select(sock+1, &rset, &wset, 0, 0))
320                 graph_sock = accept(sock, (struct sockaddr*)0, (int*)0);
321
322         if (graph_sock == -1) {
323                 graphics = FALSE;
324                 return 0;
325         }
326         on = 1;
327         close(sock);
328         fcntl(graph_sock, F_SETFL, O_NONBLOCK|fcntl(graph_sock, F_GETFL, 0));
329         setsockopt(graph_sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on, sizeof(on));
330
331         return 1;
332 }
333
334
335 /* writeln string */
336 void writeln_str(char *s)
337 {
338         G_MESSAGE msg;
339         msg.msg_type = MSG_GRAPH;
340         msg.param.pword[1] = GraphRes;
341         msg.param.pword[2] = GRAPH_WRITE;
342         strcpy(msg.param.pstr, s);
343
344         send_to_graph(&msg);
345         strcpy(msg.param.pstr, "\n");
346         send_to_graph(&msg);
347 }
348
349 /* write string */
350 void write_str(char *s)
351 {
352         G_MESSAGE msg;
353         msg.msg_type = MSG_GRAPH;
354         msg.param.pword[1] = GraphRes;
355         msg.param.pword[0] = GRAPH_WRITE;
356         strcpy(msg.param.pstr, s);
357         send_to_graph(&msg);
358 }
359
360 /* write char */
361 void write_char(char a)
362 {
363         G_MESSAGE msg;
364
365         msg.msg_type = MSG_GRAPH;
366         msg.param.pword[1] = GraphRes;
367         msg.param.pword[0] = GRAPH_PUTCHAR;
368         msg.param.pchar = a;
369         send_to_graph(&msg);
370 }
371
372
373 /* read char */
374 char read_char()
375 {
376         char ch;
377         G_MESSAGE msg;
378         int st;
379
380         msg.msg_type = MSG_GRAPH;
381         msg.param.pword[1] = GraphRes;
382         msg.param.pword[0] = GRAPH_READCHAR;
383         send_to_graph(&msg);
384         while(TRUE) {
385                 st = read_from_graph(&msg);
386                 if (st > 0) {
387                         if ((msg.msg_type == MSG_GRAPH) && 
388                                 (msg.param.pword[0] == GRAPH_READCHAR_RESPONSE)) 
389                                 {
390                                 ch = msg.param.pchar;
391                                 break;
392                         }
393                 }
394         }
395         return ch;
396 }
397
398 /* read line */
399 void read_line()
400 {
401         G_MESSAGE msg;
402         int st;
403
404
405         msg.msg_type = MSG_GRAPH;
406         msg.param.pword[1] = GraphRes;
407         msg.param.pword[0] = GRAPH_READLN;
408         send_to_graph(&msg);
409         while(TRUE) {
410                 st = read_from_graph(&msg);
411                 if (st > 0)
412                         if ((msg.msg_type == MSG_GRAPH) &&
413                                 (msg.param.pword[0]== GRAPH_READLN_RESPONSE))
414                                 break;
415         }
416 }
417
418 /* read string */
419 void read_str(char *s)
420 {
421         char ss[255];
422         G_MESSAGE msg;
423         int st;
424
425         msg.msg_type = MSG_GRAPH;
426         msg.param.pword[1] = GraphRes;
427         msg.param.pword[0] = GRAPH_READSTR;
428         send_to_graph(&msg);
429         while(TRUE) {
430                 st = read_from_graph(&msg);
431                 if (st > 0) {
432                         if ((msg.msg_type == MSG_GRAPH) && 
433                                 (msg.param.pword[0]==GRAPH_READSTR_RESPONSE)) {
434                                 strcpy(ss,msg.param.pstr);
435                                 break;
436                         }
437                 }
438         }
439         strcpy(s, ss);
440 }
441
442 /**
443  * send message to kernel
444  */
445 void send_to_kernel(MESSAGE *msg)
446 {
447         write(internal_sock, msg, sizeof(MESSAGE));
448 }
449
450 /* send message to net */
451 /* 2010 returns 1 if ok and 0 if node desn't exists */
452 int send_to_net(MESSAGE *msg)
453 {
454         int k, len;
455         MESSAGE m;
456         struct sockaddr_in svr;
457         char addr[256];
458
459
460         k = msg->int_msg.control.receiver.node; 
461
462         /* 2010 check if node exists */
463         m.msg_type = MSG_NET;
464         m.param.pword[0] = NET_NODE_EXIST;
465         m.param.pword[1] = k;
466         m.param.pword[2] = my_ctx.program_id;
467         write(net_sock, &m, sizeof(MESSAGE));
468         bzero(&m, sizeof(MESSAGE));
469          while((m.msg_type != MSG_NET) && (m.param.pword[0] != NET_NODE_EXIST))
470                 read(net_sock, &m, sizeof(MESSAGE));
471
472         if (m.param.pword[1] != 1)
473                 return 0;
474
475         strcpy(addr, m.param.pstr);
476
477         if (RInstance[k] == -1) {
478                 bzero(&m,sizeof(MESSAGE));
479                 m.msg_type = MSG_VLP;
480                 m.param.pword[0] = VLP_REMOTE_INSTANCE_PLEASE;
481                 m.param.pword[1] = my_ctx.program_id;
482                 m.param.pword[2] = k;
483                 send_to_kernel(&m);
484                 bzero(&m, sizeof(MESSAGE));
485
486                 while(1) {
487                         read(internal_sock, &m, sizeof(MESSAGE));
488                         if ((m.msg_type == MSG_VLP) &&
489                                 (m.param.pword[0] == VLP_REMOTE_INSTANCE_HERE))
490                                 break;
491                 }
492
493                 /*printf("DEBUG: remote instance made with id: "
494                         "%d addr %s port %d\n", m.param.pword[1], addr,
495                         htons(m.param.pword[8]));*/
496                 RInstance[k] = m.param.pword[1];
497                 /* Make direct connection */
498                 DirConn[k] = socket(AF_INET, SOCK_STREAM, 0);
499                 svr.sin_family = AF_INET;
500                 svr.sin_addr.s_addr = inet_addr(addr);
501                 svr.sin_port = htons(m.param.pword[8]);
502                 len = connect(DirConn[k], (struct sockaddr*)&svr, sizeof(svr));
503                 if (len!=0) {
504                         RInstance[k] = -1;
505
506                         writeln_str("Cannot connect remote instance!");
507                 } else {
508                         fcntl(DirConn[k], F_SETFL, O_NONBLOCK |
509                                                 fcntl(DirConn[k], F_GETFL, 0));
510                 }
511         }
512         if (RInstance[k] != -1) {
513                 write(DirConn[k], &(msg->int_msg), sizeof(message));
514         } 
515         return 1;
516 }
517
518 /* -------------------- Check for message on internal socket -------------*/
519
520 void get_internal()
521 {
522         MESSAGE m, m1;
523         message mx;
524
525         int r, max, i;
526         char s[80];
527         fd_set rset;
528         struct timeval tout = {0, 0};
529
530  /* 2010 */
531  /* ----------- Direct connection messages -----
532         FD_ZERO(&DirSet);
533         maxDirSet = 0;
534         for(i = 0; i < 255; i++)
535                 if (DirConn[i]!=-1) {
536                         FD_SET(DirConn[i], &DirSet);
537                         if (maxDirSet<DirConn[i])
538                                 maxDirSet=DirConn[i];
539                 }
540
541         if (select(maxDirSet + 1, &DirSet, 0, 0, (struct timeval *)&tout) > 0) {
542                 for(i = 0; i < 255; i++) {
543                         if ((DirConn[i] != -1) &&
544                                         (FD_ISSET(DirConn[i], &DirSet))) {
545                                 r = read(DirConn[i], &mx, sizeof(mx));
546                                 if (r > 0) {
547                                         memcpy(globmsgqueue + msgtail,&mx,
548                                                         sizeof(message));
549                                         msgtail = (msgtail + 1) % MAXMSGQUEUE;
550                                         msgready++;
551                                 }
552                         }
553                 }
554         }
555 -----------------------------------------*/
556
557         FD_ZERO(&rset);
558         FD_SET(net_sock, &rset);
559         FD_SET(internal_sock, &rset); 
560         if (net_sock > internal_sock)
561                 max = net_sock;
562         else
563                 max = internal_sock;
564         /* 2010 */
565         for(i = 0; i < 255; i++) {
566                 if (DirConn[i] != -1) {
567                         FD_SET(DirConn[i], &rset);
568                         if (max < DirConn[i])
569                                 max = DirConn[i];
570                 }
571         }
572
573         if (select(max + 1, &rset, 0, 0, (struct timeval *)&tout) > 0) {
574                 /* 2010 */
575                 for(i = 0; i < 255; i++) {
576                         if ((DirConn[i] != -1) && (FD_ISSET(DirConn[i], &rset))) {
577                                 /*
578                                 printf("DEBUG: Interp has message on "
579                                         "direct connection: type %d par %d\n",
580                                                 mx.control.type,mx.control.par);
581                                 */
582                                 r = read(DirConn[i], &mx, sizeof(mx));
583                                 if (r > 0 && r == sizeof(mx)) {
584                                         memcpy(globmsgqueue + msgtail, &mx,
585                                                         sizeof(message));
586                                         msgtail = (msgtail+1) % MAXMSGQUEUE;
587                                         msgready++;
588                                 } 
589                         }
590                 }
591
592                 if (FD_ISSET(net_sock,&rset)) {
593                         r = read(net_sock, &m, sizeof(MESSAGE));
594                 
595                         if (r>0) {
596                                 switch(m.msg_type) {
597                                 case MSG_NET:
598                                         switch(m.param.pword[0]) {
599                                         case NET_PROPAGATE:
600                                         /*
601                                         printf("DEBUG: cint net_sock MSG_NET "
602                                                 "NET_PROPAGATE cmd %d\n",
603                                                         m.param.pword[6]);*/
604                                                 memcpy(globmsgqueue + msgtail,
605                                                         &m.int_msg,
606                                                         sizeof(message));
607                                                 msgtail = (msgtail + 1) %
608                                                                 MAXMSGQUEUE;
609                                                 msgready++;
610                                                 break;
611                                         };
612                                         break;
613                                 }
614                         }
615                 }
616
617                 if (FD_ISSET(internal_sock, &rset)) {
618                         r = read(internal_sock, &m, sizeof(MESSAGE));
619
620                         if (r > 0) {
621                                 switch(m.msg_type) {
622                                 case MSG_INT:
623                                         switch(m.param.pword[0]) {
624                                         case INT_CLOSE_INSTANCE:
625                                                 endrun(0);
626                                         case INT_KILL:
627                                                 endrun(1);
628                                         default:
629                                                 break;
630                                         }
631                                 case MSG_NET:
632                                         if (m.param.pword[0] == NET_PROPAGATE) {
633                                                 /*
634                                                 printf("DEBUG: cint internal_sock MSG_NET NET_PROPAGATE cmd %d\n",m.param.pword[6]);*/
635                                                 memcpy(globmsgqueue + msgtail,
636                                                         &m.int_msg,
637                                                         sizeof(message));
638                                                 msgtail = (msgtail+1) %
639                                                                 MAXMSGQUEUE;
640                                                 msgready++;
641                                         };
642                                         break;
643                                 }
644                         }
645                 }
646         }
647 }
648
649
650 void request_id()
651 {
652         MESSAGE m;
653         G_MESSAGE m1; 
654
655         m.msg_type = MSG_INT;
656         m.param.pword[0] = INT_CTX_REQ;
657         send_to_kernel(&m);
658         while ((m.msg_type != MSG_INT) || (m.param.pword[0] != INT_CTX))
659                 read(internal_sock, &m, sizeof(MESSAGE));
660
661         my_ctx.node = m.param.pword[1];
662         my_ctx.program_id = m.param.pword[2];
663         if (remote) {
664                 parent_ctx.node = m.param.pword[3];
665                 parent_ctx.program_id = m.param.pword[4];
666                 RInstance[parent_ctx.node] = parent_ctx.program_id;
667         } else {
668                 parent_ctx.node = my_ctx.node;
669                 parent_ctx.program_id = my_ctx.program_id;
670         }
671         ournode = my_ctx.node;
672         /* strcpy(nname,m.param.pstr);*/
673         /* net_sock = open(nname,O_WRONLY);*/
674         m1.msg_type = MSG_GRAPH;
675         m1.param.pword[0] = GRAPH_SET_TITLE;
676         m1.param.pword[1] = GraphRes;
677         sprintf(m1.param.pstr, "%s      ID: %d", ProgName, my_ctx.program_id);
678
679         if (remote)
680                 strcat(m1.param.pstr, "  REMOTE instance");
681         send_to_graph(&m1);
682 }
683
684
685
686 void send_ready()
687 {
688         int sock, len;
689         struct sockaddr_in svr;
690         char name[255];
691         struct hostent *info;
692
693         MESSAGE msg;
694         msg.msg_type = MSG_NET;
695         msg.param.pword[0] = NET_PROPAGATE;
696         msg.param.pword[1] = MSG_VLP;
697         msg.param.pword[2] = my_ctx.node;
698         msg.param.pword[4] = parent_ctx.node;
699         msg.param.pword[6] = VLP_REMOTE_INSTANCE_OK;
700         msg.param.pword[7] = my_ctx.program_id;
701
702         sock = socket(AF_INET, SOCK_STREAM, 0);
703         bzero(&svr, sizeof(svr));
704         svr.sin_family = AF_INET;
705         svr.sin_addr.s_addr = INADDR_ANY;
706         svr.sin_port = 0;
707         bind(sock, (struct sockaddr*)&svr, sizeof(svr));
708         listen(sock, 5);
709         len = sizeof(svr);
710         getsockname(sock,(struct sockaddr*)&svr, &len);
711         msg.param.pword[8] = ntohs(svr.sin_port);
712         gethostname(name, &len);
713         info = (struct hostent*)gethostbyname(name);
714         bcopy((char*)info->h_addr, (char*)&svr.sin_addr, info->h_length);
715         sprintf(msg.param.pstr, "%s", inet_ntoa(svr.sin_addr));
716         send_to_kernel(&msg);
717
718         bzero(&svr, sizeof(svr));
719         DirConn[parent_ctx.node] = accept(sock, (struct sockaddr*)&svr, &len);
720         fcntl(DirConn[parent_ctx.node], F_SETFL, O_NONBLOCK |
721                                 fcntl(DirConn[parent_ctx.node], F_GETFL, 0));
722 }
723
724 int main(int argc, char **argv)
725 {
726         /* initialize executor */
727         initiate(argc, argv);
728         /* initialize running system */
729         runsys();
730         init_scheduler();
731         GraphRes = get_graph_res();
732         if (GraphRes < 0)
733                 exit(12);
734
735         request_id();
736         if (remote)
737                 send_ready(); 
738
739         /* set label for continue long jump */
740         setjmp(contenv);
741         /* repeat until exit() is called */
742         while (TRUE) {
743                 get_internal();
744                 /* reschedule current process */
745                 schedule();
746                 if (ready != 0) {
747                         /* fetch instruction */
748                         decode();
749                         /* and execute it */
750                         execute();
751                 }
752         }
753         return 0;
754 }
755