Debian Codegraph @

libsrc/xcon/consubsa.c

raw
1 /*===========================================================================
2 Copyright (C) 1994-2009 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: [email protected]
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 /*+++++++++++++++++++++++ module consubs +++++++++++++++++++++++
29 .LANGUAGE C
30 .IDENTIFICATION Module consubs
31 .AUTHOR K. Banse ESO - Garching
32 .KEYWORDS
33 connection, sockets
34 .COMMENTS
35 holds inxcon, Mrunning
36 .ENVIRONMENT VMS and UNIX
37 .VERSION [1.00] 940426: pulled out from prepb.c
38 990830
39
40 090407 last modif
41 ------------------------------------------------------------------------*/
42
43 #include <midas_def.h>
44 #include <fsydef.h>
45 #include <osyparms.h>
46 #include <xconndef.h>
47 #include <string.h>
48
49 #define READ 0
50
51
52 /*
53
54 */
55
56
57 void inxcon(munit,direc)
58
59 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
60 .PURPOSE
61 build up file names + clean up structures (partly)
62 .ALGORITHM
63 use translation of MID_WORK stored in XCONNECT.DIREC
64 .RETURNS
65 success code = 0, = 1 for problems
66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
67
68 char *munit; /* IN: Midas unit of sender */
69 char *direc; /* IN: directory for file transfer */
70
71 {
72 register int nr;
73
74 int offs;
75
76
77 XCONNECT.MYPID = oshpid();
78 XCONNECT.MYUNIT[0] = munit[0];
79 XCONNECT.MYUNIT[1] = munit[1];
80
81 if (*direc != '\0')
82 offs = CGN_COPY(XCONNECT.SBOX,direc); /* get Midas startup directory */
83 else
84 offs = 0;
85
86 (void)strcpy(&XCONNECT.SBOX[offs],"FORGR .SBOX"); /* get send_box */
87
88 (void)strcpy(XCONNECT.RBOX,direc);
89 (void)strcat(XCONNECT.RBOX,"FORGR .RBOX"); /* get receive_box */
90
91 XCONNECT.OFFS = offs + 5; /* point to sender unit */
92 XCONNECT.OFFR = offs + 7; /* point to receiver unit */
93
94
95 for (nr=0; nr<MAX_BACK; nr++)
96 {
97 BKMIDAS[nr].PID = -1;
98 BKMIDAS[nr].WAIT = 0;
99 BKMIDAS[nr].CHAN = 0;
100 BKMIDAS[nr].UNIT[0] = ' ';
101 BKMIDAS[nr].HOST[0] = '\0';
102 }
103 }
104
105 /*
106
107 */
108
109 int Mrunning(munit,maxtime)
110 char munit[];
111 int maxtime;
112
113 {
114 int fid, loop, n, retval;
115
116 char cbuf[120], kbuf[120];
117
118
119 OSY_TRNLOG("MID_WORK",kbuf,112,&n);
120 if (strcmp(kbuf,"MID_WORK") == 0)
121 { /* if MID_WORK not defined, */
122 OSY_TRNLOG("HOME",kbuf,112,&n); /* use $HOME/midwork/ instead */
123 (void) strcat(kbuf,"/midwork/");
124 (void) sprintf(cbuf,"%sRUNNING%c%c",kbuf,munit[0],munit[1]);
125 }
126
127 else
128 {
129 if (kbuf[n-1] != FSY_DIREND)
130 {
131 char cc;
132
133 cc = FSY_DIREND;
134 (void) sprintf(cbuf,"%s%cRUNNING%c%c",kbuf,cc,munit[0],munit[1]);
135 }
136 else
137 (void) sprintf(cbuf,"%sRUNNING%c%c",kbuf,munit[0],munit[1]);
138 }
139
140 if (maxtime > 0)
141 {
142 retval = -1;
143 loop = maxtime*2;
144 while (loop > 0)
145 {
146 fid = osaopen(cbuf,READ);
147 if (fid > -1)
148 {
149 n = osaread(fid,cbuf,20);
150 osaclose(fid);
151
152 if (n < 20)
153 retval = 0; /* running, but not ready yet */
154 else
155 return 1;
156 }
157 ospuwait(500000); /* wait 500 msecs */
158 loop --;
159 }
160 return retval; /* no Midas running */
161 }
162
163 else
164 {
165 fid = osaopen(cbuf,READ);
166 if (fid < 0)
167 return -1;
168 else
169 {
170 n = osaread(fid,cbuf,20);
171 if (n < 20)
172 retval = 0; /* running, but not ready yet */
173 else
174 retval = 1;
175 osaclose(fid);
176 return retval;
177 }
178 }
179 }
180