Fossil

Check-in [af87fa5b]
Login

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

Overview
Comment:In the backoffice module, use GETPID macro consistently, fix compiler warning with MinGW, and add an assert().
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: af87fa5bcd93e318c507b145b8c09e222cb6d88fe0f1d377cd3a3aa0af06ab2d
User & Date: mistachkin 2018-08-07 21:45:18.063
Context
2018-08-07
23:01
Fix harmless compiler warning. ... (check-in: 7014c2dd user: mistachkin tags: trunk)
21:45
In the backoffice module, use GETPID macro consistently, fix compiler warning with MinGW, and add an assert(). ... (check-in: af87fa5b user: mistachkin tags: trunk)
21:44
Fix harmless compiler warning. ... (check-in: 014bb2d7 user: mistachkin tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/backoffice.c.
60
61
62
63
64
65
66



67
68
69
70
71
72
73
#include "config.h"
#include "backoffice.h"
#include <time.h>
#if defined(_WIN32)
# include <windows.h>
# include <stdio.h>
# include <process.h>



# define GETPID (int)GetCurrentProcessId
#else
# include <unistd.h>
# include <sys/types.h>
# include <signal.h>
# define GETPID getpid
#endif







>
>
>







60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "config.h"
#include "backoffice.h"
#include <time.h>
#if defined(_WIN32)
# include <windows.h>
# include <stdio.h>
# include <process.h>
# if defined(__MINGW32__)
#  include <wchar.h>
# endif
# define GETPID (int)GetCurrentProcessId
#else
# include <unistd.h>
# include <sys/types.h>
# include <signal.h>
# define GETPID getpid
#endif
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
        }
        db_end_transaction(0);
        break;
      }
    }
  }
#if defined(_WIN32)

  backofficeWin32ThreadCleanup();
#endif
  return;
}

/*
** This routine runs to do the backoffice processing.  When adding new
** backoffice processing tasks, add them here.
*/
void backoffice_work(void){
  /* Log the backoffice run for testing purposes.  For production deployments
  ** the "backoffice-logfile" property should be unset and the following code
  ** should be a no-op. */
  char *zLog = db_get("backoffice-logfile",0);
  if( zLog && zLog[0] ){
    FILE *pLog = fossil_fopen(zLog, "a");
    if( pLog ){
      char *zDate = db_text(0, "SELECT datetime('now');");
      fprintf(pLog, "%s (%d) backoffice running\n", zDate, getpid());
      fclose(pLog);
    }
  }

  /* Here is where the actual work of the backoffice happens */
  email_backoffice(0);
}







>


















|







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
        }
        db_end_transaction(0);
        break;
      }
    }
  }
#if defined(_WIN32)
  assert( threadHandle!=NULL );
  backofficeWin32ThreadCleanup();
#endif
  return;
}

/*
** This routine runs to do the backoffice processing.  When adding new
** backoffice processing tasks, add them here.
*/
void backoffice_work(void){
  /* Log the backoffice run for testing purposes.  For production deployments
  ** the "backoffice-logfile" property should be unset and the following code
  ** should be a no-op. */
  char *zLog = db_get("backoffice-logfile",0);
  if( zLog && zLog[0] ){
    FILE *pLog = fossil_fopen(zLog, "a");
    if( pLog ){
      char *zDate = db_text(0, "SELECT datetime('now');");
      fprintf(pLog, "%s (%d) backoffice running\n", zDate, GETPID());
      fclose(pLog);
    }
  }

  /* Here is where the actual work of the backoffice happens */
  email_backoffice(0);
}
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
    ax[4] = 0;
    for(i=0; i<=3; i++) ax[i] = fossil_utf8_to_unicode(argv[i]);
    x = _wspawnv(_P_NOWAIT, ax[0], ax);
    for(i=0; i<=3; i++) fossil_unicode_free(ax[i]);
    if( g.fAnyTrace ){
      fprintf(stderr, 
        "/***** Subprocess %d creates backoffice child %d *****/\n",
        getpid(), (int)x);
    }
    if( x>=0 ) return;
  }
#else /* unix */
  {
    pid_t pid = fork();
    if( pid>0 ){
      /* This is the parent in a successful fork().  Return immediately. */
      if( g.fAnyTrace ){
        fprintf(stderr, 
          "/***** Subprocess %d creates backoffice child %d *****/\n",
          getpid(), (int)pid);
      }
      return;
    }
    if( pid==0 ){
      /* This is the child of a successful fork().  Run backoffice. */
      setsid();
      db_open_repository(backofficeDb);
      backofficeDb = "x";
      backoffice_thread();
      db_close(1);
      if( g.fAnyTrace ){
        fprintf(stderr, "/***** Backoffice Child %d exits *****/\n", getpid());
      }
      exit(0);
    }
  }
#endif
  /* Fork() failed or is unavailable.  Run backoffice in this process, but
  ** do so with the no-delay setting.







|











|











|







548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
    ax[4] = 0;
    for(i=0; i<=3; i++) ax[i] = fossil_utf8_to_unicode(argv[i]);
    x = _wspawnv(_P_NOWAIT, ax[0], ax);
    for(i=0; i<=3; i++) fossil_unicode_free(ax[i]);
    if( g.fAnyTrace ){
      fprintf(stderr, 
        "/***** Subprocess %d creates backoffice child %d *****/\n",
        GETPID(), (int)x);
    }
    if( x>=0 ) return;
  }
#else /* unix */
  {
    pid_t pid = fork();
    if( pid>0 ){
      /* This is the parent in a successful fork().  Return immediately. */
      if( g.fAnyTrace ){
        fprintf(stderr, 
          "/***** Subprocess %d creates backoffice child %d *****/\n",
          GETPID(), (int)pid);
      }
      return;
    }
    if( pid==0 ){
      /* This is the child of a successful fork().  Run backoffice. */
      setsid();
      db_open_repository(backofficeDb);
      backofficeDb = "x";
      backoffice_thread();
      db_close(1);
      if( g.fAnyTrace ){
        fprintf(stderr, "/***** Backoffice Child %d exits *****/\n", GETPID());
      }
      exit(0);
    }
  }
#endif
  /* Fork() failed or is unavailable.  Run backoffice in this process, but
  ** do so with the no-delay setting.