Fossil

Check-in [c52fb5ed]
Login

Check-in [c52fb5ed]

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

Overview
Comment:Attempt to get the backoffice running on Windows.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | backoffice-win
Files: files | file ages | folders
SHA3-256: c52fb5eddb6099933607697e5144670d3103bd817cbeb09c0d3c093477e910f2
User & Date: tsbg 2018-12-10 08:07:02
Context
2019-04-26
16:39
Merge trunk. ... (check-in: 3a19db88 user: tsbg tags: backoffice-win)
2018-12-10
08:07
Attempt to get the backoffice running on Windows. ... (check-in: c52fb5ed user: tsbg tags: backoffice-win)
2018-12-07
19:36
Reworded 2 references to 40-character artifact IDs, since those particular IDs may now be longer than 40 characters. ... (check-in: 565c2173 user: stephan tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/alerts.c.

841
842
843
844
845
846
847

848





849
850

851



852
853
854
855
856
857
858
    }
    rc = sqlite3_reset(p->pStmt);
    if( rc!=SQLITE_OK ){
      emailerError(p, "Failed to insert email message into output queue.\n"
                      "%s", sqlite3_errmsg(p->db));
    }
  }else if( p->zCmd ){

    FILE *out = popen(p->zCmd, "w");





    if( out ){
      fwrite(blob_buffer(&all), 1, blob_size(&all), out);

      pclose(out);



    }else{
      emailerError(p, "Could not open output pipe \"%s\"", p->zCmd);
    }
  }else if( p->zDir ){
    char *zFile = file_time_tempname(p->zDir, ".email");
    blob_write_to_file(&all, zFile);
    fossil_free(zFile);







>

>
>
>
>
>


>

>
>
>







841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
    }
    rc = sqlite3_reset(p->pStmt);
    if( rc!=SQLITE_OK ){
      emailerError(p, "Failed to insert email message into output queue.\n"
                      "%s", sqlite3_errmsg(p->db));
    }
  }else if( p->zCmd ){
#if !defined(_WIN32)
    FILE *out = popen(p->zCmd, "w");
#else
    int in, pid;
    FILE *out;
    popen2(p->zCmd, &in, &out, &pid);
#endif
    if( out ){
      fwrite(blob_buffer(&all), 1, blob_size(&all), out);
#if !defined(_WIN32)
      pclose(out);
#else
      pclose2(in ,out, pid);
#endif
    }else{
      emailerError(p, "Could not open output pipe \"%s\"", p->zCmd);
    }
  }else if( p->zDir ){
    char *zFile = file_time_tempname(p->zDir, ".email");
    blob_write_to_file(&all, zFile);
    fossil_free(zFile);

Changes to src/backoffice.c.

281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
** we cannot prove the the process is dead, return true.
*/
static int backofficeProcessExists(sqlite3_uint64 pid){
#if defined(_WIN32)
  return pid>0 && backofficeWin32ProcessExists((DWORD)pid)!=0;
#else
  return pid>0 && kill((pid_t)pid, 0)==0;
#endif 
}

/*
** Check to see if the process identified by pid has finished.  If
** we cannot prove the the process is still running, return true.
*/
static int backofficeProcessDone(sqlite3_uint64 pid){
#if defined(_WIN32)
  return pid<=0 || backofficeWin32ProcessExists((DWORD)pid)==0;
#else
  return pid<=0 || kill((pid_t)pid, 0)!=0;
#endif 
}

/*
** Return a process id number for the current process
*/
static sqlite3_uint64 backofficeProcessId(void){
  return (sqlite3_uint64)GETPID();







|











|







281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
** we cannot prove the the process is dead, return true.
*/
static int backofficeProcessExists(sqlite3_uint64 pid){
#if defined(_WIN32)
  return pid>0 && backofficeWin32ProcessExists((DWORD)pid)!=0;
#else
  return pid>0 && kill((pid_t)pid, 0)==0;
#endif
}

/*
** Check to see if the process identified by pid has finished.  If
** we cannot prove the the process is still running, return true.
*/
static int backofficeProcessDone(sqlite3_uint64 pid){
#if defined(_WIN32)
  return pid<=0 || backofficeWin32ProcessExists((DWORD)pid)==0;
#else
  return pid<=0 || kill((pid_t)pid, 0)!=0;
#endif
}

/*
** Return a process id number for the current process
*/
static sqlite3_uint64 backofficeProcessId(void){
  return (sqlite3_uint64)GETPID();
465
466
467
468
469
470
471


472
473
474
475
476
477
478
      x.idNext = 0;
      x.tmNext = 0;
      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);







>
>







465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
      x.idNext = 0;
      x.tmNext = 0;
      backofficeWriteLease(&x);
      db_end_transaction(0);
      backofficeTrace("/***** Begin Backoffice Processing %d *****/\n",
                      GETPID());
      backoffice_work();
      backofficeTrace("/***** End Backoffice Processing %d *****/\n",
                      GETPID());
      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);
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
void backoffice_run_if_needed(void){
  if( backofficeDb==0 ) return;
  if( strcmp(backofficeDb,"x")==0 ) return;
  if( g.db ) return;
  if( g.repositoryOpen ) return;
#if defined(_WIN32)
  {


    int i;
    intptr_t x;
    char *argv[4];
    wchar_t *ax[5];
    argv[0] = g.nameOfExe;



    argv[1] = "backoffice";
    argv[2] = "-R";
    argv[3] = backofficeDb;
    ax[4] = 0;
    for(i=0; i<=3; i++) ax[i] = fossil_utf8_to_unicode(argv[i]);
    x = _wspawnv(_P_NOWAIT, ax[0], (const wchar_t * const *)ax);

















    for(i=0; i<=3; i++) fossil_unicode_free(ax[i]);



    backofficeTrace(
      "/***** Subprocess %d creates backoffice child %lu *****/\n",
      GETPID(), GetProcessId((HANDLE)x));
    if( x>=0 ) return;

  }
#else /* unix */
  {
    pid_t pid = fork();
    if( pid>0 ){
      /* This is the parent in a successful fork().  Return immediately. */
      backofficeTrace(







>
>
|
|
<
|
<
>
>
>
|
<
|
<
|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
|
|
|
|
>







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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
void backoffice_run_if_needed(void){
  if( backofficeDb==0 ) return;
  if( strcmp(backofficeDb,"x")==0 ) return;
  if( g.db ) return;
  if( g.repositoryOpen ) return;
#if defined(_WIN32)
  {
    STARTUPINFOW si;
    PROCESS_INFORMATION pi;
    BOOL rc;
    Blob binCmd;

    wchar_t *wcsCmd;

    /* Build the command string and make sure the process does not get
    ** handled as CGI. */
    blob_zero(&binCmd);
    blob_appendf(&binCmd, "\"%s\" backoffice --nocgi -R \"%s\"",

                 g.nameOfExe, backofficeDb);

    wcsCmd = fossil_utf8_to_unicode(blob_str(&binCmd));

    blob_reset(&binCmd);
    /* Start a detached process. */
    ZeroMemory(&pi, sizeof(pi));
    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    rc = CreateProcessW(
       NULL,             /* Application Name */
       wcsCmd,           /* Command-line */
       NULL,             /* Process attributes */
       NULL,             /* Thread attributes */
       FALSE,            /* Inherit Handles */
       DETACHED_PROCESS, /* Create flags  */
       NULL,             /* Environment */
       NULL,             /* Current directory */
       &si,              /* Startup Info */
       &pi               /* Process Info */
    );
    fossil_unicode_free(wcsCmd);
    if( rc ){
      CloseHandle(pi.hProcess);
      CloseHandle(pi.hThread);
      backofficeTrace(
        "/***** Subprocess %d creates backoffice child %d *****/\n",
        GETPID(), pi.dwProcessId);
      return;
    }
  }
#else /* unix */
  {
    pid_t pid = fork();
    if( pid>0 ){
      /* This is the parent in a successful fork().  Return immediately. */
      backofficeTrace(

Changes to src/main.c.

2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
  noJail = find_option("nojail",0,0)!=0;
  allowRepoList = find_option("repolist",0,0)!=0;
  g.useLocalauth = find_option("localauth", 0, 0)!=0;
  g.sslNotAvailable = find_option("nossl", 0, 0)!=0;
  g.fNoHttpCompress = find_option("nocompress",0,0)!=0;
  zInFile = find_option("in",0,1);
  if( zInFile ){
    backoffice_disable();
    g.httpIn = fossil_fopen(zInFile, "rb");
    if( g.httpIn==0 ) fossil_fatal("cannot open \"%s\" for reading", zInFile);
  }else{
    g.httpIn = stdin;
  }
  zOutFile = find_option("out",0,1);
  if( zOutFile ){







<







2231
2232
2233
2234
2235
2236
2237

2238
2239
2240
2241
2242
2243
2244
  noJail = find_option("nojail",0,0)!=0;
  allowRepoList = find_option("repolist",0,0)!=0;
  g.useLocalauth = find_option("localauth", 0, 0)!=0;
  g.sslNotAvailable = find_option("nossl", 0, 0)!=0;
  g.fNoHttpCompress = find_option("nocompress",0,0)!=0;
  zInFile = find_option("in",0,1);
  if( zInFile ){

    g.httpIn = fossil_fopen(zInFile, "rb");
    if( g.httpIn==0 ) fossil_fatal("cannot open \"%s\" for reading", zInFile);
  }else{
    g.httpIn = stdin;
  }
  zOutFile = find_option("out",0,1);
  if( zOutFile ){

Changes to src/popen.c.

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  si.hStdError  = hErr;
  rc = CreateProcessW(
     NULL,  /* Application Name */
     zCmd,  /* Command-line */
     NULL,  /* Process attributes */
     NULL,  /* Thread attributes */
     TRUE,  /* Inherit Handles */
     0,     /* Create flags  */
     NULL,  /* Environment */
     NULL,  /* Current directory */
     &si,   /* Startup Info */
     &pi    /* Process Info */
  );
  if( rc ){
    CloseHandle( pi.hProcess );







|







91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  si.hStdError  = hErr;
  rc = CreateProcessW(
     NULL,  /* Application Name */
     zCmd,  /* Command-line */
     NULL,  /* Process attributes */
     NULL,  /* Thread attributes */
     TRUE,  /* Inherit Handles */
     CREATE_NO_WINDOW, /* Create flags  */
     NULL,  /* Environment */
     NULL,  /* Current directory */
     &si,   /* Startup Info */
     &pi    /* Process Info */
  );
  if( rc ){
    CloseHandle( pi.hProcess );