-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathimpl.c
More file actions
1658 lines (1400 loc) · 55.9 KB
/
impl.c
File metadata and controls
1658 lines (1400 loc) · 55.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* IMPL.C (c) Copyright Roger Bowler, 1999-2012 */
/* Hercules Initialization Module */
/* */
/* Released under "The Q Public License Version 1" */
/* (http://www.hercules-390.org/herclic.html) as modifications to */
/* Hercules. */
/*-------------------------------------------------------------------*/
/* This module initializes the Hercules S/370 or ESA/390 emulator. */
/* It builds the system configuration blocks, creates threads for */
/* central processors, HTTP server, logger task and activates the */
/* control panel which runs under the main thread when in foreground */
/* mode. */
/*-------------------------------------------------------------------*/
#include "hstdinc.h"
#ifndef _IMPL_C_
#define _IMPL_C_
#endif
#ifndef _HENGINE_DLL_
#define _HENGINE_DLL_
#endif
#include "hercules.h"
#include "opcode.h"
#include "devtype.h"
#include "herc_getopt.h"
#include "hostinfo.h"
#include "history.h"
#if(HAVE_MACH_O_DYLD_H)
# include <mach-o/dyld.h>
#endif
static char shortopts[] =
#if defined( EXTERNALGUI )
"e"
#endif
"hf:r:db:vt::"
#if defined(ENABLE_BUILTIN_SYMBOLS)
"s:"
#endif
#if defined(OPTION_DYNAMIC_LOAD)
"p:l:"
#endif
;
#if defined(HAVE_GETOPT_LONG)
static struct option longopts[] =
{
{ "test", optional_argument, NULL, 't' },
{ "help", no_argument, NULL, 'h' },
{ "config", required_argument, NULL, 'f' },
{ "rcfile", required_argument, NULL, 'r' },
{ "daemon", no_argument, NULL, 'd' },
{ "herclogo", required_argument, NULL, 'b' },
{ "verbose", no_argument, NULL, 'v' },
#if defined( EXTERNALGUI )
{ "externalgui", no_argument, NULL, 'e' },
#endif
#if defined(ENABLE_BUILTIN_SYMBOLS)
{ "defsym", required_argument, NULL, 's' },
#endif
#if defined(OPTION_DYNAMIC_LOAD)
{ "modpath", required_argument, NULL, 'p' },
{ "ldmod", required_argument, NULL, 'l' },
#endif
{ NULL, 0, NULL, 0 }
};
#endif
static LOGCALLBACK log_callback = NULL;
struct cfgandrcfile
{
const char * filename; /* Or NULL */
const char * const envname; /* Name of environment variable to test */
const char * const defaultfile; /* Default file */
const char * const whatfile; /* config/restart, for message */
};
enum cfgorrc
{
want_cfg,
want_rc,
cfgorrccount
};
static struct cfgandrcfile cfgorrc[ cfgorrccount ] =
{
{ NULL, "HERCULES_CNF", "hercules.cnf", "Configuration", },
{ NULL, "HERCULES_RC", "hercules.rc", "Run Commands", },
};
#if defined(OPTION_DYNAMIC_LOAD)
#define MAX_DLL_TO_LOAD 50
static char *dll_load[MAX_DLL_TO_LOAD]; /* Pointers to modnames */
static int dll_count = -1; /* index into array */
#endif
/* forward define process_script_file (ISW20030220-3) */
extern int process_script_file(char *,int);
/* extern int quit_cmd(int argc, char *argv[],char *cmdline); */
/* Forward declarations: */
static int process_args(int argc, char *argv[]);
/* End of forward declarations. */
/*-------------------------------------------------------------------*/
/* Register a LOG callback */
/*-------------------------------------------------------------------*/
DLL_EXPORT void registerLogCallback( LOGCALLBACK cb )
{
log_callback = cb;
}
/*-------------------------------------------------------------------*/
/* Subroutine to exit process after flushing stderr and stdout */
/*-------------------------------------------------------------------*/
static void delayed_exit (int exit_code)
{
UNREFERENCED(exit_code);
/* Delay exiting is to give the system
* time to display the error message. */
#if defined( _MSVC_ )
SetConsoleCtrlHandler( NULL, FALSE); // disable Ctrl-C intercept
#endif
sysblk.shutimmed = TRUE;
fflush(stderr);
fflush(stdout);
usleep(100000);
do_shutdown();
fflush(stderr);
fflush(stdout);
usleep(100000);
return;
}
/*-------------------------------------------------------------------*/
/* Signal handler for SIGINT signal */
/*-------------------------------------------------------------------*/
static void sigint_handler (int signo)
{
// logmsg ("impl.c: sigint handler entered for thread %lu\n",/*debug*/
// thread_id()); /*debug*/
UNREFERENCED(signo);
signal(SIGINT, sigint_handler);
/* Ignore signal unless presented on console thread */
if ( !equal_threads( thread_id(), sysblk.cnsltid ) )
return;
/* Exit if previous SIGINT request was not actioned */
if (sysblk.sigintreq)
{
/* Release the configuration */
release_config();
delayed_exit(1);
}
/* Set SIGINT request pending flag */
sysblk.sigintreq = 1;
/* Activate instruction stepping */
sysblk.inststep = 1;
SET_IC_TRACE;
return;
} /* end function sigint_handler */
/*-------------------------------------------------------------------*/
/* Signal handler for SIGTERM signal */
/*-------------------------------------------------------------------*/
static void sigterm_handler (int signo)
{
// logmsg ("impl.c: sigterm handler entered for thread %lu\n",/*debug*/
// thread_id()); /*debug*/
UNREFERENCED(signo);
signal(SIGTERM, sigterm_handler);
/* Ignore signal unless presented on main program (impl) thread */
if ( !equal_threads( thread_id(), sysblk.impltid ) )
return;
/* Initiate system shutdown */
do_shutdown();
return;
} /* end function sigterm_handler */
#if defined( _MSVC_ )
/*-------------------------------------------------------------------*/
/* Perform immediate/emergency shutdown */
/*-------------------------------------------------------------------*/
static void do_emergency_shutdown()
{
sysblk.shutdown = TRUE;
if (!sysblk.shutimmed)
{
sysblk.shutimmed = TRUE;
do_shutdown();
}
else // (already in progress)
{
while (!sysblk.shutfini)
usleep(100000);
}
}
/*-------------------------------------------------------------------*/
/* Windows console control signal handler */
/*-------------------------------------------------------------------*/
static BOOL WINAPI console_ctrl_handler( DWORD signo )
{
switch ( signo )
{
///////////////////////////////////////////////////////////////
//
// PROGRAMMING NOTE
//
///////////////////////////////////////////////////////////////
//
// "SetConsoleCtrlHandler function HandlerRoutine Callback
// Function:"
//
// "Return Value:"
//
// "If the function handles the control signal, it
// should return TRUE."
//
// "CTRL_LOGOFF_EVENT:"
//
// "Note that this signal is received only by services.
// Interactive applications are terminated at logoff,
// so they are not present when the system sends this
// signal."
//
// "CTRL_SHUTDOWN_EVENT:"
//
// "Interactive applications are not present by the time
// the system sends this signal, therefore it can be
// received only be services in this situation."
//
// "CTRL_CLOSE_EVENT:"
//
// "... if the process does not respond within a certain
// time-out period (5 seconds for CTRL_CLOSE_EVENT..."
//
///////////////////////////////////////////////////////////////
//
// What this all boils down to is we'll never receive the
// logoff and shutdown signals (via this callback), and
// we only have a maximum of 5 seconds to return TRUE from
// the CTRL_CLOSE_EVENT signal. Thus, as normal shutdowns
// may likely take longer than 5 seconds and our goal is
// to try hard to shutdown Hercules as gracfully as we can,
// we are left with little choice but to always perform
// an immediate/emergency shutdown for CTRL_CLOSE_EVENT.
//
///////////////////////////////////////////////////////////////
case CTRL_BREAK_EVENT:
// "CTRL_BREAK_EVENT received: %s"
WRMSG( HHC01400, "I", "pressing interrupt key" );
OBTAIN_INTLOCK( NULL );
ON_IC_INTKEY;
WAKEUP_CPUS_MASK( sysblk.waiting_mask );
RELEASE_INTLOCK( NULL );
return TRUE;
case CTRL_C_EVENT:
if (!sysblk.shutimmed)
// "CTRL_C_EVENT received: %s"
WRMSG( HHC01401, "I", "initiating emergency shutdown" );
do_emergency_shutdown();
return TRUE;
case CTRL_CLOSE_EVENT:
if (!sysblk.shutimmed)
// "CTRL_CLOSE_EVENT received: %s"
WRMSG( HHC01402, "I", "initiating emergency shutdown" );
do_emergency_shutdown();
return TRUE;
default:
return FALSE; // (not handled; call next signal handler)
}
UNREACHABLE_CODE( return FALSE );
}
/*-------------------------------------------------------------------*/
/* Windows hidden window message handler */
/*-------------------------------------------------------------------*/
static LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch (msg)
{
///////////////////////////////////////////////////////////////
//
// PROGRAMMING NOTE
//
///////////////////////////////////////////////////////////////
//
// "If an application returns FALSE in response to
// WM_QUERYENDSESSION, it still appears in the shutdown
// UI. Note that the system does not allow console
// applications or applications without a visible window
// to cancel shutdown. These applications are automatically
// terminated if they do not respond to WM_QUERYENDSESSION
// or WM_ENDSESSION within 5 seconds or if they return FALSE
// in response to WM_QUERYENDSESSION."
//
///////////////////////////////////////////////////////////////
//
// What this all boils down to is we can NEVER prevent the
// user from logging off or shutting down since not only are
// we a console application but our window is created invisible
// as well. Thus we only have a maximum of 5 seconds to return
// TRUE from WM_QUERYENDSESSION or return 0 from WM_ENDSESSION,
// and since a normal shutdown may likely take longer than 5
// seconds and our goal is to try hard to shutdown Hercules as
// gracfully as possible, we are left with little choice but to
// perform an immediate emergency shutdown once we receive the
// WM_ENDSESSION message with a WPARAM value of TRUE.
//
///////////////////////////////////////////////////////////////
case WM_QUERYENDSESSION:
// "%s received: %s"
WRMSG( HHC01403, "I", "WM_QUERYENDSESSION", "allow" );
return TRUE; // Vote "YES"... (we have no choice!)
case WM_ENDSESSION:
if (!wParam) // FALSE? (session not really ending?)
{
// Some other application (or the user themselves)
// has aborted the logoff or system shutdown...
// "%s received: %s"
WRMSG( HHC01403, "I", "WM_ENDSESSION", "aborted" );
return 0; // (message processed)
}
// User is logging off or the system is being shutdown.
// We have a maximum of 5 seconds to shutdown Hercules.
// "%s received: %s"
WRMSG( HHC01403, "I", "WM_ENDSESSION", "initiating emergency shutdown" );
do_emergency_shutdown();
return 0; // (message handled)
default:
return DefWindowProc( hWnd, msg, wParam, lParam );
}
UNREACHABLE_CODE( return 0 );
}
// Create invisible message handling window...
HANDLE g_hWndEvt = NULL; // (temporary window creation event)
HWND g_hMsgWnd = NULL; // (window handle of message window)
static void* WinMsgThread( void* arg )
{
WNDCLASS wc = {0};
UNREFERENCED( arg );
wc.lpfnWndProc = MainWndProc;
wc.hInstance = GetModuleHandle(0);
wc.lpszClassName = "Hercules";
RegisterClass( &wc );
g_hMsgWnd = CreateWindowEx( 0,
"Hercules", "Hercules",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL,
GetModuleHandle(0), NULL );
SetEvent( g_hWndEvt ); // (indicate create window completed)
if (g_hMsgWnd) // (pump messages if window successfully created)
{
MSG msg;
while (GetMessage( &msg, NULL , 0 , 0 ))
{
TranslateMessage ( &msg );
DispatchMessage ( &msg );
}
}
return NULL;
}
#endif /* defined( _MSVC_ ) */
#if !defined(NO_SIGABEND_HANDLER)
/*-------------------------------------------------------------------*/
/* Linux watchdog thread -- detects malfunctioning CPU engines */
/*-------------------------------------------------------------------*/
static void *watchdog_thread(void *arg)
{
S64 savecount[MAX_CPU_ENGINES];
int i;
UNREFERENCED(arg);
/* Set watchdog priority just below cpu priority
such that it will not invalidly detect an
inoperable cpu */
if(sysblk.cpuprio >= 0)
set_thread_priority(0, sysblk.cpuprio+1);
for (i = 0; i < sysblk.maxcpu; i ++) savecount[i] = -1;
while(!sysblk.shutdown)
{
for (i = 0; i < sysblk.maxcpu; i++)
{
// obtain_lock (&sysblk.cpulock[i]);
if (IS_CPU_ONLINE(i)
&& sysblk.regs[i]->cpustate == CPUSTATE_STARTED
&& (!WAITSTATE(&sysblk.regs[i]->psw)
#if defined(_FEATURE_WAITSTATE_ASSIST)
&& !(sysblk.regs[i]->sie_active && WAITSTATE(&sysblk.regs[i]->guestregs->psw))
#endif
))
{
/* If the cpu is running but not executing
instructions then it must be malfunctioning */
if((INSTCOUNT(sysblk.regs[i]) == (U64)savecount[i])
&& !HDC1(debug_watchdog_signal, sysblk.regs[i]) )
{
/* Send signal to looping CPU */
signal_thread(sysblk.cputid[i], SIGUSR1);
savecount[i] = -1;
}
else
/* Save current instcount */
savecount[i] = INSTCOUNT(sysblk.regs[i]);
}
else
/* mark savecount invalid as CPU not in running state */
savecount[i] = -1;
// release_lock (&sysblk.cpulock[i]);
}
/* Sleep for 20 seconds */
SLEEP(20);
}
return NULL;
}
#endif /*!defined(NO_SIGABEND_HANDLER)*/
/*-------------------------------------------------------------------*/
/* Herclin (plain line mode Hercules) message callback function */
/*-------------------------------------------------------------------*/
void* log_do_callback( void* dummy )
{
char* msgbuf;
int msglen;
int msgidx = -1;
UNREFERENCED( dummy );
while ((msglen = log_read( &msgbuf, &msgidx, LOG_BLOCK )))
log_callback( msgbuf, msglen );
/* Let them know logger thread has ended */
log_callback( NULL, 0 );
return (NULL);
}
/*-------------------------------------------------------------------*/
/* Return panel command handler to herclin line mode hercules */
/*-------------------------------------------------------------------*/
DLL_EXPORT COMMANDHANDLER getCommandHandler()
{
return (panel_command);
}
/*-------------------------------------------------------------------*/
/* Process .RC file thread. */
/* */
/* Called synchronously when in daemon mode. */
/*-------------------------------------------------------------------*/
static void* process_rc_file (void* dummy)
{
char pathname[MAX_PATH]; /* (work) */
UNREFERENCED(dummy);
/* We have a .rc file to run */
hostpath(pathname, cfgorrc[want_rc].filename, sizeof(pathname));
/* Wait for panel thread to engage */
// ZZ FIXME:THIS NEED TO GO
if (!sysblk.daemon_mode)
while (!sysblk.panel_init)
usleep( 10 * 1000 );
/* Run the script processor for this file */
process_script_file(pathname, 1);
// (else error message already issued)
return NULL; /* End the .rc thread. */
}
/*-------------------------------------------------------------------*/
/* IMPL main entry point */
/*-------------------------------------------------------------------*/
DLL_EXPORT int impl(int argc, char *argv[])
{
TID rctid; /* RC file thread identifier */
TID logcbtid; /* RC file thread identifier */
int rc;
/* Seed the pseudo-random number generator */
srand( time(NULL) );
/* Clear the system configuration block */
memset( &sysblk, 0, sizeof( SYSBLK ) );
VERIFY( MLOCK( &sysblk, sizeof( SYSBLK )) == 0);
#if defined (_MSVC_)
_setmaxstdio(2048);
#endif
/* Initialize EYE-CATCHERS for SYSBLK */
memset(&sysblk.blknam,SPACE,sizeof(sysblk.blknam));
memset(&sysblk.blkver,SPACE,sizeof(sysblk.blkver));
memset(&sysblk.blkend,SPACE,sizeof(sysblk.blkend));
sysblk.blkloc = swap_byte_U64((U64)((uintptr_t)&sysblk));
memcpy(sysblk.blknam,HDL_NAME_SYSBLK,strlen(HDL_NAME_SYSBLK));
memcpy(sysblk.blkver,HDL_VERS_SYSBLK,strlen(HDL_VERS_SYSBLK));
sysblk.blksiz = swap_byte_U32((U32)sizeof(SYSBLK));
{
char buf[32];
MSGBUF( buf, "END%13.13s", HDL_NAME_SYSBLK );
memcpy(sysblk.blkend, buf, sizeof(sysblk.blkend));
}
/* Initialize SETMODE and set user authority */
SETMODE(INIT);
SET_THREAD_NAME("impl");
/* Remain compatible with older external gui versions */
#if defined( EXTERNALGUI )
if (argc >= 1 && strncmp(argv[argc-1],"EXTERNALGUI",11) == 0)
{
extgui = TRUE;
argc--;
}
#endif
/* Scan argv array up front and set decoded variables. As */
/* nothing has been started we can just exit on serious errors. */
rc = process_args(argc, argv);
if (rc)
{
/* HHC02343 "Terminating due to %d argument errors" */
WRMSG(HHC02343, "S", rc);
exit(rc); /* Serously bad arguments? Stop right here */
}
/* Initialize 'hostinfo' BEFORE display_version is called */
init_hostinfo( &hostinfo );
#ifdef _MSVC_
/* Initialize sockets package */
VERIFY( socket_init() == 0 );
#endif
/* Ensure hdl_shut is called in case of shutdown
hdl_shut will ensure entries are only called once */
atexit(hdl_shut);
#if defined(ENABLE_BUILTIN_SYMBOLS)
set_symbol( "VERSION", VERSION);
set_symbol( "BDATE", __DATE__ );
set_symbol( "BTIME", __TIME__ );
{
char num_procs[64];
if ( hostinfo.num_packages != 0 &&
hostinfo.num_physical_cpu != 0 &&
hostinfo.num_logical_cpu != 0 )
{
MSGBUF( num_procs, "LP=%d, Cores=%d, CPUs=%d", hostinfo.num_logical_cpu,
hostinfo.num_physical_cpu, hostinfo.num_packages );
}
else
{
if ( hostinfo.num_procs > 1 )
MSGBUF( num_procs, "MP=%d", hostinfo.num_procs );
else if ( hostinfo.num_procs == 1 )
strlcpy( num_procs, "UP", sizeof(num_procs) );
else
strlcpy( num_procs, "", sizeof(num_procs) );
}
set_symbol( "HOSTNAME", hostinfo.nodename );
set_symbol( "HOSTOS", hostinfo.sysname );
set_symbol( "HOSTOSREL", hostinfo.release );
set_symbol( "HOSTOSVER", hostinfo.version );
set_symbol( "HOSTARCH", hostinfo.machine );
set_symbol( "HOSTNUMCPUS", num_procs );
}
set_symbol( "MODNAME", sysblk.hercules_pgmname );
set_symbol( "MODPATH", sysblk.hercules_pgmpath );
#endif
sysblk.sysgroup = DEFAULT_SYSGROUP;
sysblk.msglvl = DEFAULT_MLVL; /* Defaults to TERSE and DEVICES */
/* set default console port address */
sysblk.cnslport = strdup("3270");
/* set default tape autoinit value to OFF */
sysblk.noautoinit = TRUE;
/* default for system dasd cache is on */
sysblk.dasdcache = TRUE;
#if defined( OPTION_SHUTDOWN_CONFIRMATION )
/* set default quit timeout value (also ssd) */
sysblk.quitmout = QUITTIME_PERIOD;
#endif
/* Default command separator to off (NULL) */
sysblk.cmdsep = NULL;
#if defined(_FEATURE_SYSTEM_CONSOLE)
/* set default for scpecho to TRUE */
sysblk.scpecho = TRUE;
/* set fault for scpimply to FALSE */
sysblk.scpimply = FALSE;
#endif
/* set default system state to reset */
sysblk.sys_reset = TRUE;
/* set default SHCMDOPT enabled */
sysblk.shcmdopt = SHCMDOPT_ENABLE + SHCMDOPT_DIAG8;
/* Save process ID */
sysblk.hercules_pid = getpid();
/* Save thread ID of main program */
sysblk.impltid = thread_id();
/* Save TOD of when we were first IMPL'ed */
time( &sysblk.impltime );
/* Set to LPAR mode with LPAR 1, LPAR ID of 01, and CPUIDFMT 0 */
sysblk.lparmode = 1; /* LPARNUM 1 # LPAR ID 01 */
sysblk.lparnum = 1; /* ... */
sysblk.cpuidfmt = 0; /* CPUIDFMT 0 */
sysblk.operation_mode = om_mif; /* Default to MIF operaitons */
/* set default CPU identifier */
sysblk.cpumodel = 0x0586;
sysblk.cpuversion = 0xFD;
sysblk.cpuserial = 0x000001;
sysblk.cpuid = createCpuId(sysblk.cpumodel, sysblk.cpuversion,
sysblk.cpuserial, 0);
/* set default Program Interrupt Trace to NONE */
sysblk.pgminttr = OS_NONE;
sysblk.timerint = DEF_TOD_UPDATE_USECS;
/* set default thread priorities */
sysblk.hercprio = DEFAULT_HERCPRIO;
sysblk.todprio = DEFAULT_TOD_PRIO;
sysblk.cpuprio = DEFAULT_CPU_PRIO;
sysblk.devprio = DEFAULT_DEV_PRIO;
sysblk.srvprio = DEFAULT_SRV_PRIO;
/* Cap the default priorities at zero if setuid not available */
#if !defined( _MSVC_ )
#if !defined(NO_SETUID)
if (sysblk.suid)
#endif
{
if (sysblk.hercprio < 0)
sysblk.hercprio = 0;
if (sysblk.todprio < 0)
sysblk.todprio = 0;
if (sysblk.cpuprio < 0)
sysblk.cpuprio = 0;
if (sysblk.devprio < 0)
sysblk.devprio = 0;
if (sysblk.srvprio < 0)
sysblk.srvprio = 0;
}
#endif
#if defined(_FEATURE_ECPSVM)
sysblk.ecpsvm.available = 0;
sysblk.ecpsvm.level = 20;
#endif
#ifdef PANEL_REFRESH_RATE
sysblk.panrate = PANEL_REFRESH_RATE_SLOW;
#endif
#if defined( OPTION_SHUTDOWN_CONFIRMATION )
/* Set the quitmout value */
sysblk.quitmout = QUITTIME_PERIOD; /* quit timeout value */
#endif
#if defined(OPTION_SHARED_DEVICES)
sysblk.shrdport = 0;
#endif
#if defined(ENABLE_BUILTIN_SYMBOLS)
/* setup defaults for CONFIG symbols */
{
char buf[8];
set_symbol("LPARNAME", str_lparname());
set_symbol("LPARNUM", "1");
set_symbol("CPUIDFMT", "0");
MSGBUF( buf, "%06X", sysblk.cpuserial );
set_symbol( "CPUSERIAL", buf );
MSGBUF( buf, "%04X", sysblk.cpumodel );
set_symbol( "CPUMODEL", buf );
}
#endif
#if defined(_FEATURE_CMPSC_ENHANCEMENT_FACILITY)
sysblk.zpbits = DEF_CMPSC_ZP_BITS;
#endif
/* Initialize locks, conditions, and attributes */
initialize_lock (&sysblk.config);
initialize_lock (&sysblk.todlock);
initialize_lock (&sysblk.mainlock);
sysblk.mainowner = LOCK_OWNER_NONE;
initialize_lock (&sysblk.intlock);
initialize_lock (&sysblk.iointqlk);
sysblk.intowner = LOCK_OWNER_NONE;
initialize_lock (&sysblk.sigplock);
initialize_lock (&sysblk.mntlock);
initialize_lock (&sysblk.scrlock);
initialize_condition (&sysblk.scrcond);
initialize_lock (&sysblk.crwlock);
initialize_lock (&sysblk.ioqlock);
initialize_condition (&sysblk.ioqcond);
#ifdef FEATURE_MESSAGE_SECURITY_ASSIST_EXTENSION_3
/* Initialize the wrapping key registers lock */
initialize_rwlock(&sysblk.wklock);
#endif
/* Initialize thread creation attributes so all of hercules
can use them at any time when they need to create_thread
*/
initialize_detach_attr (DETACHED);
initialize_join_attr (JOINABLE);
initialize_condition (&sysblk.cpucond);
{
int i;
for (i = 0; i < MAX_CPU_ENGINES; i++)
initialize_lock (&sysblk.cpulock[i]);
}
initialize_condition (&sysblk.sync_cond);
initialize_condition (&sysblk.sync_bc_cond);
/* Copy length for regs */
sysblk.regs_copy_len = (int)((uintptr_t)&sysblk.dummyregs.regs_copy_end
- (uintptr_t)&sysblk.dummyregs);
/* Set the daemon_mode flag indicating whether we running in
background/daemon mode or not (meaning both stdout/stderr
are redirected to a non-tty device). Note that this flag
needs to be set before logger_init gets called since the
logger_logfile_write function relies on its setting.
*/
if (!isatty(STDERR_FILENO) && !isatty(STDOUT_FILENO))
sysblk.daemon_mode = 1; /* Leave -d intact */
/* Initialize the logmsg pipe and associated logger thread.
This causes all subsequent logmsg's to be redirected to
the logger facility for handling by virtue of stdout/stderr
being redirected to the logger facility.
*/
if (!sysblk.daemon_mode
#if defined( EXTERNALGUI )
|| extgui
#endif
) logger_init();
/*
Setup the initial codepage
*/
set_codepage(NULL);
/* Now display the version information again after logger_init
has been called so that either the panel display thread or the
external gui can see the version which was previously possibly
only displayed to the actual physical screen the first time we
did it further above (depending on whether we're running in
daemon_mode (external gui mode) or not). This it the call that
the panel thread or the one the external gui actually "sees".
The first call further above wasn't seen by either since it
was issued before logger_init was called and thus got written
directly to the physical screen whereas this one will be inter-
cepted and handled by the logger facility thereby allowing the
panel thread or external gui to "see" it and thus display it.
*/
display_version ( stdout, 0, "Hercules" );
display_build_options ( stdout, 0 );
/* Report whether Hercules is running in "elevated" mode or not */
#if defined( _MSVC_ ) // (remove this test once non-Windows version of "is_elevated()" is coded)
// HHC00018 "Hercules is %srunning in elevated mode"
if (is_elevated())
WRMSG (HHC00018, "I", "" );
else
WRMSG (HHC00018, "W", "NOT " );
#endif // defined( _MSVC_ )
#if !defined(WIN32) && !defined(HAVE_STRERROR_R)
strerror_r_init();
#endif
#if defined(OPTION_SCSI_TAPE)
initialize_lock ( &sysblk.stape_lock );
initialize_condition ( &sysblk.stape_getstat_cond );
InitializeListHead ( &sysblk.stape_mount_link );
InitializeListHead ( &sysblk.stape_status_link );
#endif /* defined(OPTION_SCSI_TAPE) */
if (sysblk.scrtest)
{
// "Hercules is running in test mode."
WRMSG (HHC00019, "W" );
if (sysblk.scrfactor != 1.0)
// "Test timeout factor = %3.1f"
WRMSG( HHC00021, "I", sysblk.scrfactor );
}
/* Set default TCP keepalive values */
#if !defined( HAVE_BASIC_KEEPALIVE )
WARNING("TCP keepalive headers not found; check configure.ac")
WARNING("TCP keepalive support will NOT be generated")
// "This build of Hercules does not support TCP keepalive"
WRMSG( HHC02321, "E" );
#else // basic, partial or full: must attempt setting keepalive
#if !defined( HAVE_FULL_KEEPALIVE ) && !defined( HAVE_PARTIAL_KEEPALIVE )
WARNING("This build of Hercules will only have basic TCP keepalive support")
// "This build of Hercules has only basic TCP keepalive support"
WRMSG( HHC02322, "W" );
#elif !defined( HAVE_FULL_KEEPALIVE )
WARNING("This build of Hercules will only have partial TCP keepalive support")
// "This build of Hercules has only partial TCP keepalive support"
WRMSG( HHC02323, "W" );
#endif // (basic or partial)
/*
** Note: we need to try setting them to our desired values first
** and then retrieve the set values afterwards to detect systems
** which do not allow some values to be changed to ensure SYSBLK
** gets initialized with proper working default values.
*/
{
int rc, sfd, idle, intv, cnt;
/* Need temporary socket for setting/getting */
sfd = socket( AF_INET, SOCK_STREAM, 0 );
if (sfd < 0)
{
WRMSG( HHC02219, "E", "socket()", strerror( HSO_errno ));
idle = 0;
intv = 0;
cnt = 0;
}
else
{
idle = KEEPALIVE_IDLE_TIME;
intv = KEEPALIVE_PROBE_INTERVAL;
cnt = KEEPALIVE_PROBE_COUNT;
/* First, try setting the desired values */
rc = set_socket_keepalive( sfd, idle, intv, cnt );
if (rc < 0)
{
WRMSG( HHC02219, "E", "set_socket_keepalive()", strerror( HSO_errno ));
idle = 0;
intv = 0;
cnt = 0;
}
else
{
/* Report partial success */
if (rc > 0)
{
// "Not all TCP keepalive settings honored"
WRMSG( HHC02320, "W" );
}
sysblk.kaidle = idle;
sysblk.kaintv = intv;
sysblk.kacnt = cnt;
/* Retrieve current values from system */
if (get_socket_keepalive( sfd, &idle, &intv, &cnt ) < 0)
WRMSG( HHC02219, "E", "get_socket_keepalive()", strerror( HSO_errno ));
}
close_socket( sfd );
}
/* Initialize SYSBLK with default values */
sysblk.kaidle = idle;
sysblk.kaintv = intv;
sysblk.kacnt = cnt;
}
#endif // (KEEPALIVE)
/* Initialize runtime opcode tables */
init_opcode_tables();
#if defined(OPTION_DYNAMIC_LOAD)
/* Initialize the hercules dynamic loader */
hdl_main();
/* Load modules requested at startup */
if (dll_count >= 0)
{
int hl_err = FALSE;
for ( dll_count = 0; dll_count < MAX_DLL_TO_LOAD; dll_count++ )
{
if (dll_load[dll_count] != NULL)
{
if (hdl_load(dll_load[dll_count], HDL_LOAD_DEFAULT) != 0)
{
hl_err = TRUE;
}
free(dll_load[dll_count]);
}
else
break;
}
if (hl_err)
{
usleep(10000); // give logger time to issue error message
WRMSG(HHC01408, "S");
delayed_exit(-1);
return(1);
}
}