Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (c) 1991-2002, The Numerical Algorithms Group Ltd.
3
All rights reserved.
4
Copyright (C) 2007-2014, Gabriel Dos Reis.
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
9
met:
10
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
17
distribution.
18
19
- Neither the name of The Numerical Algorithms Group Ltd. nor the
20
names of its contributors may be used to endorse or promote products
21
derived from this software without specific prior written permission.
22
23
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
#include <stdlib.h>
37
#include <unistd.h>
38
#include <string.h>
39
#include <stdio.h>
40
#include <pwd.h>
41
#include <fcntl.h>
42
#include <termios.h>
43
#include <errno.h>
44
#include <sys/time.h>
45
#include <sys/wait.h>
46
#include <signal.h>
47
#include <locale.h>
48
49
#include "open-axiom.h"
50
#include "sockio.h"
51
#include "com.h"
52
#include "bsdsignal.h"
53
#include "sman.h"
54
55
#include "sockio.h"
56
#include "openpty.h"
57
#include "cfuns.h"
58
59
using namespace OpenAxiom;
60
61
static void process_arguments(Command*, int, char**);
62
static int in_X(void);
63
static void set_up_defaults(void);
64
static void process_options(Command*, int, char**);
65
static void death_handler(int);
66
static void sman_catch_signals(void);
67
static void fix_env(int);
68
static void init_term_io(void);
69
static const char* strPrefix(const char* , const char*);
70
static void check_spad_proc(const char* , const char*);
71
static void clean_up_old_sockets(void);
72
static SpadProcess* fork_you(int);
73
static void exec_command_env(const char*);
74
static SpadProcess* spawn_of_hell(const char* , int);
75
static void start_the_spadclient(void);
76
static void start_the_local_spadclient(void);
77
static void start_the_session_manager(void);
78
static void start_the_hypertex(Command*);
79
static void start_the_graphics(Command*);
80
static void fork_Axiom(Command*);
81
static void start_the_Axiom(Command*);
82
static void clean_up_sockets(void);
83
static void clean_hypertex_socket(void);
84
static void read_from_spad_io(int);
85
static void read_from_manager(int);
86
static void manage_spad_io(int);
87
static SpadProcess* find_child(int);
88
static void kill_all_children(void);
89
static void monitor_children(void);
90
91
/* System defined pointer to array or environment variables. */
92
extern char** environ;
93
94
int start_clef; /* start clef under spad */
95
int start_graphics; /* start the viewman */
96
int start_ht; /* start hypertex */
97
int start_spadclient; /* Start the client spad buffer */
98
int start_local_spadclient; /* Start the client spad buffer */
99
int use_X; /* Use the X windows environment */
100
int server_num; /* OpenAxiom server number */
101
102
/************************************************/
103
/* definitions of programs which sman can start */
104
/************************************************/
105
106
const char *GraphicsProgram = "/lib/viewman";
107
const char *HypertexProgram = "/lib/hypertex";
108
const char *ClefProgram = "$AXIOM/bin/clef -f $AXIOM/lib/command.list -e ";
109
const char *SessionManagerProgram = "$AXIOM/lib/session";
110
const char *SpadClientProgram = "$AXIOM/lib/spadclient";
111
char *PasteFile = NULL;
112
char *MakeRecordFile = NULL;
113
char *VerifyRecordFile = NULL;
114
115
SpadProcess *spad_process_list = NULL;
116
/***************************/
117
/* sman defaults file name */
118
/***************************/
119
120
#define SpadDefaultFile "spadprof.input"
121
122
char ClefCommandLine[256];
123
124
#define BufSize 4096 /* size of communication buffer */
125
char big_bad_buf[BufSize]; /* big I/O buffer */
126
127
openaxiom_sio* session_io = NULL; /* socket connecting to session manager */
128
129
/***********************************************************/
130
/* Some characters used and externally defined in edible.h */
131
/***********************************************************/
132
133
unsigned char _INTR, _QUIT, _ERASE, _KILL, _EOF, _EOL, _RES1, _RES2;
134
135
/*************************************/
136
/* Stuff for opening pseudo-terminal */
137
/*************************************/
138
139
int ptsNum, ptcNum;
140
char ptsPath[20];
141
142
int child_pid; /* child's process id */
143
struct termios oldbuf; /* the original settings */
144
struct termios childbuf; /* terminal structure for user i/o */
145
146
147
int death_signal = 0;
148
149
static void
150
process_arguments(Command* command, int argc,char ** argv)
151
{
152
int arg;
153
int other = 0;
154
for (arg = 1; arg < argc; arg++) {
155
if (strcmp(argv[arg], "-noclef") == 0)
156
start_clef = 0;
157
else if (strcmp(argv[arg], "-clef") == 0)
158
start_clef = 1;
159
else if (strcmp(argv[arg], "-gr") == 0
160
|| strcmp(argv[arg], "--graph") == 0 ) {
161
if (!OPENAXIOM_HAVE_GRAPHICS)
162
fprintf(stderr, "OpenAxiom was not build with Graphics support.\n");
163
else
164
start_graphics = 1;
165
}
166
else if (strcmp(argv[arg], "-nogr") == 0
167
|| strcmp(argv[arg], "--no-graph") == 0)
168
start_graphics = 0;
169
else if (strcmp(argv[arg], "-ht") == 0
170
|| strcmp(argv[arg], "--hyperdoc") == 0) {
171
if (!OPENAXIOM_HAVE_GRAPHICS)
172
fprintf(stderr, "OpenAxiom was not build with HyperDoc support.\n");
173
else
174
start_ht = 1;
175
}
176
else if (strcmp(argv[arg], "-noht") == 0
177
|| strcmp(argv[arg], "--no-hyperdoc") == 0)
178
start_ht = 0;
179
else if (strcmp(argv[arg], "-iw") == 0)
180
start_spadclient = 1;
181
else if (strcmp(argv[arg], "-ihere") == 0)
182
start_local_spadclient = 1;
183
else if (strcmp(argv[arg], "-noihere") == 0)
184
start_local_spadclient = 0;
185
else if (strcmp(argv[arg], "-noiw") == 0)
186
start_spadclient = 0;
187
else if (strcmp(argv[arg], "-nox") == 0
188
|| strcmp(argv[arg], "--no-gui") == 0) {
189
use_X = 0;
190
start_local_spadclient = 1;
191
start_spadclient = 0;
192
start_ht = 0;
193
start_graphics = 0;
194
}
195
else if (strcmp(argv[arg], "-clefprog") == 0) {
196
strcpy(ClefCommandLine,argv[++arg]);
197
ClefProgram =
198
strcat(ClefCommandLine, " -f $AXIOM/lib/command.list -e ");
199
}
200
else if (strcmp(argv[arg], "-rm") == 0)
201
MakeRecordFile = argv[++arg];
202
else if (strcmp(argv[arg], "-rv") == 0)
203
VerifyRecordFile = argv[++arg];
204
else if (strcmp(argv[arg], "-paste") == 0)
205
PasteFile = argv[++arg];
206
else
207
argv[other++] = argv[arg];
208
}
209
210
command->core.argv = argv;
211
command->core.argc = other;
212
213
/* If there were no X libraries
214
* at build-time, we proceed to
215
* overwrite the defaults startup
216
* values to not start any of the
217
* graphical components of
218
* OpenAxiom (Hyperdoc, Graphics). */
219
220
if (!OPENAXIOM_HAVE_GRAPHICS) {
221
use_X = 0;
222
start_local_spadclient = 1;
223
start_ht = 0;
224
start_graphics = 0;
225
}
226
}
227
228
static int
229
in_X(void)
230
{
231
if (oa_getenv("DISPLAY")) return 1;
232
return 0;
233
}
234
235
static void
236
set_up_defaults(void)
237
{
238
start_clef = 1;
239
start_graphics = 1;
240
start_ht = 1;
241
start_spadclient = 0;
242
start_local_spadclient = 1;
243
use_X = isatty(0) && in_X();
244
}
245
246
static void
247
process_options(Command* command, int argc, char **argv)
248
{
249
set_up_defaults();
250
process_arguments(command, argc, argv);
251
/* Complain about command line arguments unknown to Superman. */
252
if (command->core.argc > 0) {
253
int i;
254
for (i = 0; i < command->core.argc; ++i)
255
fprintf(stderr,"command line error: %s\n", command->core.argv[i]);
256
exit(-1);
257
}
258
}
259
260
static void
261
death_handler(int sig)
262
{
263
death_signal = 1;
264
}
265
266
static void
267
sman_catch_signals(void)
268
{
269
270
/* Set up the signal handlers for sman */
271
bsdSignal(SIGINT, SIG_IGN,RestartSystemCalls);
272
bsdSignal(SIGTERM, death_handler,RestartSystemCalls);
273
bsdSignal(SIGQUIT, death_handler,RestartSystemCalls);
274
bsdSignal(SIGHUP, death_handler,RestartSystemCalls);
275
bsdSignal(SIGILL, death_handler,RestartSystemCalls);
276
bsdSignal(SIGTRAP, death_handler,RestartSystemCalls);
277
278
#ifdef SIGABRT
279
bsdSignal(SIGABRT, death_handler,RestartSystemCalls);
280
#else
281
#ifdef SIGIOT
282
bsdSignal(SIGIOT, death_handler,RestartSystemCalls);
283
#endif
284
#endif
285
286
bsdSignal(SIGBUS, death_handler,RestartSystemCalls);
287
bsdSignal(SIGSEGV, death_handler,RestartSystemCalls);
288
289
}
290
291
static void
292
fix_env(int spadnum)
293
{
294
char sn[20];
295
sprintf(sn, "%d", spadnum);
296
oa_setenv("SPADNUM", sn);
297
oa_setenv("SPADSERVER", "TRUE");
298
}
299
300
static void
301
init_term_io(void)
302
{
303
if(!isatty(0)) return;
304
if( tcgetattr(0, &oldbuf) == -1) {
305
perror("getting termios");
306
return ; /* exit(-1); */
307
}
308
if( tcgetattr(0, &childbuf) == -1) {
309
perror("getting termios");
310
return ; /* exit(-1); */
311
}
312
_INTR = oldbuf.c_cc[VINTR];
313
_QUIT = oldbuf.c_cc[VQUIT];
314
_ERASE = oldbuf.c_cc[VERASE];
315
_KILL = oldbuf.c_cc[VKILL];
316
_EOF = oldbuf.c_cc[VEOF];
317
_EOL = oldbuf.c_cc[VEOL];
318
}
319
320
static const char*
321
strPrefix(const char* prefix, const char* s)
322
{
323
while (*prefix != '\0' && *prefix == *s) {
324
prefix++;
325
s++;
326
}
327
if (*prefix == '\0') return s;
328
return NULL;
329
}
330
331
static void
332
check_spad_proc(const char *file, const char *prefix)
333
{
334
const char *num;
335
int pid;
336
if ((num = strPrefix(prefix, file))) {
337
pid = atoi(num);
338
if (pid > 2) {
339
kill(pid, 0);
340
if (kill(pid, 0) == -1 && errno == ESRCH) {
341
unlink(file);
342
}
343
}
344
}
345
}
346
347
static void
348
clean_up_old_sockets(void)
349
{
350
char com[512], tmp_file[128];
351
FILE *file;
352
int len;
353
sprintf(tmp_file, "/tmp/socks.%d", server_num);
354
sprintf(com, "ls /tmp/.d* /tmp/.s* /tmp/.i* /tmp/.h* 2> %s > %s",
355
tmp_file, tmp_file);
356
system(com);
357
file = fopen(tmp_file, "r");
358
if (file == NULL) {
359
fprintf(stderr, "Can't open socket listing file\n");
360
return;
361
}
362
while(fgets(com, 512, file) != NULL) {
363
len = strlen(com);
364
if (len) com[len-1] = '\0';
365
else break;
366
check_spad_proc(com, "/tmp/.d");
367
check_spad_proc(com, "/tmp/.s");
368
check_spad_proc(com, "/tmp/.i");
369
check_spad_proc(com, "/tmp/.h");
370
}
371
fclose(file);
372
unlink(tmp_file);
373
}
374
375
static SpadProcess *
376
fork_you(int death_action)
377
{
378
/* fork a new process, giving it a default death action */
379
/* return NULL in child, SpadProcess in parent */
380
int child_pid = fork();
381
SpadProcess *proc;
382
if (!child_pid) return NULL;
383
proc = (SpadProcess *) malloc(sizeof(SpadProcess));
384
proc->proc_id = child_pid;
385
proc->death_action = death_action;
386
proc->command = NULL;
387
proc->next = spad_process_list;
388
spad_process_list = proc;
389
return proc;
390
}
391
392
static void
393
exec_command_env(const char *command)
394
{
395
char new_command[512];
396
sprintf(new_command, "exec %s", command);
397
execle("/bin/sh","/bin/sh", "-c", new_command, (char*)NULL, environ);
398
}
399
400
static SpadProcess *
401
spawn_of_hell(const char *command, int death_action)
402
{
403
SpadProcess *proc = fork_you(death_action);
404
if (proc != NULL) {
405
proc->command = command;
406
return proc;
407
}
408
exec_command_env(command);
409
return NULL;
410
}
411
412
static void
413
start_the_spadclient(void)
414
{
415
char command[256];
416
if (start_clef)
417
sprintf(command,
418
"xterm -sb -sl 500 -name axiomclient -n OpenAxiom -T OpenAxiom -e %s %s",
419
ClefProgram, SpadClientProgram);
420
else
421
sprintf(command,
422
"xterm -sb -sl 500 -name axiomclient -n OpenAxiom -T OpenAxiom -e %s",
423
SpadClientProgram);
424
spawn_of_hell(command, NadaDelShitsky);
425
}
426
427
static void
428
start_the_local_spadclient(void)
429
{
430
char command[256];
431
if (start_clef)
432
sprintf(command, "%s %s", ClefProgram, SpadClientProgram);
433
else
434
sprintf(command, "%s", SpadClientProgram);
435
spawn_of_hell(command, NadaDelShitsky);
436
}
437
438
static void
439
start_the_session_manager(void)
440
{
441
spawn_of_hell(SessionManagerProgram, Die);
442
}
443
444
static void
445
start_the_hypertex(Command* cmd)
446
{
447
const char* root_dir = cmd->root_dir;
448
const char* command = oa_concatenate_string(root_dir,HypertexProgram);
449
450
if (readablep(command) != 1) {
451
fprintf(stderr, "Hypertex program not found.\n");
452
return;
453
}
454
if (PasteFile){
455
command = oa_concatenate_string(command, " -s -k -ip ");
456
command = oa_concatenate_string(command, PasteFile);
457
spawn_of_hell(command, NadaDelShitsky);
458
}
459
else if (MakeRecordFile){
460
command = oa_concatenate_string(command, " -s -k -rm ");
461
command = oa_concatenate_string(command, MakeRecordFile);
462
spawn_of_hell(command, NadaDelShitsky);
463
}
464
else if (VerifyRecordFile){
465
command = oa_concatenate_string(command, " -s -k -rv ");
466
command = oa_concatenate_string(command, VerifyRecordFile);
467
spawn_of_hell(command, NadaDelShitsky);
468
}
469
else
470
spawn_of_hell(command, CleanHypertexSocket);
471
}
472
473
static void
474
start_the_graphics(Command* cmd)
475
{
476
const char* root_dir = cmd -> root_dir;
477
const char* command = oa_concatenate_string(root_dir,GraphicsProgram);
478
479
if (readablep(command) == 1)
480
spawn_of_hell(command, DoItAgain);
481
else
482
fprintf(stderr, "Graphics program not found.\n");
483
}
484
485
/* Start the core executable session in a separate process, */
486
/* using a pseudo-terminal to catch all input and output */
487
static void
488
fork_Axiom(Command* cmd)
489
{
490
SpadProcess *proc;
491
492
proc = fork_you(Die);
493
child_pid = (proc == NULL ? 0 : proc->proc_id);
494
switch(child_pid) {
495
case -1 :
496
fprintf(stderr, "Can't create a new process \n");
497
exit(0);
498
case 0:
499
/* Dissasociate from my parents group so all my child processes */
500
/* look at my terminal as the controlling terminal for the */
501
/* group */
502
503
if(setsid() < 0) {
504
perror("Dissassociating from parents group");
505
exit(-1);
506
}
507
508
close(ptsNum);
509
/* Now reopen the server side, so that pg, su, etc. work properly */
510
511
if ((ptsNum = open(ptsPath, O_RDWR)) < 0 ) {
512
perror("fork_Axiom: Failed to reopen server");
513
exit(-1);
514
}
515
#if defined(SUN4OS5platform) || defined(HP10platform)
516
ioctl(ptsNum,I_PUSH,"ptem");
517
ioctl(ptsNum,I_PUSH,"ldterm");
518
#endif
519
520
/* since I am the child, I can close ptc, and dup pts for all its */
521
/* standard descriptors */
522
523
if( (dup2(ptsNum, 0) == -1) ||
524
(dup2(ptsNum, 1) == -1) ||
525
(dup2(ptsNum, 2) == -1) ) {
526
perror("trying to dupe the child");
527
exit(-1);
528
}
529
close(ptcNum);
530
close(ptsNum);
531
532
533
/* I also have to turn off echoing, since I am echoing all the */
534
/* input myself */
535
536
childbuf.c_lflag &= ~ECHO;
537
if( tcsetattr(0, TCSAFLUSH, &childbuf) == -1) {
538
perror("setting the term buffer");
539
exit(-1);
540
}
541
542
/* Tell the Core that it is being invoked in server mode. */
543
oa_allocate_process_argv(&cmd->core, 2);
544
cmd->core.argv[0] = (char*) make_path_for(cmd->root_dir, Driver::core);
545
cmd->core.argv[1] = (char*) "--role=server";
546
execute_core(cmd, Driver::core);
547
}
548
}
549
550
static void
551
start_the_Axiom(Command* cmd)
552
{
553
server_num = make_server_number();
554
clean_up_old_sockets();
555
if (server_num == -1) {
556
fprintf(stderr, "could not get an OpenAxiom server number\n");
557
exit(-1);
558
}
559
if (ptyopen(&ptcNum, &ptsNum, ptsPath) == -1) {
560
perror("start_the_Axiom: ptyopen failed");
561
exit(-1);
562
}
563
fix_env(server_num);
564
fork_Axiom(cmd);
565
close(ptsNum);
566
}
567
568
static void
569
clean_hypertex_socket(void)
570
{
571
char name[256];
572
sprintf(name, "%s%d", MenuServerName, server_num);
573
unlink(name);
574
}
575
576
static void
577
clean_up_sockets(void)
578
{
579
char name[256];
580
sprintf(name, "%s%d", SpadServer, server_num);
581
unlink(name);
582
sprintf(name, "%s%d", SessionServer, server_num);
583
unlink(name);
584
sprintf(name, "%s%d", SessionIOName, server_num);
585
unlink(name);
586
clean_hypertex_socket();
587
}
588
589
static void
590
read_from_spad_io(int ptcNum)
591
{
592
int ret_code = 0, i=0;
593
static int mes_len =0;
594
ret_code = read(ptcNum, big_bad_buf, BufSize);
595
if (ret_code == -1) {
596
clean_up_sockets();
597
exit(-1);
598
}
599
if (session_io == NULL) {
600
if (ret_code < mes_len)
601
mes_len -= ret_code;
602
else {
603
if (mes_len > 0) {
604
i = mes_len;
605
mes_len = 0;
606
}
607
else
608
i = 0;
609
ret_code = write(1, big_bad_buf+i, ret_code-i);
610
}
611
}
612
else
613
ret_code = swrite(session_io, byte_address(big_bad_buf), ret_code,
614
"writing to session man");
615
if (ret_code == -1) {
616
perror("writing output to session manager");
617
clean_up_sockets();
618
exit(-1);
619
}
620
}
621
622
static void
623
read_from_manager(int ptcNum)
624
{
625
int ret_code;
626
ret_code = sread(session_io, byte_address(big_bad_buf), BufSize,
627
"reading session io");
628
if (ret_code == -1) {
629
return;
630
}
631
ret_code = write(ptcNum, big_bad_buf, ret_code);
632
if (ret_code == -1) {
633
return;
634
}
635
}
636
637
static void
638
manage_spad_io(int ptcNum)
639
{
640
int ret_code, p;
641
fd_set rd;
642
while (1) {
643
rd = socket_mask;
644
FD_SET(ptcNum, &rd);
645
if (session_io != NULL)
646
FD_SET(session_io->socket, &rd);
647
ret_code = sselect(FD_SETSIZE, &rd, 0, 0, NULL);
648
if (ret_code == -1) {
649
perror("Session manager select");
650
clean_up_sockets();
651
exit(-1);
652
}
653
if (FD_ISSET(ptcNum, &rd)) {
654
read_from_spad_io(ptcNum);
655
}
656
if (server.socket > 0 && FD_ISSET(server.socket, &rd)) {
657
p = accept_connection();
658
switch(p) {
659
case SessionIO:
660
session_io = purpose_table[SessionIO];
661
/* printf("connected session manager\n\r");*/
662
printf("\n");
663
break;
664
default:
665
printf("sman: Unknown connection request type: %d\n", p);
666
break;
667
}
668
}
669
if (session_io != NULL && FD_ISSET(session_io->socket, &rd)) {
670
read_from_manager(ptcNum);
671
}
672
}
673
}
674
675
#if 0
676
static void
677
print_spad_process_list()
678
{
679
SpadProcess *proc;
680
for(proc = spad_process_list; proc != NULL; proc = proc->next)
681
fprintf(stderr, "proc_id = %d, death_action = %d\n", proc->proc_id,
682
proc->death_action);
683
}
684
#endif
685
686
static SpadProcess *
687
find_child(int proc_id)
688
{
689
SpadProcess *proc;
690
for(proc = spad_process_list; proc != NULL; proc = proc->next)
691
if (proc->proc_id == proc_id) return proc;
692
return NULL;
693
}
694
695
static void
696
kill_all_children(void)
697
{
698
char name[256];
699
SpadProcess *proc;
700
701
702
for(proc = spad_process_list; proc != NULL; proc = proc->next) {
703
kill(proc->proc_id, SIGTERM);
704
}
705
sprintf(name, "/tmp/hyper%d.input",server_num);
706
unlink(name);
707
708
}
709
710
static void
711
monitor_children(void)
712
{
713
int dead_baby, stat;
714
SpadProcess *proc;
715
while (1) {
716
stat = 0;
717
dead_baby = wait(&stat);
718
/* Check the value of dead_baby, since wait may have returned
719
a pid but subsequently we have received a signal. Yeuch! */
720
if (dead_baby == -1 && death_signal) {
721
kill_all_children();
722
clean_up_sockets();
723
openaxiom_sleep(2);
724
exit(0);
725
}
726
727
if (dead_baby == -1) {
728
fprintf(stderr, "sman: wait returned -1\n");
729
continue;
730
}
731
proc = find_child(dead_baby);
732
if (proc == NULL) {
733
/* fprintf(stderr, "sman: %d is not known to be a child process\n",
734
dead_baby);
735
*/
736
continue;
737
}
738
switch(proc->death_action) {
739
case Die:
740
kill_all_children();
741
clean_up_sockets();
742
openaxiom_sleep(2);
743
exit(0);
744
case NadaDelShitsky:
745
break;
746
case DoItAgain:
747
spawn_of_hell(proc->command, DoItAgain);
748
break;
749
case CleanHypertexSocket:
750
clean_hypertex_socket();
751
break;
752
}
753
}
754
}
755
756
int
757
main(int argc, char *argv[])
758
{
759
Command command;
760
command.root_dir = get_systemdir(argc, argv);
761
process_options(&command, argc, argv);
762
763
oa_setenv("LC_ALL", "C");
764
setlocale(LC_ALL, "");
765
bsdSignal(SIGINT, SIG_IGN,RestartSystemCalls);
766
init_term_io();
767
spad_process_list = NULL;
768
start_the_Axiom(&command);
769
if (open_server(SessionIOName) == -2) {
770
fprintf(stderr, "Fatal error opening I/O socket\n");
771
clean_up_sockets();
772
exit(-1);
773
}
774
start_the_session_manager();
775
if (start_spadclient)
776
start_the_spadclient();
777
if (start_local_spadclient)
778
start_the_local_spadclient();
779
if (start_ht and in_X())
780
start_the_hypertex(&command);
781
if (start_graphics and in_X())
782
start_the_graphics(&command);
783
openaxiom_sleep(1);
784
785
if (fork_you(Die) != NULL) {
786
sman_catch_signals();
787
monitor_children();
788
exit(0);
789
}
790
manage_spad_io(ptcNum);
791
return(0);
792
}
793
794
795
796