-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfile.c
1408 lines (1260 loc) · 40 KB
/
file.c
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
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 Deutches Elektronen-Synchrotron in der Helmholtz-
* Gemelnschaft (DESY).
* Copyright (c) 2002 Berliner Speicherring-Gesellschaft fuer Synchrotron-
* Strahlung mbH (BESSY).
* Copyright (c) 2002 Southeastern Universities Research Association, as
* Operator of Thomas Jefferson National Accelerator Facility.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* This file is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
/* file.c */
/************************DESCRIPTION***********************************
File contains file handling routines
**********************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <Xm/Protocols.h>
#include <Xm/AtomMgr.h>
#include "alh.h"
#ifdef HAVE_SYSV_IPC
#include <sys/msg.h>
#endif
#ifndef CYGWIN32
#ifndef WIN32
/* WIN32 does not have dirent.h used by opendir, closedir */
#include <sys/stat.h>
#include <pwd.h>
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#else
#include <process.h>
#endif
#endif
#include <ctype.h>
#include <Xm/Xm.h>
#include "version.h"
#include "alLib.h"
#include "axArea.h"
#include "ax.h"
/* global variables */
char *programName;
int programId;
/* default file names */
#define DEFAULT_CONFIG "ALH-default.alhConfig"
#define DEFAULT_ALARM "ALH-default.alhAlarm"
#define DEFAULT_OPMOD "ALH-default.alhOpmod"
extern ALINK *alhArea; /* need to group reload in MB-mode*/
struct UserInfo {
char *loginid;
char *real_world_name;
char *myhostname;
char *displayName;
};
struct UserInfo userID;
int _no_error_popup=0; /* No popup window. Error messages logged to opMod file. */
int _global_flag=0; /* Global execution mode. */
int _transients_flag=0; /* Do ca_put of config file value for ackt */
int _main_window_flag=0; /* Flag: Start with main window */
/* Default display filter function */
int (*default_display_filter)(GCLINK *) = alFilterAll;
int _read_only_flag=0; /* Read-only flag. Albert */
int _passive_flag=0; /* Passive flag. Albert */
int _description_field_flag=0;/* Add description into the Log file */
int _printer_flag=0; /* Printer flag. Albert */
int printerMsgQKey; /* Network printer MsgQKey. Albert */
int printerMsgQId; /* Network printer MsgQId. Albert */
int _time_flag=0; /* Dated flag. Albert */
int tm_day_old; /* Day-variable for dated. Albert */
int _DB_call_flag=0; /* Database(Oracle...) call. Albert */
int DBMsgQKey; /* Database MsgQKey. Albert */
int DBMsgQId; /* Database MsgQId. Albert */
int _message_broadcast_flag=0; /* MessBroadcast Sys Albert */
char messBroadcastLockFileName[250]; /* FN for lock file. Albert */
char messBroadcastInfoFileName[250]; /* FN for info file. Albert */
int messBroadcastDeskriptor; /* FD for lock file. Albert */
void broadcastMessTesting();
XtIntervalId broadcastMessTimeoutId=0;
int amIsender=0;
int notsave=0;
const char *rebootString="MIN ALH WILL NOT SAVE ALARM LOG!!!!";
char * reloadMBString = "0 RELOAD_FACILITY: ";
int max_not_save_time=10;
void broadcastMess_exit_quit(int);
unsigned long broadcastMessDelay=2000; /*(msec) periodic mess testing. Albert */
int _lock_flag=0; /* Flag for locking. Albert */
char lockFileName[250]; /* FN for lock file. Albert */
int lockFileDeskriptor; /* FD for lock file. Albert */
unsigned long lockDelay=20000; /* (msec) periodical masterStatus testing. */
int masterFlag=0; /* am I master for write operations? Albert */
/* changed from 1 to 0. Stadler */
void masterTesting(); /* periodical calback of masterStatus testing*/
extern Widget blinkToplevel; /* for locking status marking */
char masterStr[64],slaveStr[64]; /* titles of Master/Slave +- printer/database*/
XtIntervalId lockTimeoutId=0;
extern XFontStruct *font_info;
extern char alhVersionString[100];
#ifdef CMLOG
/* CMLOG flags & variables */
int use_CMLOG_alarm = 0;
int use_CMLOG_opmod = 0;
#endif
int _xml_flag = 0; /* Use XML-ish log format. SNS */
int _mask_color_flag = 0; /* SLS (Andreas Luedeke): if channel/group mask disables sound, then change bg color of mask */
/* this helps to quickly check for all disabled channels, e.g. before an application restart */
extern int DEBUG;
extern int alarmLogFileMaxRecords; /* alarm log file maximum # records */
extern int alarmLogFileOffsetBytes; /* alarm log file current offset in bytes */
extern FILE *fl; /* alarm log pointer */
extern FILE *fo; /* opmod log pointer */
struct command_line_data
{
char* configDir;
char* logDir;
char* lockFileBase; /* Andreas Luedeke */
char* soundFile; /* Andreas Luedeke */
char* configFile;
char* logFile;
char* opModFile;
int alarmLogFileMaxRecords;
};
static struct command_line_data commandLine = {
NULL,NULL,NULL,NULL,NULL,NULL,NULL,0};
#define PARM_DEBUG 0
#define PARM_ACT 1
#define PARM_ALL_FILES_DIR 2
#define PARM_LOG_DIR 3
#define PARM_ALARM_LOG_FILE 4
#define PARM_OPMOD_LOG_FILE 5
#define PARM_ALARM_LOG_MAX 6
#define PARM_DATABASE 7
#define PARM_PRINTER 8
#define PARM_DATED 9
#define PARM_PASSIVE 10
#define PARM_READONLY 11
#define PARM_MESSAGE_BROADCAST 12
#define PARM_SILENT 13
#define PARM_LOCK 14
#define PARM_HELP 15
#define PARM_ALARM_LOG_CMLOG 16
#define PARM_OPMOD_LOG_CMLOG 17
#define PARM_GLOBAL 18
#define PARM_CAPUT_ACK_TRANSIENTS 19
#define PARM_VERSION 20
#define PARM_NO_ERROR_POPUP 21
#define PARM_MAIN_WINDOW 22
#define PARM_ALARM_FILTER 23
#define PARM_DESC_FIELD 24
#define PARM_XML 25
#define PARM_LOCK_FILE 26
#define PARM_SOUND_FILE 27
#define PARM_NOACK_MASK_COLOR 28
struct parm_data
{
char* parm;
int len;
int id;
};
/* order of elements matters: long before short to prevent ambiguity */
static struct parm_data ptable[] = {
#ifdef CMLOG
{ "-aCM", 4, PARM_ALARM_LOG_CMLOG },
#endif
{ "-a", 2, PARM_ALARM_LOG_FILE },
{ "-B", 2, PARM_MESSAGE_BROADCAST }, /* Albert */
{ "-c", 2, PARM_ACT },
{ "-caputackt", 10, PARM_CAPUT_ACK_TRANSIENTS },
{ "-D", 2, PARM_READONLY },
{ "-debug", 6 , PARM_DEBUG },
{ "-desc_field", 11 , PARM_DESC_FIELD },
{ "-f", 2, PARM_ALL_FILES_DIR },
{ "-filter", 7, PARM_ALARM_FILTER },
{ "-global", 7, PARM_GLOBAL },
{ "-help", 5, PARM_HELP },
{ "-L", 2, PARM_LOCK }, /* Albert */
{ "-Lfile", 6, PARM_LOCK_FILE }, /* Andreas Luedeke */
{ "-l", 2, PARM_LOG_DIR },
{ "-m", 2, PARM_ALARM_LOG_MAX },
{ "-mainwindow", 11, PARM_MAIN_WINDOW },
{ "-maskcolor", 10, PARM_NOACK_MASK_COLOR },
{ "-noerrorpopup", 13, PARM_NO_ERROR_POPUP },
{ "-O", 2, PARM_DATABASE }, /* Albert */
{ "-o", 2, PARM_OPMOD_LOG_FILE },
#ifdef CMLOG
{ "-oCM", 4, PARM_OPMOD_LOG_CMLOG },
#endif
{ "-p", 2, PARM_SOUND_FILE },
{ "-P", 2, PARM_PRINTER },
{ "-S", 2, PARM_PASSIVE },
{ "-s", 2, PARM_SILENT },
{ "-T", 2, PARM_DATED },
{ "-v", 2, PARM_VERSION },
{ "-version", 8, PARM_VERSION },
{ "-xml", 4, PARM_XML }, /* SNS */
{ NULL, -1, -1 }};
/* forward declarations */
static void saveConfigFile_callback(Widget widget,char *filename,
XmAnyCallbackStruct *cbs);
static void printUsage(char *);
static void fileSetup(char *filename,ALINK *area,int fileType,int programId,
Widget widget);
static int checkFilename(char *filename,int fileType);
static int getCommandLineParms(int argc, char** argv);
static int getUserInfo();
/***************************************************
exit and quit application
***************************************************/
void exit_quit(Widget w, XtPointer clientdata, XtPointer calldata)
{
struct subWindow *subWindow;
ALINK *area = (ALINK *)clientdata;
GLINK *proot=0;
if(_message_broadcast_flag && amIsender) {
createDialog(blinkToplevel,XmDIALOG_MESSAGE,
"You sent a message\n","Wait a seconds before message will delivery\n");
return;
}
alLogOpModMessage(0,0,"Setup---Exit");
if (fl) { fclose(fl); fl=0; }
if (fo) { fclose(fo); fo=0; }
if (area && area->pmainGroup) proot = area->pmainGroup->p1stgroup;
/*
* note: if pmainGroup or proot == NULL then probably never even fired up initial
* configuration file and ca...
*/
if (proot) {
/* cancel all the channel access requests */
if (programId==ALH) {
alCaCancel(area->pmainGroup);
alCaStop();
}
/* delete all the subgroups of proot & free proot */
alDeleteGroup(proot);
}
if (programId==ACT) editClipboardSet(0,0);
if (area){
if (area->treeWindow){
subWindow=area->treeWindow;
if (subWindow->lines) free(subWindow->lines);
free(area->treeWindow);
}
if (area->groupWindow){
subWindow=area->groupWindow;
if (subWindow->lines) free(subWindow->lines);
free(area->groupWindow);
}
if (area->propWindow) free(area->propWindow);
if (area->forceMaskWindow) free(area->forceMaskWindow);
if (area->forcePVWindow) free(area->forcePVWindow);
if (area->maskWindow) free(area->maskWindow);
if (area->beepSevrWindow) free(area->beepSevrWindow);
if (area->noAckWindow) free(area->noAckWindow);
alHeartbeatPVRemove(area->pmainGroup);
if (area->pmainGroup) free(area->pmainGroup);
free(area);
}
XtDestroyWidget(topLevelShell);
XtDestroyWidget(w);
XFreeFont(display,font_info);
#ifndef CYGWIN32
#ifndef WIN32
if (masterFlag) {
lockf(lockFileDeskriptor,F_ULOCK, 0L);
if (lockTimeoutId) {
XtRemoveTimeOut(lockTimeoutId);
}
}
if(_lock_flag) {
/* Moved to above part. Stadler
lockf(lockFileDeskriptor,F_ULOCK, 0L);
if (lockTimeoutId) {
XtRemoveTimeOut(lockTimeoutId);
}
*/
if(_message_broadcast_flag) {
lockf(messBroadcastDeskriptor, F_ULOCK, 0L); /* Albert */
if (broadcastMessTimeoutId) {
XtRemoveTimeOut(broadcastMessTimeoutId);
}
}
}
#endif
#endif
#ifdef CMLOG
if (use_CMLOG_alarm || use_CMLOG_opmod) alCMLOGdisconnect();
#endif
exit(0);
}
/******************************************************
shorten file name without path
******************************************************/
char *shortfile(char *name)
{
size_t len;
char *shortname;
len = strlen(name);
shortname = name;
while (len != 0) {
if(*(name+len)== '/') {
shortname = name+len+1;
break;
}
len--;
}
return shortname;
}
/******************************************************
checkFilename
******************************************************/
static int checkFilename(char *filename,int fileType)
{
FILE *tt = 0;
if ( filename[0] == '\0') return 2;
if ( DEBUG == 1 )
printf("\nFilename is %s \n", filename);
switch (fileType) {
case FILE_CONFIG:
case FILE_CONFIG_INSERT:
tt = fopen(filename,"r");
if (!tt){
return 2;
}
break;
case FILE_SAVEAS:
tt = fopen(filename,"r");
if (tt){
return 3;
}
case FILE_SAVE:
case FILE_SAVEAS_OK:
case FILE_PRINT:
tt = fopen(filename,"w");
if (!tt){
return 4;
}
break;
case FILE_OPMOD:
case FILE_ALARMLOG:
if(!_read_only_flag) tt = fopen(filename,"a");
else {
tt = fopen(filename,"r");
if(!tt)
{
strcpy(filename,"/tmp/AlhDisableWriting");
chmod("/tmp/AlhDisableWriting",0777);
tt = fopen(filename,"w");
if (!tt) {
fprintf(stderr,"can't read OPMOD or ALARMLOG and /tmp directory \n");
exit(1);
}
}
}
if (!tt){
return 4;
}
break;
}
if (tt) fclose(tt);
return 0;
}
/******************************************************
fileCancelCallback
******************************************************/
void fileCancelCallback(Widget widget,ALINK *area,
XmFileSelectionBoxCallbackStruct *cbs)
{
area->managed = TRUE;
XtUnmanageChild(widget);
}
/******************************************************
fileSetupCallback
******************************************************/
void fileSetupCallback(Widget widget,int client_data,
XmFileSelectionBoxCallbackStruct *cbs)
{
char *filename;
ALINK *area;
int pgm;
/* get the filename string */
XmStringGetLtoR(cbs->value, XmSTRING_DEFAULT_CHARSET, &filename);
if ( DEBUG == 1 )
printf("\nfileSetupCallback: filename is %s \n", filename);
/* get the area pointer */
XtVaGetValues(widget, XmNuserData, &area, NULL);
if (area) pgm = area->programId;
else pgm = programId;
fileSetup(filename,area,client_data,pgm,widget);
XtFree(filename);
}
/******************************************************
fileSetup
******************************************************/
static void fileSetup(char *filename,ALINK *area,int fileType,
int programId,Widget widget)
{
int error;
char fileTypeString[NAMEDEFAULT_SIZE];
char str[MAX_STRING_LENGTH];
char *dir=0;
char *pattern=0;
char *filename_dup;
FILE *tt;
Widget fileSelectionBox;
time_t timeofday;
struct tm *tms;
char buf[16];
/* _______ For Dated AlLog File. Albert______________________________*/
timeofday = time(0L);
tms = localtime(&timeofday);
sprintf(buf,".%.4d-%.2d-%.2d",
1900+tms->tm_year,1+tms->tm_mon,tms->tm_mday);
buf[11]=0;
tm_day_old = tms->tm_mday;
if ( ((fileType == FILE_ALARMLOG)||(fileType == FILE_OPMOD))&&(_time_flag) )
{
strncat(filename, &buf[0], strlen(buf));
}
/* _______ End. Albert______________________________*/
error = checkFilename(filename,fileType);
if (error){
switch(fileType) {
case FILE_CONFIG:
case FILE_CONFIG_INSERT:
pattern = CONFIG_PATTERN;
dir = psetup.configDir;
if (programId == ALH) {
strcpy(fileTypeString,"Alarm Handler: Alarm Configuration File");
} else {
/* not error to start act with no filename */
if ( filename[0] == '\0' && fileType == FILE_CONFIG ) error = 0;
strcpy(fileTypeString,"Alarm Configuration Tool: Alarm Configuration File");
}
break;
case FILE_OPMOD:
pattern = OPMOD_PATTERN;
dir = psetup.logDir;
strcpy(fileTypeString,"OpMod Log File");
break;
case FILE_ALARMLOG:
pattern = ALARMLOG_PATTERN;
dir = psetup.logDir;
strcpy(fileTypeString,"Alarm Log File");
break;
case FILE_PRINT:
pattern = TREEREPORT_PATTERN;
dir = NULL;
strcpy(fileTypeString,"Print File");
break;
default:
pattern = '\0';
dir = psetup.configDir;
strcpy(fileTypeString,"Filename");
break;
}
}
if (error){
fileSelectionBox = widget;
/* Display file selection box */
if (widget && XtIsShell(widget)) {
long fileTypeLong=fileType;
Atom WM_DELETE_WINDOW;
fileSelectionBox = createFileDialog(widget,
(void *)fileSetupCallback, (XtPointer)fileTypeLong,
(void *)exit_quit,(XtPointer)FALSE,
(XtPointer)NULL,
fileTypeString, (String)pattern, dir);
WM_DELETE_WINDOW = XmInternAtom(XtDisplay(fileSelectionBox),
"WM_DELETE_WINDOW", False);
XmAddWMProtocolCallback(XtParent(fileSelectionBox),WM_DELETE_WINDOW,
(XtCallbackProc)exit_quit,(XtPointer)FALSE );
}
/* Display file error dialog */
switch (error){
case 1:
createDialog(fileSelectionBox,XmDIALOG_ERROR,filename," is a directory.");
break;
case 2:
/* no warning if DEFAULT filename does not exist */
if ( strcmp(shortfile(filename),DEFAULT_CONFIG) )
createDialog(fileSelectionBox,XmDIALOG_ERROR,filename," open error.");
break;
case 3:
strcpy(str, filename);
strcat(str," already exists. Overwrite?");
filename_dup = malloc(strlen(filename)+1);
if ( filename_dup ) strcpy(filename_dup,filename);
createActionDialog(fileSelectionBox,XmDIALOG_WARNING, str ,
(XtCallbackProc)saveConfigFile_callback,
(XtPointer)filename_dup,(XtPointer)area);
break;
case 4:
errMsg("Error opening file %s\n",filename);
switch(fileType) {
case FILE_ALARMLOG:
errMsg("WARNING: Continuing without Alarm Log file\n");
break;
case FILE_OPMOD:
errMsg("WARNING: Continuing without OpMod Log file\n");
break;
default:
break;
}
break;
default:
break;
}
} else {
/* unmanage the fileSelection dialog */
if (widget && !XtIsShell(widget))
createFileDialog(0,0,0,0,0,0,0,0,0);
switch(fileType) {
case FILE_CONFIG:
#ifdef CMLOG
if (use_CMLOG_alarm || use_CMLOG_opmod) alCMLOGconnect();
#endif
setupConfig(filename,programId,area);
if(_lock_flag) /* Albert */
{
FILE *fp;
strcpy(lockFileName,psetup.lockFileBase); /* Andreas Luedeke */
strcat(lockFileName,".LOCK"); /* allow lock to be generated outside logdir */
if (!(fp=fopen(lockFileName,"a")))
{
perror("Can't open locking file for a");
exit(1);
}
fclose(fp);
#ifndef CYGWIN32
#ifndef WIN32
if((lockFileDeskriptor=open(lockFileName,O_RDWR,0644)) == 0)
{
perror("Can't open locking file for rw");
exit(1);
}
#endif
#endif
if (DEBUG) fprintf(stderr,"INIT: deskriptor for %s=%d\n",
lockFileName,lockFileDeskriptor);
strcpy(masterStr,"Master");
strcpy(slaveStr, "Slave");
if(_printer_flag) {
strcat(masterStr,"+printer");
strcat(slaveStr, "+printer");
}
if(_DB_call_flag) {
strcat(masterStr,"+Oracle");
strcat(slaveStr, "+Oracle");
}
if(_message_broadcast_flag) {
strcat(masterStr,"+Message");
strcat(slaveStr, "+Message");
}
masterTesting(); /* Albert */
}
if(_message_broadcast_flag) /* Albert */
{
FILE *fpL, *fpI;
strcpy(messBroadcastLockFileName,psetup.configFile);
strcat(messBroadcastLockFileName,".MESSLOCK");
strcpy(messBroadcastInfoFileName,psetup.configFile);
strcat(messBroadcastInfoFileName,".MESS");
if ( (!(fpL=fopen(messBroadcastLockFileName,"a")))
|| (!(fpI=fopen(messBroadcastInfoFileName,"a"))) )
{
perror("Can't open messBroadcast file for a");
exit(1);
}
fclose(fpL);
fclose(fpI);
#ifndef CYGWIN32
#ifndef WIN32
if((messBroadcastDeskriptor=
open(messBroadcastLockFileName,O_RDWR,0644)) == 0)
{
perror("Can't open messBroadcast file for rw");
exit(1);
}
#endif
#endif
if (DEBUG) fprintf(stderr,"INIT: deskriptor for %s=%d\n",
messBroadcastLockFileName,messBroadcastDeskriptor);
broadcastMessTesting(widget);
signal(SIGINT,broadcastMess_exit_quit);
}
#ifdef HAVE_SYSV_IPC
if( _printer_flag)
{
struct msqid_ds buf;
printerMsgQId = msgget (printerMsgQKey, 0600|IPC_CREAT);
if(printerMsgQId == -1) {perror("printer:msgQ_create"); exit(1);}
else {
if(DEBUG) fprintf(stderr,"printerMsgQ with key=%d is OK\n",
printerMsgQKey);
if (msgctl(printerMsgQId,IPC_STAT,&buf) != 1)
{
if(DEBUG)fprintf(stderr,"printer:o=%d.%d,perm=%04o,max byte=%ld\n",
buf.msg_perm.uid,buf.msg_perm.gid,
buf.msg_perm.mode,
buf.msg_qbytes);
if(DEBUG) fprintf(stderr,"printer:%ld msgs = %ld bytes on queue\n",
buf.msg_qnum, buf.msg_cbytes);
}
else {perror("printer:msgctl()"); exit(1);}
}
}
if( _DB_call_flag)
{
struct msqid_ds buf;
DBMsgQId = msgget (DBMsgQKey, 0600|IPC_CREAT);
if(DBMsgQId == -1) {perror("DB:msgQ_create"); exit(1);}
else {
if(DEBUG) fprintf(stderr,"DB:msgQ with key=%d is OK\n",
DBMsgQKey);
if (msgctl(DBMsgQId,IPC_STAT,&buf) != 1)
{
if(DEBUG)fprintf(stderr,"DB:o=%d.%d,perm=%04o,max byte=%ld\n",
buf.msg_perm.uid,buf.msg_perm.gid,
buf.msg_perm.mode,
buf.msg_qbytes);
if(DEBUG) fprintf(stderr,"DB:%ld msgs = %ld bytes on queue\n",
buf.msg_qnum, buf.msg_cbytes);
}
else {perror("DB:msgctl()"); exit(1);}
}
}
#endif
break;
case FILE_ALARMLOG:
alLogOpModMessage(0,0,"Setup Alarm Log File : %s",filename);
strcpy(psetup.logFile,filename);
if (fl) fclose(fl); /* RO-flag. Albert */
if(_read_only_flag) fl = fopen(psetup.logFile,"r");
else if((_time_flag)||(_lock_flag)) fl = fopen(psetup.logFile,"a");
else fl = fopen(psetup.logFile,"w+");
if (!fl) perror("CAN'T OPEN ALARM LOG FILE"); /* Albert */
if (!fl) errMsg("CAN'T OPEN ALARM LOG FILE");
if (alarmLogFileMaxRecords) alarmLogFileOffsetBytes = 0;
break;
case FILE_OPMOD:
alLogOpModMessage(0,0,"Setup OpMod File : %s",filename);
strcpy(psetup.opModFile,filename);
if (fo) fclose(fo);
if(!_read_only_flag) fo=fopen(psetup.opModFile,"a");
/* RO-option. Albert */
else fo=fopen(psetup.opModFile,"r");
if (!fo) perror("CAN'T OPEN OPMOD LOG FILE"); /* Albert */
if (!fo) errMsg("CAN'T OPEN OPMOD LOG FILE");
break;
case FILE_SAVEAS:
case FILE_SAVE:
filename_dup = malloc(strlen(filename)+1);
if ( filename_dup ) strcpy(filename_dup,filename);
saveConfigFile_callback(widget,filename_dup,(void *)NULL);
break;
case FILE_PRINT:
tt = fopen(filename,"w");
alPrintConfig(tt,area->pmainGroup);
fclose(tt);
break;
case FILE_CONFIG_INSERT:
editInsertFile(filename,area);
break;
}
}
}
/******************************************************
saveConfigFile_callback
******************************************************/
static void saveConfigFile_callback(Widget widget,char *filename,
XmAnyCallbackStruct *cbs)
{
ALINK *area;
XtVaGetValues(widget, XmNuserData, &area, NULL);
alLogOpModMessage(0,0,"Setup Save New Config: %s",filename);
if ( DEBUG == 1 )
printf("\nSaving Config File to %s \n", filename);
alWriteConfig(filename,area->pmainGroup);
/* unmanage the warning dialog */
XtUnmanageChild(widget);
/* unmanage the fileSelection dialog */
createFileDialog(0,0,0,0,0,0,0,0,0);
/* Free the filename string copy */
free(filename);
}
/******************************************************
getCommandLineParms
******************************************************/
static int getCommandLineParms(int argc, char** argv)
{
int i,j;
int finished=0;
int parm_error=0;
FILE *fp;
alarmLogFileMaxRecords=commandLine.alarmLogFileMaxRecords=2000; /* Albert */
for(i=1;i<argc && !parm_error;i++)
{
for(j=0;!finished && !parm_error && ptable[j].parm;j++)
{
if(strncmp(ptable[j].parm,argv[i],Mmax(ptable[j].len,strlen(argv[i])))==0)
{
switch(ptable[j].id)
{
case PARM_DEBUG:
DEBUG = TRUE;
finished=1;
break;
case PARM_ACT:
strcpy(programName,"act");
programId = ACT;
finished=1;
break;
case PARM_SILENT:
psetup.silenceForever=TRUE;
finished=1;
break;
case PARM_ALL_FILES_DIR:
if(++i>=argc) parm_error=1;
else
{
if(argv[i][0]=='-') parm_error=2;
else
{
commandLine.configDir=argv[i];
finished=1;
}
}
break;
case PARM_LOG_DIR:
if(++i>=argc) parm_error=1;
else
{
if(argv[i][0]=='-') parm_error=2;
else
{
commandLine.logDir=argv[i];
finished=1;
}
}
break;
case PARM_ALARM_LOG_FILE:
if(++i>=argc) parm_error=1;
else
{
if(argv[i][0]=='-') parm_error=2;
else
{
commandLine.logFile=argv[i];
finished=1;
}
}
break;
case PARM_OPMOD_LOG_FILE:
if(++i>=argc) parm_error=1;
else
{
if(argv[i][0]=='-') parm_error=2;
else
{
commandLine.opModFile=argv[i];
finished=1;
}
}
break;
case PARM_ALARM_FILTER:
if(++i>=argc) parm_error=1;
else
{
if (argv[i][0] == 'a') {
default_display_filter = alFilterAlarmsOnly;
finished = 1;
} else if (argv[i][0] == 'u') {
default_display_filter = alFilterUnackAlarmsOnly;
finished = 1;
} else if (argv[i][0] == 'n') {
default_display_filter = alFilterAll;
finished = 1;
} else parm_error=2;
}
break;
#ifdef CMLOG
case PARM_ALARM_LOG_CMLOG:
use_CMLOG_alarm = 1;
finished=1;
break;
case PARM_OPMOD_LOG_CMLOG:
use_CMLOG_opmod = 1;
finished=1;
break;
#endif
case PARM_ALARM_LOG_MAX:
if(++i>=argc) parm_error=1;
else
{
if(argv[i][0]=='-') parm_error=2;
else
{
commandLine.alarmLogFileMaxRecords=atoi(argv[i]);
if( (!commandLine.alarmLogFileMaxRecords)&&(strcmp(argv[i],"0") )) parm_error=2;
alarmLogFileMaxRecords=commandLine.alarmLogFileMaxRecords;
finished=1;
}
}
break;
case PARM_PRINTER: /* Printer parameters. Albert */
if(++i>=argc) parm_error=1;
else
{
if(argv[i][0]=='-') parm_error=2;
else
{
printerMsgQKey=atoi(argv[i]);
if(!printerMsgQKey) parm_error=2;
_printer_flag=1;
finished=1;
}
}
break;
case PARM_DATED:
_time_flag=1; /* Dated-option. Albert */
finished=1;
break;
case PARM_PASSIVE:
/*_read_only_flag=1;*/ /* Passive-option. Albert */
_passive_flag=1;
finished=1;
break;
case PARM_READONLY:
_read_only_flag=1; /* RO-option. Albert */
finished=1;
break;
case PARM_LOCK:
_lock_flag=1; /* locking system. Albert */
finished=1;
break;
case PARM_DATABASE: /* DATABASE-option. Albert */
if(++i>=argc) parm_error=1;
else
{
if(argv[i][0]=='-') parm_error=2;
else
{
DBMsgQKey=atoi(argv[i]);
if(!DBMsgQKey) parm_error=2;
_DB_call_flag=1;
finished=1;
}
}
break;
case PARM_MESSAGE_BROADCAST:
_message_broadcast_flag=1;/* Mess. Broadcast Albert */
finished=1;
break;
case PARM_MAIN_WINDOW:
_main_window_flag=1;
finished=1;
break;
case PARM_NO_ERROR_POPUP:
_no_error_popup=1;
finished=1;
break;
case PARM_GLOBAL:
_global_flag=1;
finished=1;
break;
case PARM_CAPUT_ACK_TRANSIENTS:
_transients_flag=1;
finished=1;
break;
case PARM_HELP:
printUsage(argv[0]);
finished=1;
break;
case PARM_VERSION:
fprintf(stderr,"%s\n",alhVersionString);
exit(1);
break;
case PARM_DESC_FIELD:
_description_field_flag=1;
finished=1;
break;
case PARM_XML: /* SNS */
_xml_flag=1;
finished=1;
break;
case PARM_LOCK_FILE: /* Andreas Luedeke: place .LOCK file in special directory */
if(++i>=argc) parm_error=1;
else
{
if(argv[i][0]=='-') parm_error=2;
else
{