Fossil SCM

Fix the backoffice processes on unix so that they close file descriptors 0, 1, and 2 and reopen them on /dev/null, so as not to interfere with parent processes in any way. Restore the default of backoffice-nodelay back to off. Remove the /test-backoffice-lease webpage, which did not work correctly.

drh 2018-08-08 18:17 trunk merge
Commit c09b2512b3f86e507deec2d418dd9961b3233bf8811b55d48feeefa7911b21ae
+6 -76
--- src/backoffice.c
+++ src/backoffice.c
@@ -164,18 +164,10 @@
164164
*/
165165
void backoffice_no_delay(void){
166166
backofficeNoDelay = 1;
167167
}
168168
169
-/*
170
-** Signal that the backoffice should not be run at the conclusion of
171
-** the current session.
172
-*/
173
-void backoffice_do_not_run(void){
174
- backofficeDb = "x";
175
-}
176
-
177169
/*
178170
** Sleeps for the specified number of milliseconds -OR- until interrupted
179171
** by another thread (if supported by the underlying platform). Non-zero
180172
** will be returned if the sleep was interrupted.
181173
*/
@@ -441,76 +433,10 @@
441433
}else{
442434
fossil_print("\n");
443435
}
444436
}
445437
446
-
447
-/*
448
-** WEBPAGE: test-backoffice-lease
449
-**
450
-** Print out information about the backoffice "lease" entry in the
451
-** config table that controls whether or not backoffice should run.
452
-*/
453
-void test_backoffice_lease_page(void){
454
- sqlite3_int64 tmNow = time(0);
455
- Lease x;
456
- const char *zLease;
457
- login_check_credentials();
458
- if( !g.perm.Setup ){
459
- login_needed(0);
460
- return;
461
- }
462
- style_header("Backoffice Lease");
463
- backoffice_do_not_run();
464
- @ <table class='label-value'>
465
- zLease = db_get("backoffice","");
466
- @ <tr><th>Now:</th><td>%lld(tmNow)</td></tr>
467
- @ <tr><th>Lease:</th><td colspan="3">"%h(zLease)"</td></tr>
468
- backofficeReadLease(&x);
469
- @ <tr><th>idCurrent:</th><td>%lld(x.idCurrent)</td><td>&nbsp;</td><td>\
470
- if( backofficeProcessExists(x.idCurrent) ){
471
- @ (exists) \
472
- }
473
- if( backofficeProcessDone(x.idCurrent) ){
474
- @ (done) \
475
- }
476
- @ </td></tr>
477
- @ <tr><th>tmCurrent:</th><td>%lld(x.tmCurrent)</td><td></td><td>\
478
- if( x.tmCurrent>0 ){
479
- @ (now%+lld(x.tmCurrent-tmNow)) \
480
- }
481
- @ </td></tr>
482
- @ <tr><th>idNext:</th><td>%lld(x.idNext)</td><td>&nbsp;</td><td>\
483
- if( backofficeProcessExists(x.idNext) ){
484
- @ (exists) \
485
- }
486
- if( backofficeProcessDone(x.idNext) ){
487
- @ (done) \
488
- }
489
- @ </td></tr>
490
- @ <tr><th>tmNext:</th><td>%lld(x.tmNext)</td><td></td><td>\
491
- if( x.tmNext>0 ){
492
- @ (now%+lld(x.tmNext-tmNow)) \
493
- }
494
- @ </td></tr>
495
-#ifndef _WIN32
496
- if( P("fds")!=0 ){
497
- int i;
498
- @ <tr><th>open fds:</th><td colspan="3">
499
- for(i=0; i<1000; i++){
500
- int rc = fcntl(i, F_GETFL, 0);
501
- if( rc<0 ) continue;
502
- @ %d(i) \
503
- }
504
- @ </td></tr>
505
- }
506
-#endif
507
-
508
- @ </table>
509
- style_footer();
510
-}
511
-
512438
/*
513439
** If backoffice processing is needed set the backofficeDb variable to the
514440
** name of the database file. If no backoffice processing is needed,
515441
** this routine makes no changes to state.
516442
*/
@@ -598,11 +524,11 @@
598524
backofficeTrace("/***** Begin Backoffice Processing %d *****/\n",
599525
GETPID());
600526
backoffice_work();
601527
break;
602528
}
603
- if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",1) ){
529
+ if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",0) ){
604530
/* If the no-delay flag is set, exit immediately rather than queuing
605531
** up. Assume that some future request will come along and handle any
606532
** necessary backoffice work. */
607533
db_end_transaction(0);
608534
break;
@@ -721,11 +647,15 @@
721647
}
722648
if( pid==0 ){
723649
/* This is the child of a successful fork(). Run backoffice. */
724650
int i;
725651
setsid();
726
- for(i=3; close(i)==0 || i<10; i++){}
652
+ for(i=0; i<=2; i++){
653
+ close(i);
654
+ open("/dev/null", O_RDWR);
655
+ }
656
+ for(i=3; i<100; i++){ close(i); }
727657
db_open_repository(backofficeDb);
728658
backofficeDb = "x";
729659
backoffice_thread();
730660
db_close(1);
731661
backofficeTrace("/***** Backoffice Child %d exits *****/\n", GETPID());
732662
--- src/backoffice.c
+++ src/backoffice.c
@@ -164,18 +164,10 @@
164 */
165 void backoffice_no_delay(void){
166 backofficeNoDelay = 1;
167 }
168
169 /*
170 ** Signal that the backoffice should not be run at the conclusion of
171 ** the current session.
172 */
173 void backoffice_do_not_run(void){
174 backofficeDb = "x";
175 }
176
177 /*
178 ** Sleeps for the specified number of milliseconds -OR- until interrupted
179 ** by another thread (if supported by the underlying platform). Non-zero
180 ** will be returned if the sleep was interrupted.
181 */
@@ -441,76 +433,10 @@
441 }else{
442 fossil_print("\n");
443 }
444 }
445
446
447 /*
448 ** WEBPAGE: test-backoffice-lease
449 **
450 ** Print out information about the backoffice "lease" entry in the
451 ** config table that controls whether or not backoffice should run.
452 */
453 void test_backoffice_lease_page(void){
454 sqlite3_int64 tmNow = time(0);
455 Lease x;
456 const char *zLease;
457 login_check_credentials();
458 if( !g.perm.Setup ){
459 login_needed(0);
460 return;
461 }
462 style_header("Backoffice Lease");
463 backoffice_do_not_run();
464 @ <table class='label-value'>
465 zLease = db_get("backoffice","");
466 @ <tr><th>Now:</th><td>%lld(tmNow)</td></tr>
467 @ <tr><th>Lease:</th><td colspan="3">"%h(zLease)"</td></tr>
468 backofficeReadLease(&x);
469 @ <tr><th>idCurrent:</th><td>%lld(x.idCurrent)</td><td>&nbsp;</td><td>\
470 if( backofficeProcessExists(x.idCurrent) ){
471 @ (exists) \
472 }
473 if( backofficeProcessDone(x.idCurrent) ){
474 @ (done) \
475 }
476 @ </td></tr>
477 @ <tr><th>tmCurrent:</th><td>%lld(x.tmCurrent)</td><td></td><td>\
478 if( x.tmCurrent>0 ){
479 @ (now%+lld(x.tmCurrent-tmNow)) \
480 }
481 @ </td></tr>
482 @ <tr><th>idNext:</th><td>%lld(x.idNext)</td><td>&nbsp;</td><td>\
483 if( backofficeProcessExists(x.idNext) ){
484 @ (exists) \
485 }
486 if( backofficeProcessDone(x.idNext) ){
487 @ (done) \
488 }
489 @ </td></tr>
490 @ <tr><th>tmNext:</th><td>%lld(x.tmNext)</td><td></td><td>\
491 if( x.tmNext>0 ){
492 @ (now%+lld(x.tmNext-tmNow)) \
493 }
494 @ </td></tr>
495 #ifndef _WIN32
496 if( P("fds")!=0 ){
497 int i;
498 @ <tr><th>open fds:</th><td colspan="3">
499 for(i=0; i<1000; i++){
500 int rc = fcntl(i, F_GETFL, 0);
501 if( rc<0 ) continue;
502 @ %d(i) \
503 }
504 @ </td></tr>
505 }
506 #endif
507
508 @ </table>
509 style_footer();
510 }
511
512 /*
513 ** If backoffice processing is needed set the backofficeDb variable to the
514 ** name of the database file. If no backoffice processing is needed,
515 ** this routine makes no changes to state.
516 */
@@ -598,11 +524,11 @@
598 backofficeTrace("/***** Begin Backoffice Processing %d *****/\n",
599 GETPID());
600 backoffice_work();
601 break;
602 }
603 if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",1) ){
604 /* If the no-delay flag is set, exit immediately rather than queuing
605 ** up. Assume that some future request will come along and handle any
606 ** necessary backoffice work. */
607 db_end_transaction(0);
608 break;
@@ -721,11 +647,15 @@
721 }
722 if( pid==0 ){
723 /* This is the child of a successful fork(). Run backoffice. */
724 int i;
725 setsid();
726 for(i=3; close(i)==0 || i<10; i++){}
 
 
 
 
727 db_open_repository(backofficeDb);
728 backofficeDb = "x";
729 backoffice_thread();
730 db_close(1);
731 backofficeTrace("/***** Backoffice Child %d exits *****/\n", GETPID());
732
--- src/backoffice.c
+++ src/backoffice.c
@@ -164,18 +164,10 @@
164 */
165 void backoffice_no_delay(void){
166 backofficeNoDelay = 1;
167 }
168
 
 
 
 
 
 
 
 
169 /*
170 ** Sleeps for the specified number of milliseconds -OR- until interrupted
171 ** by another thread (if supported by the underlying platform). Non-zero
172 ** will be returned if the sleep was interrupted.
173 */
@@ -441,76 +433,10 @@
433 }else{
434 fossil_print("\n");
435 }
436 }
437
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
438 /*
439 ** If backoffice processing is needed set the backofficeDb variable to the
440 ** name of the database file. If no backoffice processing is needed,
441 ** this routine makes no changes to state.
442 */
@@ -598,11 +524,11 @@
524 backofficeTrace("/***** Begin Backoffice Processing %d *****/\n",
525 GETPID());
526 backoffice_work();
527 break;
528 }
529 if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",0) ){
530 /* If the no-delay flag is set, exit immediately rather than queuing
531 ** up. Assume that some future request will come along and handle any
532 ** necessary backoffice work. */
533 db_end_transaction(0);
534 break;
@@ -721,11 +647,15 @@
647 }
648 if( pid==0 ){
649 /* This is the child of a successful fork(). Run backoffice. */
650 int i;
651 setsid();
652 for(i=0; i<=2; i++){
653 close(i);
654 open("/dev/null", O_RDWR);
655 }
656 for(i=3; i<100; i++){ close(i); }
657 db_open_repository(backofficeDb);
658 backofficeDb = "x";
659 backoffice_thread();
660 db_close(1);
661 backofficeTrace("/***** Backoffice Child %d exits *****/\n", GETPID());
662
+1 -1
--- src/db.c
+++ src/db.c
@@ -3023,11 +3023,11 @@
30233023
** If autosync is enabled setting this to a value greater
30243024
** than zero will cause autosync to try no more than this
30253025
** number of attempts if there is a sync failure.
30263026
*/
30273027
/*
3028
-** SETTING: backoffice-nodelay boolean default=on
3028
+** SETTING: backoffice-nodelay boolean default=off
30293029
** If backoffice-nodelay is true, then the backoffice processing
30303030
** will never invoke sleep(). If it has nothing useful to do,
30313031
** it simply exits.
30323032
*/
30333033
/*
30343034
--- src/db.c
+++ src/db.c
@@ -3023,11 +3023,11 @@
3023 ** If autosync is enabled setting this to a value greater
3024 ** than zero will cause autosync to try no more than this
3025 ** number of attempts if there is a sync failure.
3026 */
3027 /*
3028 ** SETTING: backoffice-nodelay boolean default=on
3029 ** If backoffice-nodelay is true, then the backoffice processing
3030 ** will never invoke sleep(). If it has nothing useful to do,
3031 ** it simply exits.
3032 */
3033 /*
3034
--- src/db.c
+++ src/db.c
@@ -3023,11 +3023,11 @@
3023 ** If autosync is enabled setting this to a value greater
3024 ** than zero will cause autosync to try no more than this
3025 ** number of attempts if there is a sync failure.
3026 */
3027 /*
3028 ** SETTING: backoffice-nodelay boolean default=off
3029 ** If backoffice-nodelay is true, then the backoffice processing
3030 ** will never invoke sleep(). If it has nothing useful to do,
3031 ** it simply exits.
3032 */
3033 /*
3034
--- src/style.c
+++ src/style.c
@@ -19,11 +19,10 @@
1919
**
2020
*/
2121
#include "VERSION.h"
2222
#include "config.h"
2323
#include "style.h"
24
-
2524
2625
/*
2726
** Elements of the submenu are collected into the following
2827
** structure and displayed below the main menu.
2928
**
3029
--- src/style.c
+++ src/style.c
@@ -19,11 +19,10 @@
19 **
20 */
21 #include "VERSION.h"
22 #include "config.h"
23 #include "style.h"
24
25
26 /*
27 ** Elements of the submenu are collected into the following
28 ** structure and displayed below the main menu.
29 **
30
--- src/style.c
+++ src/style.c
@@ -19,11 +19,10 @@
19 **
20 */
21 #include "VERSION.h"
22 #include "config.h"
23 #include "style.h"
 
24
25 /*
26 ** Elements of the submenu are collected into the following
27 ** structure and displayed below the main menu.
28 **
29

Keyboard Shortcuts

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