Fossil

Check-in [c09b2512]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:c09b2512b3f86e507deec2d418dd9961b3233bf8811b55d48feeefa7911b21ae
User & Date: drh 2018-08-08 18:17:42
Context
2018-08-08
18:29
Fixed some Markdown formatting problems in www/emaildesign.md. Made a few minor grammar tweaks while in there. check-in: 30716e3c user: wyoung tags: trunk
18:17
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. check-in: c09b2512 user: drh tags: trunk
18:15
Remove the /test-backoffice-lease webpage, since it doesn't really work correctly. Use only the "fossil test-backoffice-lease" command moving forward. We can wrap that command in a Wapp script if necessary. Closed-Leaf check-in: b6aadace user: drh tags: backoffice-full-close
17:21
Added initial version of www/forum.wiki document and a link to it from the front page. check-in: 4ed14b1f user: wyoung tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/backoffice.c.

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
...
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
...
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
...
719
720
721
722
723
724
725

726



727
728
729
730
731
732
733
** a backoffice will delay a UI thread, so we don't want them to run for
** longer than needed.
*/
void backoffice_no_delay(void){
  backofficeNoDelay = 1;
}

/*
** Signal that the backoffice should not be run at the conclusion of
** the current session.
*/
void backoffice_do_not_run(void){
  backofficeDb = "x";
}

/*
** Sleeps for the specified number of milliseconds -OR- until interrupted
** by another thread (if supported by the underlying platform).  Non-zero
** will be returned if the sleep was interrupted.
*/
static int backofficeSleep(int milliseconds){
#if defined(_WIN32)
................................................................................
  if( x.tmNext>0 ){
    fossil_print(" (now%+d)\n",x.tmNext-tmNow);
  }else{
    fossil_print("\n");
  }
}


/*
** WEBPAGE: test-backoffice-lease
**
** Print out information about the backoffice "lease" entry in the
** config table that controls whether or not backoffice should run.
*/
void test_backoffice_lease_page(void){
  sqlite3_int64 tmNow = time(0);
  Lease x;
  const char *zLease;
  login_check_credentials();
  if( !g.perm.Setup ){
    login_needed(0);
    return;
  }
  style_header("Backoffice Lease");
  backoffice_do_not_run();
  @ <table class='label-value'>
  zLease = db_get("backoffice","");
  @ <tr><th>Now:</th><td>%lld(tmNow)</td></tr>
  @ <tr><th>Lease:</th><td colspan="3">"%h(zLease)"</td></tr>
  backofficeReadLease(&x);
  @ <tr><th>idCurrent:</th><td>%lld(x.idCurrent)</td><td>&nbsp;</td><td>\
  if( backofficeProcessExists(x.idCurrent) ){
    @ (exists) \
  }
  if( backofficeProcessDone(x.idCurrent) ){
    @ (done) \
  }
  @ </td></tr>
  @ <tr><th>tmCurrent:</th><td>%lld(x.tmCurrent)</td><td></td><td>\
  if( x.tmCurrent>0 ){
    @ (now%+lld(x.tmCurrent-tmNow)) \
  }
  @ </td></tr>
  @ <tr><th>idNext:</th><td>%lld(x.idNext)</td><td>&nbsp;</td><td>\
  if( backofficeProcessExists(x.idNext) ){
    @ (exists) \
  }
  if( backofficeProcessDone(x.idNext) ){
    @ (done) \
  }
  @ </td></tr>
  @ <tr><th>tmNext:</th><td>%lld(x.tmNext)</td><td></td><td>\
  if( x.tmNext>0 ){
    @ (now%+lld(x.tmNext-tmNow)) \
  }
  @ </td></tr>
#ifndef _WIN32
  if( P("fds")!=0 ){
    int i;
    @ <tr><th>open fds:</th><td colspan="3">
    for(i=0; i<1000; i++){
      int rc = fcntl(i, F_GETFL, 0);
      if( rc<0 ) continue;
      @ %d(i) \
    }
    @ </td></tr>
  }
#endif

  @ </table>
  style_footer();
}

/*
** If backoffice processing is needed set the backofficeDb variable to the
** name of the database file.  If no backoffice processing is needed,
** this routine makes no changes to state.
*/
void backoffice_check_if_needed(void){
  Lease x;
................................................................................
      backofficeWriteLease(&x);
      db_end_transaction(0);
      backofficeTrace("/***** Begin Backoffice Processing %d *****/\n",
                      GETPID());
      backoffice_work();
      break;
    }
    if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",1) ){
      /* If the no-delay flag is set, exit immediately rather than queuing
      ** up.  Assume that some future request will come along and handle any
      ** necessary backoffice work. */
      db_end_transaction(0);
      break;
    }
    /* This process needs to queue up and wait for the current lease
................................................................................
        GETPID(), (int)pid);
      return;
    }
    if( pid==0 ){
      /* This is the child of a successful fork().  Run backoffice. */
      int i;
      setsid();

      for(i=3; close(i)==0 || i<10; i++){}



      db_open_repository(backofficeDb);
      backofficeDb = "x";
      backoffice_thread();
      db_close(1);
      backofficeTrace("/***** Backoffice Child %d exits *****/\n", GETPID());
      exit(0);
    }







<
<
<
<
<
<
<
<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|







 







>
|
>
>
>







162
163
164
165
166
167
168








169
170
171
172
173
174
175
...
431
432
433
434
435
436
437


































































438
439
440
441
442
443
444
...
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
...
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
** a backoffice will delay a UI thread, so we don't want them to run for
** longer than needed.
*/
void backoffice_no_delay(void){
  backofficeNoDelay = 1;
}









/*
** Sleeps for the specified number of milliseconds -OR- until interrupted
** by another thread (if supported by the underlying platform).  Non-zero
** will be returned if the sleep was interrupted.
*/
static int backofficeSleep(int milliseconds){
#if defined(_WIN32)
................................................................................
  if( x.tmNext>0 ){
    fossil_print(" (now%+d)\n",x.tmNext-tmNow);
  }else{
    fossil_print("\n");
  }
}



































































/*
** If backoffice processing is needed set the backofficeDb variable to the
** name of the database file.  If no backoffice processing is needed,
** this routine makes no changes to state.
*/
void backoffice_check_if_needed(void){
  Lease x;
................................................................................
      backofficeWriteLease(&x);
      db_end_transaction(0);
      backofficeTrace("/***** Begin Backoffice Processing %d *****/\n",
                      GETPID());
      backoffice_work();
      break;
    }
    if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",0) ){
      /* If the no-delay flag is set, exit immediately rather than queuing
      ** up.  Assume that some future request will come along and handle any
      ** necessary backoffice work. */
      db_end_transaction(0);
      break;
    }
    /* This process needs to queue up and wait for the current lease
................................................................................
        GETPID(), (int)pid);
      return;
    }
    if( pid==0 ){
      /* This is the child of a successful fork().  Run backoffice. */
      int i;
      setsid();
      for(i=0; i<=2; i++){
        close(i);
        open("/dev/null", O_RDWR);
      }
      for(i=3; i<100; i++){ close(i); }
      db_open_repository(backofficeDb);
      backofficeDb = "x";
      backoffice_thread();
      db_close(1);
      backofficeTrace("/***** Backoffice Child %d exits *****/\n", GETPID());
      exit(0);
    }

Changes to src/db.c.

3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
/*
** SETTING: autosync-tries  width=16 default=1
** If autosync is enabled setting this to a value greater
** than zero will cause autosync to try no more than this
** number of attempts if there is a sync failure.
*/
/*
** SETTING: backoffice-nodelay boolean default=on
** If backoffice-nodelay is true, then the backoffice processing
** will never invoke sleep().  If it has nothing useful to do,
** it simply exits.
*/
/*
** SETTING: backoffice-logfile width=40
** If backoffice-logfile is not an empty string and is a valid







|







3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
/*
** SETTING: autosync-tries  width=16 default=1
** If autosync is enabled setting this to a value greater
** than zero will cause autosync to try no more than this
** number of attempts if there is a sync failure.
*/
/*
** SETTING: backoffice-nodelay boolean default=off
** If backoffice-nodelay is true, then the backoffice processing
** will never invoke sleep().  If it has nothing useful to do,
** it simply exits.
*/
/*
** SETTING: backoffice-logfile width=40
** If backoffice-logfile is not an empty string and is a valid

Changes to src/style.c.

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
**
** This file contains code to implement the basic web page look and feel.
**
*/
#include "VERSION.h"
#include "config.h"
#include "style.h"


/*
** Elements of the submenu are collected into the following
** structure and displayed below the main menu.
**
** Populate these structure with calls to
**







<







17
18
19
20
21
22
23

24
25
26
27
28
29
30
**
** This file contains code to implement the basic web page look and feel.
**
*/
#include "VERSION.h"
#include "config.h"
#include "style.h"


/*
** Elements of the submenu are collected into the following
** structure and displayed below the main menu.
**
** Populate these structure with calls to
**