finit.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #pragma ident "@(#) libf/fio/finit.c 92.4 11/16/99 15:43:33"
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #ifdef _UNICOS
00061 #include <infoblk.h>
00062 #include <sys/category.h>
00063 #endif
00064 #if defined(_LITTLE_ENDIAN)
00065 #include <stdlib.h>
00066 #include <cray/portdefs.h>
00067 #else
00068 #include <signal.h>
00069 #include <stdio.h>
00070 #include <stdlib.h>
00071 #include <string.h>
00072 #include <unistd.h>
00073 #include <sys/stat.h>
00074 #include <cray/mtlock.h>
00075 #if defined(_CRAYMPP) && defined(SA_SIGINFO)
00076 #define GOT_SIGINFO
00077 #include <siginfo.h>
00078 #endif
00079 #include "fio.h"
00080 #endif
00081
00082 #ifdef _UNICOS
00083 #pragma _CRI soft _lwrite_setup
00084 #elif !defined(_LITTLE_ENDIAN)
00085 #pragma weak _lwrite_setup
00086 #endif
00087 extern void _lwrite_setup(void);
00088
00089 #ifdef _UNICOS
00090 #pragma _CRI soft _wf_setup
00091 #elif !defined(_LITTLE_ENDIAN)
00092 #pragma weak _wf_setup
00093 #endif
00094 extern void _wf_setup(void);
00095 extern void _fcleanup(void);
00096 #ifdef __mips
00097 extern void _fortclean(void);
00098 #endif
00099
00100
00101
00102 #ifdef GOT_SIGINFO
00103 static void _f_sig(int, siginfo_t *, void *);
00104 #else
00105 static void _f_sig(int);
00106 #endif
00107 extern void _aborthandle(void);
00108 #ifdef _CRAYMPP
00109
00110 void _f_stopsig(int);
00111 extern void _abortcatch(int);
00112 #endif
00113
00114 #ifdef _CRAY1
00115 #pragma _CRI soft $WBUFLN, $RBUFLN
00116 extern int $WBUFLN, $RBUFLN;
00117 _f_int $RFDCOM[1];
00118 _f_int $WFDCOM[1];
00119 #endif
00120
00121 #ifndef _ABSOFT
00122 extern char *sys_siglist[];
00123 #endif
00124
00125 extern int __fdctrace_enable;
00126
00127 short _fortran_io_is_init;
00128 short _e_fortran_io_is_init;
00129 short _i_fortran_io_is_init;
00130 short _f_abort;
00131
00132 #ifdef _CRAYMPP
00133
00134 volatile int _infio;
00135 volatile int _needtostop;
00136 extern int G@INTIO;
00137 #endif
00138
00139
00140
00141
00142
00143
00144
00145 void
00146 _initialize_fortran_io(void)
00147 {
00148 _fortran_io_is_init = 1;
00149
00150
00151
00152 if (LOADED(_lwrite_setup))
00153 _lwrite_setup();
00154
00155
00156
00157 if (LOADED(_wf_setup))
00158 _wf_setup();
00159
00160 #ifdef _CRAY1
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 if (LOADED_DATA(&$RBUFLN))
00180 if (_VALUE($RBUFLN) > _f_rcsz)
00181 _f_rcsz = _VALUE($RBUFLN);
00182
00183 if (LOADED_DATA(&$WBUFLN))
00184 if (_VALUE($WBUFLN) > _f_rcsz)
00185 _f_rcsz = _VALUE($WBUFLN);
00186 #endif
00187
00188 return;
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198 void
00199 _initialize_e_fortran_io(void)
00200 {
00201 _e_fortran_io_is_init = 1;
00202
00203 if (! _fortran_io_is_init)
00204 _initialize_fortran_io();
00205
00206
00207
00208 (void) atexit(_fcleanup);
00209 #ifdef __mips
00210 (void) __ateachexit(_fortclean);
00211 #endif
00212 #ifdef _UNICOS
00213 (void) atabort(_fcleanup);
00214 #endif
00215
00216
00217
00218 #ifdef DEBUG
00219 if (__fdctrace_enable < 0) {
00220 char *estr;
00221
00222 estr = getenv("FDCTRACE");
00223
00224 __fdctrace_enable = (estr == NULL) ? 0 : atol(estr);
00225 }
00226 #endif
00227
00228 return;
00229 }
00230
00231
00232
00233
00234
00235
00236 void
00237 _initialize_i_fortran_io(void)
00238 {
00239 _i_fortran_io_is_init = 1;
00240
00241 if (! _fortran_io_is_init)
00242 _initialize_fortran_io();
00243
00244 return;
00245 }
00246
00247 #ifdef _UNICOS
00248
00249
00250
00251
00252
00253
00254 void
00255 _finit(void)
00256 {
00257
00258
00259
00260
00261 _initialize_e_fortran_io();
00262 return;
00263 }
00264
00265
00266
00267
00268
00269
00270
00271
00272 void
00273 f$init(void)
00274 {
00275 register short catchem;
00276 char *trace;
00277
00278 catchem = 1;
00279
00280
00281
00282
00283
00284 if (((trace = getenv("TRACEBK")) && atol(trace) == 0) ||
00285 ((trace = getenv("TRACEBK2")) && atol(trace) != 0))
00286 catchem = 0;
00287 #ifdef _CRAYMPP
00288
00289
00290
00291
00292 if (_num_pes() > 1) {
00293 struct sigaction act, oact;
00294
00295 act.sa_handler = _f_stopsig;
00296 act.sa_mask = 0;
00297 act.sa_flags = SA_RESETHAND | SA_CLEARPEND ;
00298
00299 (void) sigaction(SIGBUFIO, &act, &oact);
00300
00301 if (oact.sa_handler != SIG_DFL &&
00302 oact.sa_handler != _f_stopsig)
00303 (void) sigaction(SIGBUFIO, &oact, 0);
00304 }
00305 #endif
00306 if (catchem) {
00307 #ifndef SIGSMCE
00308 #define SIGSMCE 38
00309 #endif
00310 #ifndef SIGAPTEAM
00311 #define SIGAPTEAM 39
00312 #endif
00313 unsigned long mask;
00314 struct sigaction act, oact;
00315 register int sig;
00316
00317 mask = (SIG_DMPDFL | sigmask(SIGHUP) |
00318 sigmask(SIGINT) | sigmask(SIGTERM) |
00319 sigmask(SIGCPULIM) | sigmask(SIGPIPE) |
00320 sigmask(SIGSMCE)) | sigmask(SIGAPTEAM)
00321 & ~SIG_CANTMASK;
00322 #ifdef GOT_SIGINFO
00323 act.sa_sigaction = _f_sig;
00324 #else
00325 act.sa_handler = _f_sig;
00326 #endif
00327 act.sa_mask = 0;
00328 act.sa_flags = SA_RESETHAND | SA_NODEFER | SA_CLEARPEND;
00329 #ifdef GOT_SIGINFO
00330 act.sa_flags |= SA_SIGINFO;
00331 #endif
00332
00333 for (sig = 1; mask != 0; sig++, mask >>= 1)
00334 if (mask & 01) {
00335 (void) sigaction(sig, &act, &oact);
00336 #ifdef _CRAYMPP
00337 if (oact.sa_handler != SIG_DFL &&
00338 oact.sa_handler != _abortcatch)
00339 #else
00340 if (oact.sa_handler != SIG_DFL)
00341 #endif
00342 (void) sigaction(sig, &oact, 0);
00343 }
00344 }
00345
00346 #ifdef _CRAYMPP
00347 _barrier();
00348 #endif
00349
00350 return;
00351 }
00352
00353 #endif
00354
00355
00356
00357
00358
00359 #if defined(_UNICOS) && !(defined(GOT_SIGINFO) || defined(_CRAYMPP))
00360
00361 static short _f_gotsig = 0;
00362 static long _f_siglock = 0;
00363
00364 static void
00365 _f_sig(int sig)
00366 {
00367 sigset_t set;
00368
00369 (void) sigoff();
00370
00371 _semclr(2);
00372
00373 MEM_LOCK(&_f_siglock);
00374
00375 if (_f_gotsig == 0) {
00376
00377 _f_gotsig = 1;
00378 _f_abort = 1;
00379
00380 MEM_UNLOCK(&_f_siglock);
00381
00382 (void) sigon();
00383 (void) fflush(stdout);
00384 (void) fflush(stderr);
00385
00386 if (sig > 0 && sig < NSIG) {
00387 (void) write(fileno(stderr), sys_siglist[sig],
00388 strlen(sys_siglist[sig]));
00389 (void) write(fileno(stderr), "\n", 1);
00390 }
00391
00392 (void) sigtrbk(stderr);
00393
00394 _aborthandle();
00395
00396 }
00397 else {
00398
00399 MEM_UNLOCK(&_f_siglock);
00400
00401 (void) sigon();
00402 }
00403
00404 set = sigmask(sig);
00405
00406 (void) sigprocmask(SIG_BLOCK, &set, NULL);
00407 (void) killm(C_PROC, 0, sig);
00408
00409 return;
00410 }
00411
00412 #elif defined(_CRAYMPP)
00413
00414 static DECL_LOCK(_f_siglock)
00415
00416 void
00417 _f_stopsig(int sig)
00418 {
00419
00420
00421 G@INTIO = 1;
00422
00423 if (_infio) {
00424
00425
00426
00427
00428
00429 struct sigaction act, oact;
00430
00431 _needtostop = 1;
00432 act.sa_handler = _f_stopsig;
00433 act.sa_mask = 0;
00434 act.sa_flags = SA_RESETHAND | SA_CLEARPEND ;
00435
00436 (void) sigaction(SIGBUFIO, &act, &oact);
00437 return;
00438 }
00439
00440 _fcleanup();
00441
00442 exit(0);
00443 }
00444
00445 #ifdef GOT_SIGINFO
00446 static void
00447 _f_sig(int sig, siginfo_t *sip, void *ctx)
00448 #else
00449 static void
00450 _f_sig(int sig)
00451 #endif
00452 {
00453 sigset_t set;
00454 register long locked;
00455 register long start;
00456 register long wait;
00457 char buf[50];
00458
00459 (void) sigoff();
00460
00461 locked = _shmem_test_lock(&_f_siglock);
00462 _f_abort = 1;
00463
00464 if (!locked) {
00465
00466
00467
00468
00469 (void) sigon();
00470 (void) fflush(stdout);
00471 (void) fflush(stderr);
00472 #ifdef GOT_SIGINFO
00473 psiginfo(sip, "SIGNAL");
00474 #else
00475 if (sig > 0 && sig < NSIG) {
00476 (void) strncpy(buf, sys_siglist[sig], sizeof(buf) - 1);
00477 (void) strcat(buf, "\n");
00478 (void) write(fileno(stderr), buf, strlen(buf));
00479 }
00480 #endif
00481 (void) sigtrbk(stderr);
00482 _aborthandle();
00483 } else {
00484
00485
00486
00487
00488
00489 (void) sigon();
00490 _aborthandle();
00491 #ifdef _UNICOS_MAX
00492 _barrier();
00493 #endif
00494 _localexit(EXIT_FAILURE);
00495 }
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510 set = sigmask(sig);
00511
00512 (void) sigprocmask(SIG_BLOCK, &set, NULL);
00513 (void) killm(C_PROC, 0, sig);
00514
00515 #ifdef _UNICOS_MAX
00516 _set_barrier();
00517 start = _rtc();
00518 wait = start + CLK_TCK;
00519
00520 while (_rtc() >= start && _rtc() < wait) {
00521 if (_test_barrier())
00522 break;
00523 }
00524 #endif
00525
00526 return;
00527 }
00528 #endif
00529
00530 #ifdef _SOLARIS
00531
00532
00533
00534
00535
00536
00537
00538 void
00539 _F90_INIT()
00540 {
00541
00542
00543
00544
00545
00546 _initialize_e_fortran_io();
00547
00548 return;
00549 }
00550
00551 #endif