~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to monit/preph.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*===========================================================================
 
2
  Copyright (C) 1995-2010 European Southern Observatory (ESO)
 
3
 
 
4
  This program is free software; you can redistribute it and/or 
 
5
  modify it under the terms of the GNU General Public License as 
 
6
  published by the Free Software Foundation; either version 2 of 
 
7
  the License, or (at your option) any later version.
 
8
 
 
9
  This program is distributed in the hope that it will be useful,
 
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
  GNU General Public License for more details.
 
13
 
 
14
  You should have received a copy of the GNU General Public 
 
15
  License along with this program; if not, write to the Free 
 
16
  Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, 
 
17
  MA 02139, USA.
 
18
 
 
19
  Correspondence concerning ESO-MIDAS should be addressed as follows:
 
20
        Internet e-mail: midas@eso.org
 
21
        Postal address: European Southern Observatory
 
22
                        Data Management Division 
 
23
                        Karl-Schwarzschild-Strasse 2
 
24
                        D 85748 Garching bei Muenchen 
 
25
                        GERMANY
 
26
===========================================================================*/
 
27
 
 
28
/*+++++++++++++++++++ MIDAS monitor routines PREPH +++++++++++++++++++++++++++
 
29
.LANGUAGE  C
 
30
.IDENTIFICATION Module PREPH
 
31
.AUTHOR         K. Banse                        ESO - Garching
 
32
.ENVIRONMENT  VMS and UNIX
 
33
.KEYWORDS
 
34
  MIDAS monitor, process control
 
35
.COMMENTS  
 
36
  holds INPREPA, START_IT, RUN_IT, STOP_IT, DCLOP, ASSIO, DCLDEM, HTERM, 
 
37
        CNTRLC, EXH, intmonit
 
38
 
 
39
.VERSION [1.00]  870710: initial vers. built from FORTRAN v. 4.30 as of 870311
 
40
 
 
41
 100608         last modif
 
42
----------------------------------------------------------------------------*/
 
43
 
 
44
 
 
45
#include <fileexts.h>
 
46
#include <osyparms.h>
 
47
#include <monitdef.h>
 
48
#include <midback.h>
 
49
#include <errno.h>
 
50
#include <oserror.h>
 
51
 
 
52
#include <fsydef.h>
 
53
 
 
54
#include <string.h>
 
55
#include <signal.h>                     /* for symbolic signal names */
 
56
 
 
57
 
 
58
static char      keyfile[200];          /* full name of MID_WORK:FORGRxy.KEY */
 
59
static char      prefix[8];
 
60
 
 
61
#if vms
 
62
static int  ttchan, mbchan;        /* old MONIT.TTCHAN, MONIT.MBCHAN */
 
63
static int   Cintr = 1;
 
64
 
 
65
static char      mbx[12];
 
66
static char      vmsbuf[200];   
 
67
static char      Userterm[20];
 
68
 
 
69
void START_IT();
 
70
#endif
 
71
 
 
72
int hostinfo();
 
73
 
 
74
/*
 
75
 
 
76
*/
 
77
 
 
78
void intmonit()
 
79
 
 
80
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
81
.PURPOSE
 
82
 interrupt routine for Cntrl/C in the monitor
 
83
.ALGORITHM
 
84
 clean up all the stuff from Midas procedures
 
85
.RETURNS
 
86
 nothing
 
87
-----------------------------------------------------------------------*/
 
88
 
 
89
{
 
90
 
 
91
#if vms
 
92
Cintr = 1;
 
93
#endif
 
94
 
 
95
MONIT.CTRLC = 1;                                /* indicate the interrupt */
 
96
osscatch(SIGINT,intmonit);                 /* reenable CntrlC catching */
 
97
 
 
98
}
 
99
 
 
100
/*
 
101
 
 
102
*/
 
103
 
 
104
void INPREPA()
 
105
 
 
106
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
107
.PURPOSE
 
108
  link to the keyword file as a shared data structure
 
109
  set initial values for SYSCOM
 
110
  create subprocess FORGRxy and set up everything what's needed for
 
111
  communicating with that subprocess
 
112
.ALGORITHM
 
113
  create + map global section for keyword file + hold it until
 
114
  PREPA exits
 
115
.RETURNS
 
116
  nothing
 
117
---------------------------------------------------------------------------*/
 
118
 
 
119
{
 
120
int   iwa, mm, kk, stat, fastmem, ibuf[9];
 
121
register int  nr;
 
122
 
 
123
char  cbuf[40];
 
124
extern char DATA_PATH[328];
 
125
 
 
126
 
 
127
 
 
128
fastmem = myINIT(0);    /*  clean FCT and do other stuff like in  SCSPRO */
 
129
 
 
130
 
 
131
/*  init global data  */
 
132
 
 
133
MONIT.LEVEL = 0;
 
134
MONIT.COUNT = 0;
 
135
MONIT.INTERRUPT = 0;
 
136
MONIT.PAUSLEVL = -1;
 
137
MONIT.TOPLEVL = 0;
 
138
MONIT.CROSS_COUNT = 0;
 
139
MONIT.COMPILED = 0;
 
140
ERRORS.STATUS = 0;              /* init low level error status */
 
141
ERRORS.SYS = 0;                 /* and for the Monitor */
 
142
 
 
143
MONIT.CTRLC = 0;
 
144
 
 
145
for (nr=0; nr<MAX_LEVEL; nr++)
 
146
   {
 
147
   MONIT.ECKO[nr] = 0;
 
148
   MONIT.MDEBUG[nr] = 0;
 
149
   MONIT.PDEBUG[nr] = 0;
 
150
   MONIT.PCODE[nr] = 0;
 
151
   MONIT.MXT[nr] = 0;
 
152
   MONIT.ENDT[nr] = 0;
 
153
   TRANSLATE[nr].PNTR[0] = NULL;
 
154
   TRANSLATE[nr].PNTR[1] = NULL;
 
155
   TRANSLATE[nr].LEN[0] = 0;
 
156
   TRANSLATE[nr].LEN[1] = 0;
 
157
   }
 
158
MONIT.MAXTIME = 0;
 
159
MONIT.ECKO[MAX_LEVEL] = 0;
 
160
MONIT.MDEBUG[MAX_LEVEL] = 0;
 
161
MONIT.PDEBUG[MAX_LEVEL] = 0;
 
162
MONIT.PROCESS = -1;                     /* init to no_subprocess  */
 
163
MONIT.CMD_LIST_UPDA = 1;        /* => INITCOM will use update_cmd_list() */
 
164
 
 
165
(void) OSY_TRNLOG("PYMIDAS",cbuf,8,&stat);
 
166
if (strcmp(cbuf,"YES") == 0)            /* check, if this is PyMidas */
 
167
   {
 
168
   MONIT.ENV = 'P';
 
169
   (void) strcpy(FRONT.PROMPT,"*Midas ");
 
170
   FRONT.PEND = 7;
 
171
   }
 
172
else
 
173
   MONIT.ENV = 'N';
 
174
 
 
175
(void) strcpy(BATCH[0].CMND,"IF");      /* same order as in COMPILE !! */
 
176
(void) strcpy(BATCH[1].CMND,"ELSE");
 
177
(void) strcpy(BATCH[2].CMND,"ELSEIF");
 
178
(void) strcpy(BATCH[3].CMND,"ENDIF");
 
179
(void) strcpy(BATCH[4].CMND,"DO");
 
180
(void) strcpy(BATCH[5].CMND,"ENDDO");
 
181
 
 
182
(void) strcpy(PROC.FORMAT,"4.4  18.8 18.8 "); /* init interactive FORMAT */
 
183
        
 
184
FRAMACC('I',KAUX.OUT,0,&iwa);           /* init structure FRAME */
 
185
 
 
186
 
 
187
/*  set error_continue, error_log and error_display flag for the monitor  */
 
188
 
 
189
ERRO_CONT = 1;                          /* continue always  */
 
190
ERRO_LOG = 0;                           /* log nothing      */
 
191
ERRO_DISP = 0;                          /* display nothing  */
 
192
ERRO_INDX = -1;                         /* clear error message pointers  */
 
193
ERRO_OFF = 0;
 
194
 
 
195
 
 
196
/*  initialize CONTEXT structure */
 
197
 
 
198
kk = MAX_CONTXT * 8;
 
199
memset((void *)CONTXT.NAME,32,(size_t)kk);              /* clear context names */
 
200
CONTXT.NAME[kk] = '\0';                 /* make sure we have an end marker */
 
201
CONTXT.STACK = 0;
 
202
CONTXT.BASE = 0;
 
203
for (nr=0; nr<MAX_CONTXT; nr++)
 
204
   {
 
205
   CONTXT.QUEUE[nr] = 0;
 
206
   CONTXT.pdirec[nr] = (char *) 0;
 
207
   }
 
208
 
 
209
 
 
210
/* prepare name of keyword file + open it  */
 
211
 
 
212
stat = OSY_TRNLOG("MID_WORK",keyfile,160,&kk);   /* Decode default directory  */
 
213
if (stat != ERR_NORMAL)
 
214
   {
 
215
   (void) printf("we could not translate MID_WORK or MID_WORK > 160 char.\n\r");
 
216
   ospexit(1);
 
217
   }
 
218
 
 
219
#if vms
 
220
if (keyfile[kk-1] != FSY_DISKEND)
 
221
   {
 
222
   if (keyfile[kk-1] != FSY_DIREND)
 
223
      {
 
224
      keyfile[kk++] = FSY_DIREND;
 
225
      keyfile[kk] = '\0';
 
226
      }
 
227
   }
 
228
#else
 
229
if (keyfile[kk-1] != FSY_DIREND)
 
230
   {
 
231
   keyfile[kk++] = FSY_DIREND;
 
232
   keyfile[kk] = '\0';
 
233
   }
 
234
#endif
 
235
 
 
236
(void) strcpy(FRONT.STARTUP,keyfile);   /* save name of startup directory */
 
237
(void) strcpy(CPATH[0].STR,keyfile);            /* also in CPATH[0] */
 
238
(void) strcpy(EPATH[0].STR,keyfile);            /* also in EPATH[0] */
 
239
for (nr=1; nr<4; nr++)
 
240
   {
 
241
   CPATH[nr].STR[0] = '\0';                     /* mark the end */
 
242
   EPATH[nr].STR[0] = '\0';                     /* mark the end */
 
243
   }
 
244
 
 
245
 
 
246
/*  get foreground keys in  */
 
247
 
 
248
if (FRONT.ENV == '*')                   /* Unix command line input */
 
249
   stat = MID_MOVKEY("IM","**");
 
250
else
 
251
   {
 
252
   (void) strcpy(&keyfile[kk],"FORGR  .KEY");
 
253
   keyfile[kk+5] = FRONT.DAZUNIT[0];
 
254
   keyfile[kk+6] = FRONT.DAZUNIT[1];
 
255
   stat = MID_MOVKEY("IM",keyfile);
 
256
   }
 
257
if (stat != ERR_NORMAL) ospexit(1);
 
258
 
 
259
stat = MID_LOG('I',FRONT.DAZUNIT,2);            /* open the logfile  */
 
260
if (stat != ERR_NORMAL)
 
261
   {
 
262
   (void) strcpy(cbuf,"INPREPA/MID_LOG:");
 
263
   MID_ERROR("MIDAS",cbuf,stat,1);
 
264
   }
 
265
 
 
266
(void) strcpy(prefix,"FORGR  ");                /* will be used in DCLOP() */
 
267
prefix[5] = FRONT.DAZUNIT[0];
 
268
prefix[6] = FRONT.DAZUNIT[1];
 
269
 
 
270
 
 
271
/* save offsets for keys P1,...,P8  +  Q1, Q2, Q3 */
 
272
 
 
273
MONIT.POFF[0] = OFF_P1;
 
274
MONIT.POFF[1] = OFF_P2;
 
275
MONIT.POFF[2] = OFF_P3;
 
276
MONIT.POFF[3] = OFF_P4;
 
277
MONIT.POFF[4] = OFF_P5;
 
278
MONIT.POFF[5] = OFF_P6;
 
279
MONIT.POFF[6] = OFF_P7;
 
280
MONIT.POFF[7] = OFF_P8;
 
281
MONIT.POFF[8] = OFF_Q1;
 
282
MONIT.POFF[9] = OFF_Q2;
 
283
MONIT.POFF[10] = OFF_Q3;
 
284
        
 
285
KIWORDS[OFF_OUTFLG] = 99;                       /* init keyword OUT$FLAG */
 
286
KIWORDS[OFF_OUTFLG+2] = -1;
 
287
(void) strcpy(&KCWORDS[OFF_OUTNAM]," yyy");
 
288
 
 
289
KIWORDS[OFF_MODE+6] = 0;                /* reset overall program level  */
 
290
KIWORDS[OFF_MONPAR+2] = KEY_MAXENT;     /* store no. of global + local keys */ 
 
291
KIWORDS[OFF_MONPAR+3] = LOC_MAXENT;
 
292
KIWORDS[OFF_MONPAR+18] = fastmem;       /* save FASTMEM option */
 
293
if (fastmem != 0)
 
294
   KIWORDS[OFF_MONPAR+19] = 2000;       /* set MP(20) = 4000 */
 
295
 
 
296
/* indicate if we're executed from PyMidas */
 
297
if (MONIT.ENV == 'P')
 
298
   {                                    /* indicate PyMidas in MID$SESS */
 
299
   KCWORDS[OFF_SESS+27] = 'P';
 
300
   KCWORDS[OFF_SESS+28] = 'Y';
 
301
   KCWORDS[OFF_SESS+29] = ' ';
 
302
   }
 
303
else
 
304
   {                    
 
305
   KCWORDS[OFF_SESS+27] = KCWORDS[OFF_SESS+28] = KCWORDS[OFF_SESS+29] = ' ';
 
306
   }
 
307
 
 
308
/* initialize  keyword DATA_PATH */
 
309
memset((void *)&KCWORDS[OFF_DPATH],32,(size_t)319);
 
310
for (nr=0; nr<320; nr+=80) KCWORDS[OFF_DPATH+nr] = '^';
 
311
KCWORDS[OFF_DPATH+319] = '\0';
 
312
(void) strcpy(DATA_PATH,&KCWORDS[OFF_DPATH]);   /* copy also to DATA_PATH */
 
313
 
 
314
        
 
315
PIPE.CONT[0] = '\0';                    /* clear PIPE(line) structure */
 
316
PIPE.EXE[0] = '\0'; 
 
317
PIPE.PROC[0] = '\0'; 
 
318
PIPE.INSTRUM[0] = '\0'; 
 
319
 
 
320
for (nr=0; nr<5; nr++)                  /* clear REDIRECT structure  */
 
321
   REDIRECT[nr].OUTFLAG[0] = 99;
 
322
 
 
323
 
 
324
/*  clear default definitions + open file internal.cod  */
 
325
 
 
326
(void) PARDEFS('I'," ");
 
327
(void) INTERNAL("OPEN","COD",&mm);
 
328
        
 
329
 
 
330
if (KIWORDS[OFF_MODE] == 1 )
 
331
   mm = hostinfo(1,ibuf,cbuf,cbuf+16,cbuf+28);
 
332
else
 
333
   mm = hostinfo(0,ibuf,cbuf,cbuf+16,cbuf+28);
 
334
 
 
335
 
 
336
/*****************  VMS  ***********************/
 
337
 
 
338
#if vms
 
339
 
 
340
/*  get channel no. of user ASCII terminal and initialize terminal mode  */
 
341
(void) OSY_TRNLOG("TT",Userterm,19,&kk);        /* Decode terminal name  */
 
342
(void) OSY_ASSIGN("TT",2,&ttchan);              /* as used in main process! */
 
343
        
 
344
KAUX.DCLINP = 0;
 
345
START_IT();                             /* start up foreground process  */
 
346
 
 
347
#endif
 
348
 
 
349
/***********************************************/
 
350
        
 
351
 
 
352
 
 
353
osscatch(SIGINT,intmonit);      /* set up Control/C interrupt handler */
 
354
}
 
355
 
 
356
/*
 
357
 
 
358
*/
 
359
 
 
360
#if vms
 
361
 
 
362
void START_IT()
 
363
 
 
364
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
365
.PURPOSE
 
366
  create subprocess FORGRxy
 
367
  and set up everything what's needed for communicating with that subprocess
 
368
.ALGORITHM
 
369
  use lots of system service calls
 
370
.RETURNS
 
371
  nothing
 
372
-----------------------------------------------------------------------*/
 
373
 
 
374
{
 
375
char    eqn[2][20], cbuf[200];
 
376
        
 
377
int   stat, mm, pid;
 
378
int   DCLDEM(), HTERM(), EXH();         /* external functions  */
 
379
 
 
380
 
 
381
stat = OSY_DCLEXH(EXH);                 /* declare exit handler  */
 
382
if (stat != ERR_NORMAL)
 
383
   {
 
384
   printf("problems with exit handler/event_flag clearing...\n\r");
 
385
   ospexit(1);
 
386
   }
 
387
        
 
388
 
 
389
/*  Create mailboxes for DCL commands to foreground processes  */
 
390
 
 
391
(void) strcpy(mbx,"FORGR  _IN");
 
392
mbx[5] = FRONT.DAZUNIT[0];
 
393
mbx[6] = FRONT.DAZUNIT[1];
 
394
 
 
395
stat = OSY_CREMBX(mbx,&mbchan);
 
396
if (stat != ERR_NORMAL)
 
397
   {
 
398
   (void) printf("problems with mailbox creation...\n\r");
 
399
   ospexit(1);
 
400
   }
 
401
 
 
402
stat = OSY_TRNLOG(mbx,&eqn[0][0],20,&mm);           /* get equivalence name  */
 
403
if (stat != ERR_NORMAL)
 
404
   {
 
405
   (void) printf("could not translate mailbox %s ...\n\r",mbx);
 
406
   ospexit(1);
 
407
   }
 
408
else
 
409
   eqn[0][mm] = '\0';
 
410
 
 
411
        
 
412
MONIT.PROCESS = 0;
 
413
 
 
414
 
 
415
/*  Enable AST for subprocess's first DCL input request   */
 
416
 
 
417
 
 
418
stat = OSY_ENAST(mbchan,"READATT",DCLDEM,0);
 
419
if (stat != ERR_NORMAL)
 
420
   {
 
421
   (void) printf("could not enable AST for mailbox, status = %x \n\r",stat);
 
422
   ospexit(1);
 
423
   }
 
424
        
 
425
/*  Create subprocess                                        */
 
426
 
 
427
mbx[7] = '\0';                  /* that's already the process name */
 
428
stat = OSY_SPAWN(&eqn[0][0],mbx,Userterm,&pid,HTERM,&mm); 
 
429
MONIT.PID = pid;
 
430
        
 
431
if (stat != ERR_NORMAL)
 
432
   {
 
433
   (void) printf("could not spawn subprocess - delete old FORGRxy process\n\r");
 
434
   ospexit(1);
 
435
   }
 
436
   
 
437
 
 
438
/* Hibernate until something happens  */
 
439
 
 
440
stat = OSY_HIBER();
 
441
if (stat != ERR_NORMAL)
 
442
   {
 
443
   (void) printf("problems with hibernating call, status = %x \n\r",stat);
 
444
   ospexit(1);
 
445
   }
 
446
  
 
447
 
 
448
/*  --- we only get here after having been woken up by the subprocess ---  */
 
449
 
 
450
        
 
451
sect_1000:
 
452
 
 
453
if (MONIT.PROCESS != 1 )                /* has the subprocess died?  */
 
454
   {
 
455
   (void) printf(" subprocess %s has died...\n\r",mbx);
 
456
   ospexit(1);
 
457
   }
 
458
 
 
459
        
 
460
/*  Make subprocess assignments at user level  */
 
461
 
 
462
(void) strcpy(vmsbuf,Userterm);
 
463
ASSIO(vmsbuf,vmsbuf);
 
464
        
 
465
}
 
466
 
 
467
/*
 
468
 
 
469
*/
 
470
 
 
471
void RUN_IT(image)
 
472
        
 
473
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
474
.PURPOSE
 
475
  run given image in a subprocess
 
476
.ALGORITHM
 
477
  enable CNTRL/C AST to terminate a foreground process
 
478
.RETURNS
 
479
  nothing
 
480
---------------------------------------------------------------------*/
 
481
 
 
482
char    *image   /*IN: image to be executed in the subprocess  */;
 
483
 
 
484
{
 
485
char    *dclpntr;
 
486
 
 
487
int   stat, mm, kk;
 
488
int   DCLDEM(), CNTRLC();
 
489
 
 
490
 
 
491
/*  Enable CTRL/C AST only for interactive foreground process  */
 
492
 
 
493
if (Cintr > 0)
 
494
   {
 
495
   if (KIWORDS[OFF_MODE+2] != 1)
 
496
     {
 
497
     mm = 0;
 
498
     stat = OSY_ENAST(ttchan,"CNTRLC",CNTRLC,0);
 
499
     if (stat != ERR_NORMAL)
 
500
        {
 
501
        (void) printf("could not enable AST for CNTRL_C, status = %x\n\r",stat);
 
502
        ospexit(1);
 
503
        }
 
504
      }
 
505
   MONIT.CTRLC = 0;                     /* just for compatibility */
 
506
 
 
507
   Cintr = 0;
 
508
   }
 
509
 
 
510
 
 
511
/*  check, that subprocess has not died   */
 
512
 
 
513
if (MONIT.PROCESS < 0)
 
514
   {
 
515
   (void) printf("RUN_IT: subprocess %s has died...\n\r",mbx);
 
516
   ospexit(1);
 
517
   }
 
518
 
 
519
 
 
520
/* image name or host opsys command?  */
 
521
 
 
522
if (*image == '$')
 
523
   {
 
524
   MONIT.PROCESS = 2;           /* host opsys command: set flag  */
 
525
   dclpntr = image;
 
526
   if (CGN_INDEXC(dclpntr,'@') > 0) KAUX.DCLINP = 1;
 
527
   }
 
528
else
 
529
   {
 
530
   MONIT.PROCESS = 3;   /* image: set flag + construct RUN command  */
 
531
   dclpntr = vmsbuf;
 
532
   if (MONIT.MDEBUG[MONIT.LEVEL] != 0)
 
533
      {
 
534
      if (MONIT.MDEBUG[MONIT.LEVEL] == 2)
 
535
         {
 
536
         (void) strcpy(dclpntr,"$RUN/DEBUG ");          /* with debugger */
 
537
         (void) strcpy(dclpntr+11,image);
 
538
         }
 
539
      else                                      /* get the current time first */
 
540
         {
 
541
         (void) sprintf(vmsbuf,"before %s",image);
 
542
         SCTPUT(vmsbuf);
 
543
         OSY_ASCTIM(vmsbuf);
 
544
         SCTPUT(vmsbuf);
 
545
         (void) strcpy(dclpntr,"$RUN/NODEBUG ");        /* without debugger */
 
546
         (void) strcpy(dclpntr+13,image);
 
547
         MONIT.PROCESS = 9;
 
548
         }
 
549
      }
 
550
   else
 
551
      {
 
552
      (void) strcpy(dclpntr,"$RUN/NODEBUG ");           /* without debugger */
 
553
      (void) strcpy(dclpntr+13,image);
 
554
      }
 
555
 
 
556
   /* write keywords out + command string into mailbox */
 
557
 
 
558
   fixout(1,MONIT.LEVEL);                       /* close any ASCII out file */
 
559
   (void) MID_LOG('O',LINE.STR,2);              /* close logfile */
 
560
   (void) MID_MOVKEY("O",vmsbuf);               /* write keywords out  */
 
561
   }
 
562
        
 
563
 
 
564
DCLOP(dclpntr);
 
565
        
 
566
 
 
567
/* Enable AST for PREPA -> PROCESS mailbox read demand  */
 
568
 
 
569
stat = OSY_ENAST(mbchan,"READATT",DCLDEM,0);
 
570
if (stat != ERR_NORMAL)
 
571
   {
 
572
   (void) printf("could not enable AST for READATT, status = %x\n\r",stat);
 
573
   ospexit(1);
 
574
   }
 
575
 
 
576
        
 
577
/*  hibernate until something happens  */
 
578
 
 
579
stat = OSY_HIBER();
 
580
if (stat != ERR_NORMAL)
 
581
   {
 
582
   (void) printf("problems with hibernating call, status = %x\n\r",stat);
 
583
   ospexit(1);
 
584
   }
 
585
 
 
586
        
 
587
/*  --- we only get here after having been woken up by the subprocess ---   */
 
588
 
 
589
        
 
590
sect_1000:
 
591
 
 
592
if (MONIT.PROCESS >= 3)
 
593
   {
 
594
   (void) strcpy(vmsbuf,FRONT.STARTUP);    /* get name of startup directory */
 
595
   kk = strlen(vmsbuf);
 
596
   (void) strcpy(&vmsbuf[kk],"FORGR  .KEY");
 
597
   vmsbuf[kk+5] = FRONT.DAZUNIT[0];
 
598
   vmsbuf[kk+6] = FRONT.DAZUNIT[1];
 
599
   (void) MID_MOVKEY("IM",vmsbuf);              /* get keywords back  */
 
600
   (void) MID_LOG('I',FRONT.DAZUNIT,2);         /* open logfile again  */
 
601
 
 
602
   if (MONIT.PROCESS == 9)              /* get current time after execution */
 
603
      {
 
604
      (void) sprintf(vmsbuf,"after %s",image);
 
605
      SCTPUT(vmsbuf);
 
606
      OSY_ASCTIM(vmsbuf);
 
607
      SCTPUT(vmsbuf);
 
608
      }
 
609
   }
 
610
}
 
611
 
 
612
/*
 
613
 
 
614
*/
 
615
 
 
616
STOP_IT()
 
617
        
 
618
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
619
.PURPOSE
 
620
  kill foreground subprocess;
 
621
.ALGORITHM
 
622
  PID is stored in MONIT.PID - use system service calls
 
623
.RETURNS
 
624
  nothing
 
625
----------------------------------------------------------------*/
 
626
 
 
627
{
 
628
int  stat;
 
629
 
 
630
 
 
631
/*  flush terminal I/O + delete process  */
 
632
 
 
633
(void) OSY_CANCEL(ttchan);
 
634
        
 
635
if (MONIT.PROCESS != -1)
 
636
   {
 
637
   stat = OSY_DELPRC(&MONIT.PID);       /* try to abort foreground process */
 
638
   if (stat != ERR_NORMAL)
 
639
      (void) printf("problems with process deletion, status = %x\n\r",stat);
 
640
   MONIT.PROCESS = -1;
 
641
   }
 
642
        
 
643
}
 
644
 
 
645
/*
 
646
 
 
647
*/
 
648
 
 
649
ASSIO(indev,outdev)
 
650
 
 
651
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
652
.PURPOSE
 
653
  assign the standard I/O streams for subprocess
 
654
.ALGORITHM
 
655
  use DCLOP to pass "$ASSIGN commands" to the subprocess
 
656
.RETURNS
 
657
  nothing
 
658
--------------------------------------------------------------------*/
 
659
        
 
660
char    *indev  /*IN: point to input device (with '\0')  */;
 
661
char    *outdev /*OUT: output device (with '\0')  */;
 
662
 
 
663
{
 
664
int  mm;
 
665
        
 
666
char    work[60];
 
667
 
 
668
        
 
669
DCLOP("$SET NOVERIFY");         /* Switch off verify in subprocess */
 
670
 
 
671
DCLOP("$SET NOON");             /* Prevent error exit  */
 
672
 
 
673
(void) strcpy(work,"$ASSIGN ");
 
674
(void) strcpy(&work[8],indev);
 
675
mm = strlen(work);
 
676
 
 
677
(void) strcpy(&work[mm]," SYS$COMMAND");        /* $ASSIGN indev SYS$COMMAND */
 
678
DCLOP(work);
 
679
(void) strcpy(&work[mm]," SYS$INPUT");          /* $ASSIGN indev SYS$INPUT  */
 
680
DCLOP(work);
 
681
(void) strcpy(&work[mm]," FOR$READ");           /* $ASSIGN indev FOR$READ  */
 
682
DCLOP(work);
 
683
(void) strcpy(&work[mm]," DBG$INPUT");          /* $ASSIGN indev DBG$INPUT  */
 
684
DCLOP(work);
 
685
(void) strcpy(&work[mm]," TT");         /*  $ASSIGN indev SYS$COMMAND  */
 
686
DCLOP(work);
 
687
 
 
688
(void) strcpy(&work[8],outdev);
 
689
mm = strlen(work);
 
690
(void) strcpy(&work[mm]," SYS$OUTPUT"); /*  $ASSIGN outdev SYS$OUTPUT  */
 
691
DCLOP(work);
 
692
        
 
693
}
 
694
 
 
695
/*
 
696
 
 
697
*/
 
698
 
 
699
DCLDEM()
 
700
 
 
701
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
702
.PURPOSE
 
703
  service AST when subprocess requests next DCL command
 
704
.ALGORITHM
 
705
  wake up main process
 
706
.RETURNS
 
707
  nothing
 
708
---------------------------------------------------------------*/
 
709
 
 
710
{
 
711
int  stat;
 
712
 
 
713
 
 
714
/*  If first time, set subprocess status = created  */
 
715
 
 
716
if (MONIT.PROCESS == 0) MONIT.PROCESS = 1;
 
717
 
 
718
        
 
719
/* Wake the main process */
 
720
 
 
721
stat = OSY_WAKE();
 
722
if (stat != ERR_NORMAL)
 
723
   ospexit(1);
 
724
        
 
725
 
 
726
/*  for host (DCL) commands we may have to reset SYS$INPUT...  */
 
727
 
 
728
if (KAUX.DCLINP == 1)
 
729
   {
 
730
   KAUX.DCLINP = 0;
 
731
   (void) strcpy(vmsbuf,"$ASSIGN ");
 
732
   (void) strcpy(&vmsbuf[8],Userterm);
 
733
   (void) strcat(vmsbuf," SYS$INPUT");
 
734
   DCLOP(vmsbuf);
 
735
   }
 
736
        
 
737
}
 
738
 
 
739
/*
 
740
 
 
741
*/
 
742
 
 
743
HTERM()
 
744
 
 
745
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
746
.PURPOSE
 
747
  service AST when subprocess terminates
 
748
.ALGORITHM
 
749
  wake up main process 
 
750
.RETURNS
 
751
  nothing
 
752
------------------------------------------------------------------*/
 
753
 
 
754
{
 
755
int  stat;
 
756
 
 
757
/*  Set the process status flag   */
 
758
 
 
759
MONIT.PROCESS = -1;
 
760
        
 
761
/*  Wake the main process if hibernating */
 
762
 
 
763
stat = OSY_WAKE();
 
764
 
 
765
if (stat != ERR_NORMAL)
 
766
   ospexit(1);
 
767
        
 
768
}
 
769
 
 
770
/*
 
771
 
 
772
*/
 
773
 
 
774
EXH(stat)
 
775
 
 
776
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
777
.PURPOSE
 
778
  kill subprocesses on forced exit of main process
 
779
.ALGORITHM
 
780
  will be called as EXH(stat) when main process crashes
 
781
  use OSY_DELPRC
 
782
.RETURNS
 
783
  nothing
 
784
------------------------------------------------------------------*/
 
785
 
 
786
int   *stat   /* IN:    status of exit  */;
 
787
 
 
788
{       
 
789
 
 
790
/*  Last chance to get rid of subprocesses  */
 
791
 
 
792
if (MONIT.PROCESS != -1)
 
793
   {
 
794
   *stat = OSY_DELPRC(&MONIT.PID);
 
795
   MONIT.PROCESS = -1;
 
796
   }
 
797
        
 
798
if (KIWORDS[OFF_AUX+7] == 1) ostraw(0);
 
799
 
 
800
}
 
801
 
 
802
/*
 
803
 
 
804
*/
 
805
 
 
806
DCLOP(dcl)
 
807
 
 
808
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
809
.PURPOSE
 
810
  pass DCL input to subprocess via mailbox
 
811
.ALGORITHM
 
812
  get mailbox from keyword CHANNEL + use system service calls
 
813
.RETURNS
 
814
  nothing
 
815
-------------------------------------------------------------------------*/
 
816
 
 
817
char    *dcl    /* IN: pointer to host command (terminated by '\0')  */;
 
818
 
 
819
 
 
820
{
 
821
int  stat;
 
822
 
 
823
 
 
824
/*  Write DCL command to mailbox  */
 
825
 
 
826
stat = OSY_WRCHAN(mbchan,dcl,(int)strlen(dcl));
 
827
 
 
828
if (stat != ERR_NORMAL) 
 
829
   {
 
830
   if (strncmp(dcl,"$RUN",4) == 0)
 
831
      {
 
832
      char  string[160];
 
833
      int   nr, m;
 
834
 
 
835
      for (nr=0; nr<4; nr++)
 
836
         {
 
837
         if (EPATH[nr].STR[0] == '\0') break;
 
838
 
 
839
         m = CGN_COPY(string,EPATH[nr].STR);
 
840
         (void) strcpy(&string[m],dcl);
 
841
         stat = OSY_WRCHAN(mbchan,string,(int)strlen(string));
 
842
         if (stat == ERR_NORMAL) return;
 
843
         }
 
844
      }
 
845
   (void) printf("problems with OSY_WRCHAN of %s ...\n\r",dcl);
 
846
   }
 
847
 
 
848
}
 
849
 
 
850
/*
 
851
 
 
852
*/
 
853
 
 
854
CNTRLC()
 
855
 
 
856
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
857
.PURPOSE
 
858
  AST routine for CTRL/C
 
859
.ALGORITHM
 
860
  reset any procedure level, clear local keys + force exit of image in subproce
 
861
.RETURNS
 
862
  nothing
 
863
-----------------------------------------------------------------------*/
 
864
        
 
865
{
 
866
int  stat;
 
867
 
 
868
 
 
869
/* proceed unless subprocess isn't running a job  */
 
870
 
 
871
(void) strcpy(vmsbuf,"FORGR  ");
 
872
vmsbuf[5] = FRONT.DAZUNIT[0];
 
873
vmsbuf[6] = FRONT.DAZUNIT[1];
 
874
 
 
875
stat = OSY_FORCEX(vmsbuf);
 
876
if (stat != ERR_NORMAL) ospexit(1);
 
877
 
 
878
MONIT.CTRLC = 1;                                /* indicate the interrupt */
 
879
Cintr = 1;
 
880
 
 
881
}
 
882
 
 
883
/*
 
884
 
 
885
*/
 
886
 
 
887
#else                                   /* Unix part */
 
888
 
 
889
void RUN_IT(image)
 
890
        
 
891
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
892
.PURPOSE
 
893
  run given image in a subprocess
 
894
.ALGORITHM
 
895
  enable CNTRL/C AST to terminate a foreground process
 
896
.RETURNS
 
897
  nothing
 
898
---------------------------------------------------------------------*/
 
899
 
 
900
char    *image          /*IN: image to be executed in the subprocess  */;
 
901
 
 
902
{
 
903
int  kk, exec_stat;
 
904
long int   oshtime(), startsecs, elapsed;
 
905
 
 
906
char  cbuf[240], *cptr;
 
907
 
 
908
 
 
909
 
 
910
 
 
911
startsecs = 0L;
 
912
 
 
913
/* image name or host opsys command?  */
 
914
 
 
915
if (*image == '$')
 
916
   {
 
917
   MONIT.PROCESS = 2;                /* host opsys command: set flag  */
 
918
   exec_stat = DCLOP(image);
 
919
   }
 
920
 
 
921
else
 
922
   {
 
923
   MONIT.PROCESS = 3;  /* image name: set flag + prepare execution of image */
 
924
 
 
925
   if (MONIT.MDEBUG[MONIT.LEVEL] != 0)
 
926
      {
 
927
      if (MONIT.MDEBUG[MONIT.LEVEL] == 2)       /* we use the debugger */
 
928
         {
 
929
         int  uni, nulo, iav;
 
930
         register int  nr;
 
931
         char debugflags[42], debugopt[42];
 
932
 
 
933
         nulo = -1;
 
934
         cptr = cbuf + 1;                       /* have one byte in front */
 
935
         SCKRDC("MID$DEBUG",40,1,1,&iav,cptr,&uni,&nulo);
 
936
         cbuf[0] = '_';
 
937
         cbuf[40] = ' ';
 
938
         kk = CGN_INDEXC(cbuf,' ');
 
939
         cbuf[++kk] = '\0';
 
940
         if (cbuf[1] != '$')            /* debugger runs in host OS */
 
941
            {
 
942
            cbuf[0] = '$';
 
943
            cptr = cbuf;
 
944
            }
 
945
         SCKRDC("MID$DEBUG",40,2,1,&iav,debugflags,&uni,&nulo);
 
946
         SCKRDC("MID$DEBUG",40,3,1,&iav,debugopt,&uni,&nulo);
 
947
         if (debugflags[0] != '?')
 
948
            {
 
949
            for (nr=39; nr>0; nr--)
 
950
               {
 
951
               if (debugflags[nr] != ' ') break;
 
952
               }
 
953
            debugflags[++nr] = ' ';
 
954
            debugflags[++nr] = '\0';
 
955
            (void) strcat(cptr,debugflags);
 
956
            }
 
957
         (void) strcat(cptr,image);
 
958
         if (debugopt[0] != '?')
 
959
            {
 
960
            for (nr=39; nr>0; nr--)
 
961
               {
 
962
               if (debugopt[nr] != ' ') break;
 
963
               }
 
964
            debugopt[nr+1] = '\0';
 
965
            (void) strcat(cptr,"  ");
 
966
            (void) strcat(cptr,debugopt);
 
967
            }
 
968
         image = cptr;
 
969
         MONIT.PROCESS = 8;
 
970
         }
 
971
      else                              /* get the current time first */
 
972
         {
 
973
         startsecs = oshtime();
 
974
         MONIT.PROCESS = 9;
 
975
         }
 
976
      }
 
977
 
 
978
   /* close logfile + write keywords out  */
 
979
 
 
980
   fixout(1,MONIT.LEVEL);                       /* close any ASCII out file */
 
981
   (void) MID_LOG('O',LINE.STR,2);              /* close logfile */
 
982
   (void) MID_MOVKEY("O",cbuf);                 /* write keywords out  */
 
983
 
 
984
                                        /* printf("image = %s\n",image); */
 
985
   exec_stat = DCLOP(image);
 
986
 
 
987
   /*  on return from subprocess move keyword stuff back in */
 
988
 
 
989
   if (FRONT.ENV == '*')                /* from Unix command line */
 
990
      (void) MID_MOVKEY("IM","**");     /* get keywords back in */
 
991
   else
 
992
      (void) MID_MOVKEY("IM",keyfile);  /* inside Midas */
 
993
 
 
994
   (void) MID_LOG('I',FRONT.DAZUNIT,2);               /* open logfile again */
 
995
 
 
996
   if (MONIT.PROCESS >= 8)              /* special treatment? */
 
997
      {
 
998
      if (MONIT.PROCESS == 9)           /* get current time after execution */
 
999
         {
 
1000
         elapsed = oshtime();
 
1001
         elapsed -= startsecs;
 
1002
         (void) sprintf(cbuf,"elapsed time: %ld secs for %s",elapsed,image);
 
1003
         SCTPUT(cbuf);
 
1004
         }
 
1005
      else
 
1006
         return;
 
1007
      }
 
1008
   }
 
1009
 
 
1010
if (exec_stat != ERR_NORMAL)            /* now we can also log */
 
1011
   {                                    /* errors from the execution */
 
1012
   if (exec_stat == ERR_OPSSYS) 
 
1013
      {
 
1014
      char  *mypr, *osmsg();
 
1015
 
 
1016
      mypr = osmsg();
 
1017
      (void) sprintf(KAUX.OUT,"(ERR) Problems in executing %s",image);
 
1018
      SCTPUT(KAUX.OUT); 
 
1019
      SCTPUT(mypr);
 
1020
      kk = 888;
 
1021
      }
 
1022
   else                                 /* ERR_INPINV for timeout */
 
1023
      {
 
1024
      (void) sprintf(KAUX.OUT,"(ERR) %s timed out (%d seconds)",
 
1025
                     image,MONIT.MAXTIME);
 
1026
      SCTPUT(KAUX.OUT);
 
1027
      kk = 998;
 
1028
      }
 
1029
 
 
1030
   KIWORDS[OFF_PRSTAT] = kk;            /* store status and error source */
 
1031
   KIWORDS[OFF_PRSTAT+1] = 100;         /* into key PROGSTAT */
 
1032
   }
 
1033
        
 
1034
}
 
1035
 
 
1036
/*
 
1037
 
 
1038
*/
 
1039
 
 
1040
int DCLOP(dcl)
 
1041
 
 
1042
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
1043
.PURPOSE
 
1044
  start up subprocess to run executable
 
1045
.ALGORITHM
 
1046
  use system service
 
1047
.RETURNS
 
1048
  nothing
 
1049
-------------------------------------------------------------------------*/
 
1050
 
 
1051
char    *dcl    /* IN: pointer to host command (terminated by '\0')  */;
 
1052
 
 
1053
{
 
1054
int   pid, maxtime, stat;
 
1055
 
 
1056
 
 
1057
 
 
1058
 
 
1059
maxtime = MONIT.MXT[MONIT.LEVEL];
 
1060
if ((maxtime > 0) && (MONIT.LEVEL > 0))
 
1061
   {
 
1062
   long int   oshtime();
 
1063
 
 
1064
   maxtime = (int) (MONIT.ENDT[MONIT.LEVEL] - oshtime());
 
1065
   if (maxtime < 1) return (ERR_INPINV);
 
1066
   }
 
1067
 
 
1068
stat = OSY_SPAWN(0,dcl,prefix,maxtime,&pid);
 
1069
 
 
1070
if (MONIT.PROCESS == 2) 
 
1071
   {
 
1072
   KIWORDS[OFF_AUX+16] = stat;          /* host return status => AUX_MODE(17) */
 
1073
   stat = ERR_NORMAL;
 
1074
   }
 
1075
else
 
1076
   {
 
1077
   if ( (stat != ERR_NORMAL) && (oserror == ENOENT) )
 
1078
      {
 
1079
      char  string[160];
 
1080
      int   nr, m;
 
1081
 
 
1082
      for (nr=0; nr<4; nr++)
 
1083
         {
 
1084
         if (EPATH[nr].STR[0] != '\0') 
 
1085
            {
 
1086
            m = CGN_COPY(string,EPATH[nr].STR);
 
1087
            (void) strcpy(&string[m],dcl);
 
1088
            if ((stat = OSY_SPAWN(0,string,prefix,maxtime,&pid)) == ERR_NORMAL)
 
1089
               break;
 
1090
            }
 
1091
         }
 
1092
      }
 
1093
   }
 
1094
 
 
1095
MONIT.PID = pid;
 
1096
return (stat);
 
1097
}
 
1098
 
 
1099
 
 
1100
#endif
 
1101