Fossil SCM

Make the backoffice module tracing behave more consistently on Win32.

mistachkin 2018-08-07 23:48 trunk
Commit 0fe9da816feba1bc9455cce2b3d8a120718e727462011a70a67b9c1154f2cf2f
1 file changed +36 -26
+36 -26
--- src/backoffice.c
+++ src/backoffice.c
@@ -117,10 +117,34 @@
117117
*/
118118
static char *backofficeDb = 0;
119119
120120
/* End of state variables
121121
****************************************************************************/
122
+
123
+/*
124
+** This function emits a diagnostic message related to the processing in
125
+** this module.
126
+*/
127
+#if defined(_WIN32)
128
+# define BKOFCE_ALWAYS_TRACE (1)
129
+#else
130
+# define BKOFCE_ALWAYS_TRACE (0)
131
+#endif
132
+static void backofficeTrace(const char *zFormat, ...){
133
+ char *zMsg = 0;
134
+ if( BKOFCE_ALWAYS_TRACE || g.fAnyTrace ){
135
+ va_list ap;
136
+ va_start(ap, zFormat);
137
+ zMsg = sqlite3_vmprintf(zFormat, ap);
138
+ va_end(ap);
139
+#if defined(_WIN32)
140
+ sqlite3_win32_write_debug(zMsg, -1);
141
+#endif
142
+ }
143
+ if( g.fAnyTrace ) fprintf(stderr, "%s", zMsg);
144
+ if( zMsg ) sqlite3_free(zMsg);
145
+}
122146
123147
/*
124148
** Do not allow backoffice processes to sleep waiting on a timeslot.
125149
** They must either do their work immediately or exit.
126150
**
@@ -446,14 +470,12 @@
446470
x.tmCurrent = tmNow + BKOFCE_LEASE_TIME;
447471
x.idNext = 0;
448472
x.tmNext = 0;
449473
backofficeWriteLease(&x);
450474
db_end_transaction(0);
451
- if( g.fAnyTrace ){
452
- fprintf(stderr, "/***** Begin Backoffice Processing %d *****/\n",
453
- GETPID());
454
- }
475
+ backofficeTrace("/***** Begin Backoffice Processing %d *****/\n",
476
+ GETPID());
455477
backoffice_work();
456478
break;
457479
}
458480
if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",0) ){
459481
/* If the no-delay flag is set, exit immediately rather than queuing
@@ -466,19 +488,15 @@
466488
** to expire before continuing. */
467489
x.idNext = idSelf;
468490
x.tmNext = (tmNow>x.tmCurrent ? tmNow : x.tmCurrent) + BKOFCE_LEASE_TIME;
469491
backofficeWriteLease(&x);
470492
db_end_transaction(0);
471
- if( g.fAnyTrace ){
472
- fprintf(stderr, "/***** Backoffice On-deck %d *****/\n", GETPID());
473
- }
493
+ backofficeTrace("/***** Backoffice On-deck %d *****/\n", GETPID());
474494
if( x.tmCurrent >= tmNow ){
475495
if( backofficeSleep(1000*(x.tmCurrent - tmNow + 1)) ){
476496
/* The sleep was interrupted by a signal from another thread. */
477
- if( g.fAnyTrace ){
478
- fprintf(stderr, "/***** Backoffice Interrupt %d *****/\n", GETPID());
479
- }
497
+ backofficeTrace("/***** Backoffice Interrupt %d *****/\n", GETPID());
480498
db_end_transaction(0);
481499
break;
482500
}
483501
}else{
484502
if( lastWarning+warningDelay < tmNow ){
@@ -488,13 +506,11 @@
488506
lastWarning = tmNow;
489507
warningDelay *= 2;
490508
}
491509
if( backofficeSleep(1000) ){
492510
/* The sleep was interrupted by a signal from another thread. */
493
- if( g.fAnyTrace ){
494
- fprintf(stderr, "/***** Backoffice Interrupt %d *****/\n", GETPID());
495
- }
511
+ backofficeTrace("/***** Backoffice Interrupt %d *****/\n", GETPID());
496512
db_end_transaction(0);
497513
break;
498514
}
499515
}
500516
}
@@ -563,39 +579,33 @@
563579
argv[3] = backofficeDb;
564580
ax[4] = 0;
565581
for(i=0; i<=3; i++) ax[i] = fossil_utf8_to_unicode(argv[i]);
566582
x = _wspawnv(_P_NOWAIT, ax[0], (const wchar_t * const *)ax);
567583
for(i=0; i<=3; i++) fossil_unicode_free(ax[i]);
568
- if( g.fAnyTrace ){
569
- fprintf(stderr,
570
- "/***** Subprocess %d creates backoffice child %d *****/\n",
571
- GETPID(), (int)x);
572
- }
584
+ backofficeTrace(
585
+ "/***** Subprocess %d creates backoffice child %d *****/\n",
586
+ GETPID(), (int)x);
573587
if( x>=0 ) return;
574588
}
575589
#else /* unix */
576590
{
577591
pid_t pid = fork();
578592
if( pid>0 ){
579593
/* This is the parent in a successful fork(). Return immediately. */
580
- if( g.fAnyTrace ){
581
- fprintf(stderr,
582
- "/***** Subprocess %d creates backoffice child %d *****/\n",
583
- GETPID(), (int)pid);
584
- }
594
+ backofficeTrace(
595
+ "/***** Subprocess %d creates backoffice child %d *****/\n",
596
+ GETPID(), (int)pid);
585597
return;
586598
}
587599
if( pid==0 ){
588600
/* This is the child of a successful fork(). Run backoffice. */
589601
setsid();
590602
db_open_repository(backofficeDb);
591603
backofficeDb = "x";
592604
backoffice_thread();
593605
db_close(1);
594
- if( g.fAnyTrace ){
595
- fprintf(stderr, "/***** Backoffice Child %d exits *****/\n", GETPID());
596
- }
606
+ backofficeTrace("/***** Backoffice Child %d exits *****/\n", GETPID());
597607
exit(0);
598608
}
599609
}
600610
#endif
601611
/* Fork() failed or is unavailable. Run backoffice in this process, but
602612
--- src/backoffice.c
+++ src/backoffice.c
@@ -117,10 +117,34 @@
117 */
118 static char *backofficeDb = 0;
119
120 /* End of state variables
121 ****************************************************************************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
123 /*
124 ** Do not allow backoffice processes to sleep waiting on a timeslot.
125 ** They must either do their work immediately or exit.
126 **
@@ -446,14 +470,12 @@
446 x.tmCurrent = tmNow + BKOFCE_LEASE_TIME;
447 x.idNext = 0;
448 x.tmNext = 0;
449 backofficeWriteLease(&x);
450 db_end_transaction(0);
451 if( g.fAnyTrace ){
452 fprintf(stderr, "/***** Begin Backoffice Processing %d *****/\n",
453 GETPID());
454 }
455 backoffice_work();
456 break;
457 }
458 if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",0) ){
459 /* If the no-delay flag is set, exit immediately rather than queuing
@@ -466,19 +488,15 @@
466 ** to expire before continuing. */
467 x.idNext = idSelf;
468 x.tmNext = (tmNow>x.tmCurrent ? tmNow : x.tmCurrent) + BKOFCE_LEASE_TIME;
469 backofficeWriteLease(&x);
470 db_end_transaction(0);
471 if( g.fAnyTrace ){
472 fprintf(stderr, "/***** Backoffice On-deck %d *****/\n", GETPID());
473 }
474 if( x.tmCurrent >= tmNow ){
475 if( backofficeSleep(1000*(x.tmCurrent - tmNow + 1)) ){
476 /* The sleep was interrupted by a signal from another thread. */
477 if( g.fAnyTrace ){
478 fprintf(stderr, "/***** Backoffice Interrupt %d *****/\n", GETPID());
479 }
480 db_end_transaction(0);
481 break;
482 }
483 }else{
484 if( lastWarning+warningDelay < tmNow ){
@@ -488,13 +506,11 @@
488 lastWarning = tmNow;
489 warningDelay *= 2;
490 }
491 if( backofficeSleep(1000) ){
492 /* The sleep was interrupted by a signal from another thread. */
493 if( g.fAnyTrace ){
494 fprintf(stderr, "/***** Backoffice Interrupt %d *****/\n", GETPID());
495 }
496 db_end_transaction(0);
497 break;
498 }
499 }
500 }
@@ -563,39 +579,33 @@
563 argv[3] = backofficeDb;
564 ax[4] = 0;
565 for(i=0; i<=3; i++) ax[i] = fossil_utf8_to_unicode(argv[i]);
566 x = _wspawnv(_P_NOWAIT, ax[0], (const wchar_t * const *)ax);
567 for(i=0; i<=3; i++) fossil_unicode_free(ax[i]);
568 if( g.fAnyTrace ){
569 fprintf(stderr,
570 "/***** Subprocess %d creates backoffice child %d *****/\n",
571 GETPID(), (int)x);
572 }
573 if( x>=0 ) return;
574 }
575 #else /* unix */
576 {
577 pid_t pid = fork();
578 if( pid>0 ){
579 /* This is the parent in a successful fork(). Return immediately. */
580 if( g.fAnyTrace ){
581 fprintf(stderr,
582 "/***** Subprocess %d creates backoffice child %d *****/\n",
583 GETPID(), (int)pid);
584 }
585 return;
586 }
587 if( pid==0 ){
588 /* This is the child of a successful fork(). Run backoffice. */
589 setsid();
590 db_open_repository(backofficeDb);
591 backofficeDb = "x";
592 backoffice_thread();
593 db_close(1);
594 if( g.fAnyTrace ){
595 fprintf(stderr, "/***** Backoffice Child %d exits *****/\n", GETPID());
596 }
597 exit(0);
598 }
599 }
600 #endif
601 /* Fork() failed or is unavailable. Run backoffice in this process, but
602
--- src/backoffice.c
+++ src/backoffice.c
@@ -117,10 +117,34 @@
117 */
118 static char *backofficeDb = 0;
119
120 /* End of state variables
121 ****************************************************************************/
122
123 /*
124 ** This function emits a diagnostic message related to the processing in
125 ** this module.
126 */
127 #if defined(_WIN32)
128 # define BKOFCE_ALWAYS_TRACE (1)
129 #else
130 # define BKOFCE_ALWAYS_TRACE (0)
131 #endif
132 static void backofficeTrace(const char *zFormat, ...){
133 char *zMsg = 0;
134 if( BKOFCE_ALWAYS_TRACE || g.fAnyTrace ){
135 va_list ap;
136 va_start(ap, zFormat);
137 zMsg = sqlite3_vmprintf(zFormat, ap);
138 va_end(ap);
139 #if defined(_WIN32)
140 sqlite3_win32_write_debug(zMsg, -1);
141 #endif
142 }
143 if( g.fAnyTrace ) fprintf(stderr, "%s", zMsg);
144 if( zMsg ) sqlite3_free(zMsg);
145 }
146
147 /*
148 ** Do not allow backoffice processes to sleep waiting on a timeslot.
149 ** They must either do their work immediately or exit.
150 **
@@ -446,14 +470,12 @@
470 x.tmCurrent = tmNow + BKOFCE_LEASE_TIME;
471 x.idNext = 0;
472 x.tmNext = 0;
473 backofficeWriteLease(&x);
474 db_end_transaction(0);
475 backofficeTrace("/***** Begin Backoffice Processing %d *****/\n",
476 GETPID());
 
 
477 backoffice_work();
478 break;
479 }
480 if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",0) ){
481 /* If the no-delay flag is set, exit immediately rather than queuing
@@ -466,19 +488,15 @@
488 ** to expire before continuing. */
489 x.idNext = idSelf;
490 x.tmNext = (tmNow>x.tmCurrent ? tmNow : x.tmCurrent) + BKOFCE_LEASE_TIME;
491 backofficeWriteLease(&x);
492 db_end_transaction(0);
493 backofficeTrace("/***** Backoffice On-deck %d *****/\n", GETPID());
 
 
494 if( x.tmCurrent >= tmNow ){
495 if( backofficeSleep(1000*(x.tmCurrent - tmNow + 1)) ){
496 /* The sleep was interrupted by a signal from another thread. */
497 backofficeTrace("/***** Backoffice Interrupt %d *****/\n", GETPID());
 
 
498 db_end_transaction(0);
499 break;
500 }
501 }else{
502 if( lastWarning+warningDelay < tmNow ){
@@ -488,13 +506,11 @@
506 lastWarning = tmNow;
507 warningDelay *= 2;
508 }
509 if( backofficeSleep(1000) ){
510 /* The sleep was interrupted by a signal from another thread. */
511 backofficeTrace("/***** Backoffice Interrupt %d *****/\n", GETPID());
 
 
512 db_end_transaction(0);
513 break;
514 }
515 }
516 }
@@ -563,39 +579,33 @@
579 argv[3] = backofficeDb;
580 ax[4] = 0;
581 for(i=0; i<=3; i++) ax[i] = fossil_utf8_to_unicode(argv[i]);
582 x = _wspawnv(_P_NOWAIT, ax[0], (const wchar_t * const *)ax);
583 for(i=0; i<=3; i++) fossil_unicode_free(ax[i]);
584 backofficeTrace(
585 "/***** Subprocess %d creates backoffice child %d *****/\n",
586 GETPID(), (int)x);
 
 
587 if( x>=0 ) return;
588 }
589 #else /* unix */
590 {
591 pid_t pid = fork();
592 if( pid>0 ){
593 /* This is the parent in a successful fork(). Return immediately. */
594 backofficeTrace(
595 "/***** Subprocess %d creates backoffice child %d *****/\n",
596 GETPID(), (int)pid);
 
 
597 return;
598 }
599 if( pid==0 ){
600 /* This is the child of a successful fork(). Run backoffice. */
601 setsid();
602 db_open_repository(backofficeDb);
603 backofficeDb = "x";
604 backoffice_thread();
605 db_close(1);
606 backofficeTrace("/***** Backoffice Child %d exits *****/\n", GETPID());
 
 
607 exit(0);
608 }
609 }
610 #endif
611 /* Fork() failed or is unavailable. Run backoffice in this process, but
612

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button