| | @@ -283,11 +283,11 @@ |
| 283 | 283 | static int backofficeProcessExists(sqlite3_uint64 pid){ |
| 284 | 284 | #if defined(_WIN32) |
| 285 | 285 | return pid>0 && backofficeWin32ProcessExists((DWORD)pid)!=0; |
| 286 | 286 | #else |
| 287 | 287 | return pid>0 && kill((pid_t)pid, 0)==0; |
| 288 | | -#endif |
| 288 | +#endif |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /* |
| 292 | 292 | ** Check to see if the process identified by pid has finished. If |
| 293 | 293 | ** we cannot prove the the process is still running, return true. |
| | @@ -295,11 +295,11 @@ |
| 295 | 295 | static int backofficeProcessDone(sqlite3_uint64 pid){ |
| 296 | 296 | #if defined(_WIN32) |
| 297 | 297 | return pid<=0 || backofficeWin32ProcessExists((DWORD)pid)==0; |
| 298 | 298 | #else |
| 299 | 299 | return pid<=0 || kill((pid_t)pid, 0)!=0; |
| 300 | | -#endif |
| 300 | +#endif |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | /* |
| 304 | 304 | ** Return a process id number for the current process |
| 305 | 305 | */ |
| | @@ -467,10 +467,12 @@ |
| 467 | 467 | backofficeWriteLease(&x); |
| 468 | 468 | db_end_transaction(0); |
| 469 | 469 | backofficeTrace("/***** Begin Backoffice Processing %d *****/\n", |
| 470 | 470 | GETPID()); |
| 471 | 471 | backoffice_work(); |
| 472 | + backofficeTrace("/***** End Backoffice Processing %d *****/\n", |
| 473 | + GETPID()); |
| 472 | 474 | break; |
| 473 | 475 | } |
| 474 | 476 | if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",0) ){ |
| 475 | 477 | /* If the no-delay flag is set, exit immediately rather than queuing |
| 476 | 478 | ** up. Assume that some future request will come along and handle any |
| | @@ -559,26 +561,47 @@ |
| 559 | 561 | if( strcmp(backofficeDb,"x")==0 ) return; |
| 560 | 562 | if( g.db ) return; |
| 561 | 563 | if( g.repositoryOpen ) return; |
| 562 | 564 | #if defined(_WIN32) |
| 563 | 565 | { |
| 564 | | - int i; |
| 565 | | - intptr_t x; |
| 566 | | - char *argv[4]; |
| 567 | | - wchar_t *ax[5]; |
| 568 | | - argv[0] = g.nameOfExe; |
| 569 | | - argv[1] = "backoffice"; |
| 570 | | - argv[2] = "-R"; |
| 571 | | - argv[3] = backofficeDb; |
| 572 | | - ax[4] = 0; |
| 573 | | - for(i=0; i<=3; i++) ax[i] = fossil_utf8_to_unicode(argv[i]); |
| 574 | | - x = _wspawnv(_P_NOWAIT, ax[0], (const wchar_t * const *)ax); |
| 575 | | - for(i=0; i<=3; i++) fossil_unicode_free(ax[i]); |
| 576 | | - backofficeTrace( |
| 577 | | - "/***** Subprocess %d creates backoffice child %lu *****/\n", |
| 578 | | - GETPID(), GetProcessId((HANDLE)x)); |
| 579 | | - if( x>=0 ) return; |
| 566 | + STARTUPINFOW si; |
| 567 | + PROCESS_INFORMATION pi; |
| 568 | + BOOL rc; |
| 569 | + Blob binCmd; |
| 570 | + wchar_t *wcsCmd; |
| 571 | + /* Build the command string and make sure the process does not get |
| 572 | + ** handled as CGI. */ |
| 573 | + blob_zero(&binCmd); |
| 574 | + blob_appendf(&binCmd, "\"%s\" backoffice --nocgi -R \"%s\"", |
| 575 | + g.nameOfExe, backofficeDb); |
| 576 | + wcsCmd = fossil_utf8_to_unicode(blob_str(&binCmd)); |
| 577 | + blob_reset(&binCmd); |
| 578 | + /* Start a detached process. */ |
| 579 | + ZeroMemory(&pi, sizeof(pi)); |
| 580 | + ZeroMemory(&si, sizeof(si)); |
| 581 | + si.cb = sizeof(si); |
| 582 | + rc = CreateProcessW( |
| 583 | + NULL, /* Application Name */ |
| 584 | + wcsCmd, /* Command-line */ |
| 585 | + NULL, /* Process attributes */ |
| 586 | + NULL, /* Thread attributes */ |
| 587 | + FALSE, /* Inherit Handles */ |
| 588 | + DETACHED_PROCESS, /* Create flags */ |
| 589 | + NULL, /* Environment */ |
| 590 | + NULL, /* Current directory */ |
| 591 | + &si, /* Startup Info */ |
| 592 | + &pi /* Process Info */ |
| 593 | + ); |
| 594 | + fossil_unicode_free(wcsCmd); |
| 595 | + if( rc ){ |
| 596 | + CloseHandle(pi.hProcess); |
| 597 | + CloseHandle(pi.hThread); |
| 598 | + backofficeTrace( |
| 599 | + "/***** Subprocess %d creates backoffice child %d *****/\n", |
| 600 | + GETPID(), pi.dwProcessId); |
| 601 | + return; |
| 602 | + } |
| 580 | 603 | } |
| 581 | 604 | #else /* unix */ |
| 582 | 605 | { |
| 583 | 606 | pid_t pid = fork(); |
| 584 | 607 | if( pid>0 ){ |
| 585 | 608 | |