1
/*===========================================================================
2
Copyright (C) 1995-2010 European Southern Observatory (ESO)
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.
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.
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,
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
26
===========================================================================*/
28
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
.IDENT MIDAS Monitor module prepz2.c
33
MIDAS monitor, process control
35
holds hostinfo, ospsysinfo, pipe_mess
39
-----------------------------------------------------------------------------*/
52
#include <sys/utsname.h>
61
/* hostinfo: return useful system info */
63
int hostinfo(prf,sizes,node,mach,opsys)
65
int prf; /* IN: print flag (1 = yes) */
66
int *sizes; /* OUT: 7 elements to get size of
67
short int, int, long int,
69
pointer, off_t, size_t */
71
char *node; /* OUT: name of computer */
72
char *mach; /* OUT: machine architecture */
73
char *opsys; /* OUT: host system */
79
unsigned long int ulm;
90
char *workdir, filename[132], cbuf[144], myunit[4];
93
struct utsname *sysbuf;
101
*(sizes+1) = sizeof(m);
102
*(sizes+2) = sizeof(lm);
103
*(sizes+3) = sizeof(ulm);
104
*(sizes+4) = sizeof(f);
105
*(sizes+5) = sizeof(d);
106
*(sizes+6) = svp = sizeof(vp);
107
*(sizes+7) = sst = sizeof(t);
108
*(sizes+8) = sizeof(offset);
112
KCWORDS[OFF_SYS+30] = '3';
113
KCWORDS[OFF_SYS+31] = '2';
117
KCWORDS[OFF_SYS+30] = '6';
118
KCWORDS[OFF_SYS+31] = '4';
120
m = OFF_AUX + 18; /* point to AUX_MODE(19) */
121
KIWORDS[m++] = sst * 8; /* 32 or 64 */
123
t = (size_t) pow((double)2,(double)(31)); /* store in AUX_MODE(20) */
124
KIWORDS[m] = (int) (t - 1); /* max signed int */
128
printf("size of short int = %d, int = %d (bytes)\n",*sizes,*(sizes+1));
129
printf("size of long int = %d, unsigned long int = %d (bytes)\n",
130
*(sizes+2),*(sizes+3));
131
printf("size of float = %d, double = %d (bytes)\n",*(sizes+4),*(sizes+5));
132
printf("size of pointer = %d, size_t = %d, off_t = %d (bytes)\n",
133
svp,*(sizes+7),*(sizes+8));
137
/* get machine hardware name + host system
138
using the uname() system call leads to segfault on Fedora 6
139
and also strange behaviour on Suse 11.1 ...
140
so we do it via: $ uname -mo > file */
142
#if !defined(__APPLE__)
143
(void) strcpy(cbuf,"uname -nmo > ");
144
#else /* 'uname -o' not on Mac ... */
145
(void) strcpy(cbuf,"uname -nma > ");
148
if (!(workdir = getenv("MID_WORK")))
150
if (!(workdir = getenv("HOME"))) return (-1);
152
(void) strcpy(filename,workdir);
153
(void) strcat(filename,"/midwork");
156
(void) strcpy(filename,workdir);
158
myunit[0] = FRONT.DAZUNIT[0];
159
myunit[1] = FRONT.DAZUNIT[1];
161
(void) strcat(filename,"/Midas_info");
162
(void) strcat(filename,myunit); /* filename: $MID_WORK/Midas_infoXY */
164
(void) strcat(cbuf,filename);
165
(void) system((const char *)cbuf); /* execute the $uname command */
167
fid = osaopen(filename,READ);
168
if (fid < 0) return (-1);
170
m = osaread(fid,cbuf,40);
172
if (m < 0) return (-1); /* could not read the file... */
174
m = CGN_INDEXC(cbuf,' '); /* we should have the string: */
175
if (m < 0) return (-1); /* "node mach opsys" */
178
(void) strcpy(node,cbuf);
179
CGN_strcpy(cbuf,cbuf+m+1);
181
m = CGN_INDEXC(cbuf,' ');
182
if (m < 0) return (-1);
185
(void) strcpy(mach,cbuf);
186
(void) strcpy(opsys,cbuf+m+1);
190
printf("name: %s\n",node);
191
printf("architecture: %s\n",mach);
192
printf("hostsys: %s (%c%c bit)\n",opsys,
193
KCWORDS[OFF_SYS+30],KCWORDS[OFF_SYS+31]);
200
/* here is the code which fails on some Linux systems...
206
(void) strcpy(opsys,sysbuf->sysname);
207
(void) strcpy(mach,sysbuf->machine);
210
printf("sysname: %s\n",sysbuf->sysname);
211
printf("machine: %s\n",sysbuf->machine);
212
printf("release: %s\n",sysbuf->release);
213
printf("version: %s\n",sysbuf->version);
231
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
232
Put a formatted string to stdout and MIDAS log
233
-1: the message identifier is wrong
235
implement the pipeline commands
236
MESS/OUT and APPEND/OUT
237
Put a formatted string to stdout using MID_message
238
which in turn calls the message() function
239
developed by S. Wolf for the FORS pipeline
240
-------------------------------------------------------------*/
243
void pipe_mess(actio)
250
int indent, stat, null, unit;
252
static int cmapped = 0, clen = 0;
264
if (cmapped == 0) /* allocate once */
266
bigbuf = (char*) malloc( (size_t)MAX_CBUF);
267
if (bigbuf == (char *) NULL)
269
(void) SCTPUT("could not allocate memory for MESS_CBUF..");
278
/* if actio = A, we do APPEND/MESS */
282
iav = TOKEN[1].LEN; /* process message */
283
if ((TOKEN[1].STR[0] == '"') && (TOKEN[1].STR[iav-1] == '"'))
286
(void) memmove(TOKEN[1].STR,&TOKEN[1].STR[1],(size_t) iav);
287
TOKEN[1].STR[iav] = '\0';
290
if ((clen + iav) >= MAX_CBUF)
292
SCTPUT("overflow in pipeline message buffer...so we flush it first");
293
iav = MID_message(1," ",bigbuf,0);
298
(void) memcpy(bigbuf+clen,TOKEN[1].STR,(size_t)iav);
306
/* here for MESSAGE/OUT ... */
309
(void) CGN_CNVT(TOKEN[1].STR,1,1,&id,&rbuf,&dbuf);
315
stat = SCKRDI("MESS_LEVEL",1,1,&iav,&mess_level,&unit,&null);
316
if ((stat == 0) && (id > mess_level))
317
goto end_of_it; /* that means: clear message buffer */
321
if (TOKEN[4].STR[0] != '?')
322
(void) CGN_CNVT(TOKEN[4].STR,1,1,&indent,&rbuf,&dbuf);
324
iav = TOKEN[3].LEN; /* process message */
325
if ((TOKEN[3].STR[0] != '?') && (TOKEN[3].STR[0] != '+'))
327
if ((TOKEN[3].STR[0] == '"') &&
328
(TOKEN[3].STR[iav-1] == '"'))
331
(void) memmove(TOKEN[3].STR,&TOKEN[3].STR[1],(size_t) iav);
332
TOKEN[3].STR[iav] = '\0';
335
if ((clen + iav) >= MAX_CBUF)
336
(void) SCTPUT("overflow of pipeline message buffer...");
339
(void) memcpy(bigbuf+clen,TOKEN[3].STR,(size_t)iav);
346
/* process + display the complete message buffer */
348
iav = MID_message(id,TOKEN[2].STR,bigbuf,indent);
349
if (iav < 0) printf("`message' returned %d\n",iav);
353
clen = 0; /* clear buffer again */