| ︙ | | | ︙ | |
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
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.
*/
|
>
>
>
>
>
|
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
static FILE *backofficeFILE = 0;
/*
** Write backoffice log messages on this BLOB. to this connection:
*/
static Blob *backofficeBlob = 0;
/*
** Non-zero for extra logging detail.
*/
static int backofficeLogDetail = 0;
/* End of state variables
****************************************************************************/
/*
** This function emits a diagnostic message related to the processing in
** this module.
*/
|
| ︙ | | | ︙ | |
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
|
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 */
nThis = alert_backoffice(0);
if( nThis ){ backoffice_log("%d alerts", nThis); nTotal += nThis; }
nThis = smtp_cleanup();
if( nThis ){ backoffice_log("%d SMTPs", nThis); nTotal += 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...]
|
|
>
>
>
>
|
|
>
>
|
|
|
|
>
>
|
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
|
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",0);
#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
if( zName==0 ){
zName = (char*)file_tail(g.zRepositoryName);
if( zName==0 ) zName = "(unnamed)";
}else{
/* 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 */
nThis = alert_backoffice(0);
if( nThis ){ backoffice_log("%d alerts", nThis); nTotal += nThis; }
nThis = smtp_cleanup();
if( nThis ){ backoffice_log("%d SMTPs", nThis); nTotal += nThis; }
/* Close the log */
if( backofficeFILE ){
if( nTotal || backofficeLogDetail ){
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));
}
fclose(backofficeFILE);
}
}
/*
** COMMAND: backoffice*
**
** Usage: backoffice [OPTIONS...] [REPOSITORIES...]
|
| ︙ | | | ︙ | |
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
|
** on collection of repositories.
**
** If only a single repository is named and --poll is omitted, the the
** backoffice work is done in-process. But if there are multiple respositories
** or if --poll is used, a separate sub-process is started for each poll of
** each repository.
**
** OPTIONS:
**
** --debug Show what this command is doing.
**
** --logfile FILE Append a log of backoffice actions onto FILE.
**
** --min N When polling, invoke backoffice at least
** once every N seconds even if the repository
** never changes. 0 or negative means disable
** this feature. Default: 3600 (once per hour).
**
** --nodelay Do not queue up or wait for a backoffice job
** to complete. If no work is available or if
** backoffice has run recently, return immediately.
** The --nodelay option is implied if more than
** one repository is listed on the command-line.
**
** --poll N Repeat backoffice calls for repositories that
** change in appoximately N-second intervals.
** N less than 1 turns polling off (the default).
** Recommended polling interval: 60 seconds.
**
** --trace Enable debugging output on stderr
*/
void backoffice_command(void){
int nPoll;
int nMin;
const char *zPoll;
int bDebug = 0;
unsigned int nCmd = 0;
if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1;
if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1;
backofficeLogfile = find_option("logfile",0,1);
zPoll = find_option("poll",0,1);
nPoll = zPoll ? atoi(zPoll) : 0;
zPoll = find_option("min",0,1);
nMin = zPoll ? atoi(zPoll) : 3600;
bDebug = find_option("debug",0,0)!=0;
/* Silently consume the -R or --repository flag, leaving behind its
** argument. This is for legacy compatibility. Older versions of the
** backoffice command only ran on a single repository that was specified
** using the -R option. */
(void)find_option("repository","R",0);
|
|
<
<
>
>
>
>
>
>
>
>
|
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
|
** on collection of repositories.
**
** If only a single repository is named and --poll is omitted, the the
** backoffice work is done in-process. But if there are multiple respositories
** or if --poll is used, a separate sub-process is started for each poll of
** each repository.
**
** Standard options:
**
** --debug Show what this command is doing.
**
** --logfile FILE Append a log of backoffice actions onto FILE.
**
** --min N When polling, invoke backoffice at least
** once every N seconds even if the repository
** never changes. 0 or negative means disable
** this feature. Default: 3600 (once per hour).
**
** --nodelay Do not queue up or wait for a backoffice job
** to complete. If no work is available or if
** backoffice has run recently, return immediately.
**
** --poll N Repeat backoffice calls for repositories that
** change in appoximately N-second intervals.
** N less than 1 turns polling off (the default).
** Recommended polling interval: 60 seconds.
**
** --trace Enable debugging output on stderr
**
** Options intended for internal use only which may change or be
** discontinued in a future release:
**
** --nolease Always run backoffice, even if there is a lease
** conflict. This option implies --nodelay.
*/
void backoffice_command(void){
int nPoll;
int nMin;
const char *zPoll;
int bDebug = 0;
int bNoLease = 0;
unsigned int nCmd = 0;
if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1;
if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1;
backofficeLogfile = find_option("logfile",0,1);
zPoll = find_option("poll",0,1);
nPoll = zPoll ? atoi(zPoll) : 0;
zPoll = find_option("min",0,1);
nMin = zPoll ? atoi(zPoll) : 3600;
bDebug = find_option("debug",0,0)!=0;
bNoLease = find_option("nolease",0,0)!=0;
/* Silently consume the -R or --repository flag, leaving behind its
** argument. This is for legacy compatibility. Older versions of the
** backoffice command only ran on a single repository that was specified
** using the -R option. */
(void)find_option("repository","R",0);
|
| ︙ | | | ︙ | |
719
720
721
722
723
724
725
726
727
728
729
730
731
732
|
}
blob_init(&cmd, 0, 0);
blob_append_escaped_arg(&cmd, g.nameOfExe);
blob_append(&cmd, " backoffice --nodelay", -1);
if( g.fAnyTrace ){
blob_append(&cmd, " --trace", -1);
}
blob_append_escaped_arg(&cmd, g.argv[i]);
nCmd++;
if( bDebug ){
fossil_print("COMMAND[%u]: %s\n", nCmd, blob_str(&cmd));
}
fossil_system(blob_str(&cmd));
aLastRun[i] = iNext;
|
>
>
>
>
>
>
>
>
>
>
|
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
|
}
blob_init(&cmd, 0, 0);
blob_append_escaped_arg(&cmd, g.nameOfExe);
blob_append(&cmd, " backoffice --nodelay", -1);
if( g.fAnyTrace ){
blob_append(&cmd, " --trace", -1);
}
if( bDebug ){
blob_append(&cmd, " --debug", -1);
}
if( nPoll>0 ){
blob_append(&cmd, " --nolease", -1);
}
if( backofficeLogfile ){
blob_append(&cmd, " --logfile", -1);
blob_append_escaped_arg(&cmd, backofficeLogfile);
}
blob_append_escaped_arg(&cmd, g.argv[i]);
nCmd++;
if( bDebug ){
fossil_print("COMMAND[%u]: %s\n", nCmd, blob_str(&cmd));
}
fossil_system(blob_str(&cmd));
aLastRun[i] = iNext;
|
| ︙ | | | ︙ | |
746
747
748
749
750
751
752
753
754
755
756
757
758
759
|
** 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();
}
}
}
|
>
>
>
|
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
|
** 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 ){
backofficeLogDetail = 1;
}
if( bNoLease ){
backoffice_work();
}else{
backoffice_thread();
}
}
}
|
| ︙ | | | ︙ | |