134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
** Log backoffice activity to a file named here. If not NULL, this
** overrides the "backoffice-logfile" setting of the database. If NULL,
** the "backoffice-logfile" setting is used instead.
*/
static const char *backofficeLogfile = 0;
/*
** Write backoffice log messages to this connection:
*/
static FILE *backofficeLog = 0;
/*
** Prefix for backoffice log messages
*/
static char *backofficeLogPrefix = 0;
/* End of state variables
****************************************************************************/
/*
** This function emits a diagnostic message related to the processing in
** this module.
|
|
|
|
|
|
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
** Log backoffice activity to a file named here. If not NULL, this
** overrides the "backoffice-logfile" setting of the database. If NULL,
** the "backoffice-logfile" setting is used instead.
*/
static const char *backofficeLogfile = 0;
/*
** Write the log message into this open file.
*/
static FILE *backofficeFILE = 0;
/*
** Write backoffice log messages on this BLOB. to this connection:
*/
static Blob *backofficeBlob = 0;
/* End of state variables
****************************************************************************/
/*
** This function emits a diagnostic message related to the processing in
** this module.
|
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
|
}
/*
** Append to a message to the backoffice log, if the log is open.
*/
void backoffice_log(const char *zFormat, ...){
va_list ap;
if( backofficeLog==0 ) return;
fprintf(backofficeLog, "%s ", backofficeLogPrefix);
va_start(ap, zFormat);
vfprintf(backofficeLog, zFormat, ap);
fflush(backofficeLog);
va_end(ap);
}
#if !defined(_WIN32)
/*
** Capture routine for signals while running backoffice.
*/
static void backoffice_signal_handler(int sig){
const char *zSig = "(unk)";
if( sig==SIGSEGV ) zSig = "SIGSEGV";
if( sig==SIGFPE ) zSig = "SIGFPE";
if( sig==SIGABRT ) zSig = "SIGABRT";
if( sig==SIGILL ) zSig = "SIGILL";
backoffice_log("caught signal %d %s\n", sig, zSig);
exit(1);
}
#endif
#if !defined(_WIN32)
/*
** Convert a struct timeval into an integer number of microseconds
|
|
|
|
<
|
>
>
>
|
>
>
>
|
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
|
}
/*
** Append to a message to the backoffice log, if the log is open.
*/
void backoffice_log(const char *zFormat, ...){
va_list ap;
if( backofficeBlob==0 ) return;
blob_append_char(backofficeBlob, ' ');
va_start(ap, zFormat);
blob_vappendf(backofficeBlob, zFormat, ap);
va_end(ap);
}
#if !defined(_WIN32)
/*
** Capture routine for signals while running backoffice.
*/
static void backoffice_signal_handler(int sig){
const char *zSig = 0;
if( sig==SIGSEGV ) zSig = "SIGSEGV";
if( sig==SIGFPE ) zSig = "SIGFPE";
if( sig==SIGABRT ) zSig = "SIGABRT";
if( sig==SIGILL ) zSig = "SIGILL";
if( zSig==0 ){
backoffice_log("signal-%d", sig);
}else{
backoffice_log("%s", zSig);
}
fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob));
fflush(backofficeFILE);
exit(1);
}
#endif
#if !defined(_WIN32)
/*
** Convert a struct timeval into an integer number of microseconds
|
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
|
** backoffice processing tasks, add them here.
*/
void backoffice_work(void){
/* Log the backoffice run for testing purposes. For production deployments
** the "backoffice-logfile" property should be unset and the following code
** should be a no-op. */
const char *zLog = backofficeLogfile;
int nAlert = 0;
int nSmtp = 0;
#if !defined(_WIN32)
struct timeval sStart, sEnd;
#endif
if( zLog==0 ) zLog = db_get("backoffice-logfile",0);
if( zLog && zLog[0] ){
backofficeLog = fossil_fopen(zLog, "a");
backofficeLogPrefix = mprintf("%d %s",
GETPID(), db_get("project-name","???"));
backoffice_log("start %s\n", db_text(0, "SELECT datetime('now');"));
#if !defined(_WIN32)
gettimeofday(&sStart, 0);
signal(SIGSEGV, backoffice_signal_handler);
signal(SIGABRT, backoffice_signal_handler);
signal(SIGFPE, backoffice_signal_handler);
signal(SIGILL, backoffice_signal_handler);
#endif
}
/* Here is where the actual work of the backoffice happens */
nAlert = alert_backoffice(0);
if( nAlert ) backoffice_log("%d alerts sent\n", nAlert);
nSmtp = smtp_cleanup();
if( nSmtp ) backoffice_log("%d SMTP cleanup ops\n", nSmtp);
/* Close the log */
if( backofficeLog ){
#if !defined(_WIN32)
gettimeofday(&sEnd,0);
backoffice_log("elapse time %d us\n", tvms(&sEnd) - tvms(&sStart));
#endif
fclose(backofficeLog);
}
}
/*
** COMMAND: backoffice*
**
** Usage: backoffice [OPTIONS...] [REPOSITORIES...]
|
>
|
|
|
<
|
|
<
>
>
>
>
>
|
|
|
|
|
>
|
|
|
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
|
** backoffice processing tasks, add them here.
*/
void backoffice_work(void){
/* Log the backoffice run for testing purposes. For production deployments
** the "backoffice-logfile" property should be unset and the following code
** should be a no-op. */
const char *zLog = backofficeLogfile;
Blob log;
int nThis;
int nTotal = 0;
#if !defined(_WIN32)
struct timeval sStart, sEnd;
#endif
if( zLog==0 ) zLog = db_get("backoffice-logfile",0);
if( zLog && zLog[0] && (backofficeFILE = fossil_fopen(zLog,"a"))!=0 ){
int i;
char *zName = db_get("project-name","");
#if !defined(_WIN32)
gettimeofday(&sStart, 0);
signal(SIGSEGV, backoffice_signal_handler);
signal(SIGABRT, backoffice_signal_handler);
signal(SIGFPE, backoffice_signal_handler);
signal(SIGILL, backoffice_signal_handler);
#endif
/* Convert all spaces in the "project-name" into dashes */
for(i=0; zName[i]; i++){ if( zName[i]==' ' ) zName[i] = '-'; }
blob_init(&log, 0, 0);
backofficeBlob = &log;
blob_appendf(&log, "%s %s", db_text(0, "SELECT datetime('now')"), zName);
}
/* Here is where the actual work of the backoffice happens */
nTotal += nThis = alert_backoffice(0);
if( nThis ) backoffice_log("%d alerts", nThis);
nTotal += nThis = smtp_cleanup();
if( nThis ) backoffice_log("%d SMTPs", nThis);
/* Close the log */
if( backofficeFILE ){
if( nTotal==0 ) backoffice_log("no-op");
#if !defined(_WIN32)
gettimeofday(&sEnd,0);
backoffice_log("elapse-time %d us", tvms(&sEnd) - tvms(&sStart));
#endif
fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob));
}
}
/*
** COMMAND: backoffice*
**
** Usage: backoffice [OPTIONS...] [REPOSITORIES...]
|
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
|
/* Not polling and only one repository named. Backoffice is run
** once by this process, which then exits */
if( g.argc==3 ){
g.zRepositoryOption = g.argv[2];
g.argc--;
}
db_find_and_open_repository(0,0);
backoffice_thread();
}
}
/*
** This is the main interface to backoffice from the rest of the system.
** This routine launches either backoffice_thread() directly or as a
** subprocess.
|
>
>
>
|
>
|
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
|
/* Not polling and only one repository named. Backoffice is run
** once by this process, which then exits */
if( g.argc==3 ){
g.zRepositoryOption = g.argv[2];
g.argc--;
}
db_find_and_open_repository(0,0);
if( bDebug ){
backoffice_work();
}else{
backoffice_thread();
}
}
}
/*
** This is the main interface to backoffice from the rest of the system.
** This routine launches either backoffice_thread() directly or as a
** subprocess.
|