Fossil SCM
Make the backoffice module tracing behave more consistently on Win32.
Commit
0fe9da816feba1bc9455cce2b3d8a120718e727462011a70a67b9c1154f2cf2f
Parent
300682604f7540c…
1 file changed
+36
-26
+36
-26
| --- src/backoffice.c | ||
| +++ src/backoffice.c | ||
| @@ -117,10 +117,34 @@ | ||
| 117 | 117 | */ |
| 118 | 118 | static char *backofficeDb = 0; |
| 119 | 119 | |
| 120 | 120 | /* End of state variables |
| 121 | 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 | +} | |
| 122 | 146 | |
| 123 | 147 | /* |
| 124 | 148 | ** Do not allow backoffice processes to sleep waiting on a timeslot. |
| 125 | 149 | ** They must either do their work immediately or exit. |
| 126 | 150 | ** |
| @@ -446,14 +470,12 @@ | ||
| 446 | 470 | x.tmCurrent = tmNow + BKOFCE_LEASE_TIME; |
| 447 | 471 | x.idNext = 0; |
| 448 | 472 | x.tmNext = 0; |
| 449 | 473 | backofficeWriteLease(&x); |
| 450 | 474 | 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()); | |
| 455 | 477 | backoffice_work(); |
| 456 | 478 | break; |
| 457 | 479 | } |
| 458 | 480 | if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",0) ){ |
| 459 | 481 | /* If the no-delay flag is set, exit immediately rather than queuing |
| @@ -466,19 +488,15 @@ | ||
| 466 | 488 | ** to expire before continuing. */ |
| 467 | 489 | x.idNext = idSelf; |
| 468 | 490 | x.tmNext = (tmNow>x.tmCurrent ? tmNow : x.tmCurrent) + BKOFCE_LEASE_TIME; |
| 469 | 491 | backofficeWriteLease(&x); |
| 470 | 492 | 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()); | |
| 474 | 494 | if( x.tmCurrent >= tmNow ){ |
| 475 | 495 | if( backofficeSleep(1000*(x.tmCurrent - tmNow + 1)) ){ |
| 476 | 496 | /* 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()); | |
| 480 | 498 | db_end_transaction(0); |
| 481 | 499 | break; |
| 482 | 500 | } |
| 483 | 501 | }else{ |
| 484 | 502 | if( lastWarning+warningDelay < tmNow ){ |
| @@ -488,13 +506,11 @@ | ||
| 488 | 506 | lastWarning = tmNow; |
| 489 | 507 | warningDelay *= 2; |
| 490 | 508 | } |
| 491 | 509 | if( backofficeSleep(1000) ){ |
| 492 | 510 | /* 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()); | |
| 496 | 512 | db_end_transaction(0); |
| 497 | 513 | break; |
| 498 | 514 | } |
| 499 | 515 | } |
| 500 | 516 | } |
| @@ -563,39 +579,33 @@ | ||
| 563 | 579 | argv[3] = backofficeDb; |
| 564 | 580 | ax[4] = 0; |
| 565 | 581 | for(i=0; i<=3; i++) ax[i] = fossil_utf8_to_unicode(argv[i]); |
| 566 | 582 | x = _wspawnv(_P_NOWAIT, ax[0], (const wchar_t * const *)ax); |
| 567 | 583 | 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); | |
| 573 | 587 | if( x>=0 ) return; |
| 574 | 588 | } |
| 575 | 589 | #else /* unix */ |
| 576 | 590 | { |
| 577 | 591 | pid_t pid = fork(); |
| 578 | 592 | if( pid>0 ){ |
| 579 | 593 | /* 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); | |
| 585 | 597 | return; |
| 586 | 598 | } |
| 587 | 599 | if( pid==0 ){ |
| 588 | 600 | /* This is the child of a successful fork(). Run backoffice. */ |
| 589 | 601 | setsid(); |
| 590 | 602 | db_open_repository(backofficeDb); |
| 591 | 603 | backofficeDb = "x"; |
| 592 | 604 | backoffice_thread(); |
| 593 | 605 | 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()); | |
| 597 | 607 | exit(0); |
| 598 | 608 | } |
| 599 | 609 | } |
| 600 | 610 | #endif |
| 601 | 611 | /* Fork() failed or is unavailable. Run backoffice in this process, but |
| 602 | 612 |
| --- 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 |