Fossil SCM

Attempt to get the backoffice running on Windows.

tsbg 2018-12-10 08:07 trunk
Commit c52fb5eddb6099933607697e5144670d3103bd817cbeb09c0d3c093477e910f2
+10
--- src/alerts.c
+++ src/alerts.c
@@ -843,14 +843,24 @@
843843
if( rc!=SQLITE_OK ){
844844
emailerError(p, "Failed to insert email message into output queue.\n"
845845
"%s", sqlite3_errmsg(p->db));
846846
}
847847
}else if( p->zCmd ){
848
+#if !defined(_WIN32)
848849
FILE *out = popen(p->zCmd, "w");
850
+#else
851
+ int in, pid;
852
+ FILE *out;
853
+ popen2(p->zCmd, &in, &out, &pid);
854
+#endif
849855
if( out ){
850856
fwrite(blob_buffer(&all), 1, blob_size(&all), out);
857
+#if !defined(_WIN32)
851858
pclose(out);
859
+#else
860
+ pclose2(in ,out, pid);
861
+#endif
852862
}else{
853863
emailerError(p, "Could not open output pipe \"%s\"", p->zCmd);
854864
}
855865
}else if( p->zDir ){
856866
char *zFile = file_time_tempname(p->zDir, ".email");
857867
--- src/alerts.c
+++ src/alerts.c
@@ -843,14 +843,24 @@
843 if( rc!=SQLITE_OK ){
844 emailerError(p, "Failed to insert email message into output queue.\n"
845 "%s", sqlite3_errmsg(p->db));
846 }
847 }else if( p->zCmd ){
 
848 FILE *out = popen(p->zCmd, "w");
 
 
 
 
 
849 if( out ){
850 fwrite(blob_buffer(&all), 1, blob_size(&all), out);
 
851 pclose(out);
 
 
 
852 }else{
853 emailerError(p, "Could not open output pipe \"%s\"", p->zCmd);
854 }
855 }else if( p->zDir ){
856 char *zFile = file_time_tempname(p->zDir, ".email");
857
--- src/alerts.c
+++ src/alerts.c
@@ -843,14 +843,24 @@
843 if( rc!=SQLITE_OK ){
844 emailerError(p, "Failed to insert email message into output queue.\n"
845 "%s", sqlite3_errmsg(p->db));
846 }
847 }else if( p->zCmd ){
848 #if !defined(_WIN32)
849 FILE *out = popen(p->zCmd, "w");
850 #else
851 int in, pid;
852 FILE *out;
853 popen2(p->zCmd, &in, &out, &pid);
854 #endif
855 if( out ){
856 fwrite(blob_buffer(&all), 1, blob_size(&all), out);
857 #if !defined(_WIN32)
858 pclose(out);
859 #else
860 pclose2(in ,out, pid);
861 #endif
862 }else{
863 emailerError(p, "Could not open output pipe \"%s\"", p->zCmd);
864 }
865 }else if( p->zDir ){
866 char *zFile = file_time_tempname(p->zDir, ".email");
867
+41 -18
--- src/backoffice.c
+++ src/backoffice.c
@@ -283,11 +283,11 @@
283283
static int backofficeProcessExists(sqlite3_uint64 pid){
284284
#if defined(_WIN32)
285285
return pid>0 && backofficeWin32ProcessExists((DWORD)pid)!=0;
286286
#else
287287
return pid>0 && kill((pid_t)pid, 0)==0;
288
-#endif
288
+#endif
289289
}
290290
291291
/*
292292
** Check to see if the process identified by pid has finished. If
293293
** we cannot prove the the process is still running, return true.
@@ -295,11 +295,11 @@
295295
static int backofficeProcessDone(sqlite3_uint64 pid){
296296
#if defined(_WIN32)
297297
return pid<=0 || backofficeWin32ProcessExists((DWORD)pid)==0;
298298
#else
299299
return pid<=0 || kill((pid_t)pid, 0)!=0;
300
-#endif
300
+#endif
301301
}
302302
303303
/*
304304
** Return a process id number for the current process
305305
*/
@@ -467,10 +467,12 @@
467467
backofficeWriteLease(&x);
468468
db_end_transaction(0);
469469
backofficeTrace("/***** Begin Backoffice Processing %d *****/\n",
470470
GETPID());
471471
backoffice_work();
472
+ backofficeTrace("/***** End Backoffice Processing %d *****/\n",
473
+ GETPID());
472474
break;
473475
}
474476
if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",0) ){
475477
/* If the no-delay flag is set, exit immediately rather than queuing
476478
** up. Assume that some future request will come along and handle any
@@ -559,26 +561,47 @@
559561
if( strcmp(backofficeDb,"x")==0 ) return;
560562
if( g.db ) return;
561563
if( g.repositoryOpen ) return;
562564
#if defined(_WIN32)
563565
{
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
+ }
580603
}
581604
#else /* unix */
582605
{
583606
pid_t pid = fork();
584607
if( pid>0 ){
585608
--- src/backoffice.c
+++ src/backoffice.c
@@ -283,11 +283,11 @@
283 static int backofficeProcessExists(sqlite3_uint64 pid){
284 #if defined(_WIN32)
285 return pid>0 && backofficeWin32ProcessExists((DWORD)pid)!=0;
286 #else
287 return pid>0 && kill((pid_t)pid, 0)==0;
288 #endif
289 }
290
291 /*
292 ** Check to see if the process identified by pid has finished. If
293 ** we cannot prove the the process is still running, return true.
@@ -295,11 +295,11 @@
295 static int backofficeProcessDone(sqlite3_uint64 pid){
296 #if defined(_WIN32)
297 return pid<=0 || backofficeWin32ProcessExists((DWORD)pid)==0;
298 #else
299 return pid<=0 || kill((pid_t)pid, 0)!=0;
300 #endif
301 }
302
303 /*
304 ** Return a process id number for the current process
305 */
@@ -467,10 +467,12 @@
467 backofficeWriteLease(&x);
468 db_end_transaction(0);
469 backofficeTrace("/***** Begin Backoffice Processing %d *****/\n",
470 GETPID());
471 backoffice_work();
 
 
472 break;
473 }
474 if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",0) ){
475 /* If the no-delay flag is set, exit immediately rather than queuing
476 ** up. Assume that some future request will come along and handle any
@@ -559,26 +561,47 @@
559 if( strcmp(backofficeDb,"x")==0 ) return;
560 if( g.db ) return;
561 if( g.repositoryOpen ) return;
562 #if defined(_WIN32)
563 {
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;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
580 }
581 #else /* unix */
582 {
583 pid_t pid = fork();
584 if( pid>0 ){
585
--- src/backoffice.c
+++ src/backoffice.c
@@ -283,11 +283,11 @@
283 static int backofficeProcessExists(sqlite3_uint64 pid){
284 #if defined(_WIN32)
285 return pid>0 && backofficeWin32ProcessExists((DWORD)pid)!=0;
286 #else
287 return pid>0 && kill((pid_t)pid, 0)==0;
288 #endif
289 }
290
291 /*
292 ** Check to see if the process identified by pid has finished. If
293 ** we cannot prove the the process is still running, return true.
@@ -295,11 +295,11 @@
295 static int backofficeProcessDone(sqlite3_uint64 pid){
296 #if defined(_WIN32)
297 return pid<=0 || backofficeWin32ProcessExists((DWORD)pid)==0;
298 #else
299 return pid<=0 || kill((pid_t)pid, 0)!=0;
300 #endif
301 }
302
303 /*
304 ** Return a process id number for the current process
305 */
@@ -467,10 +467,12 @@
467 backofficeWriteLease(&x);
468 db_end_transaction(0);
469 backofficeTrace("/***** Begin Backoffice Processing %d *****/\n",
470 GETPID());
471 backoffice_work();
472 backofficeTrace("/***** End Backoffice Processing %d *****/\n",
473 GETPID());
474 break;
475 }
476 if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",0) ){
477 /* If the no-delay flag is set, exit immediately rather than queuing
478 ** up. Assume that some future request will come along and handle any
@@ -559,26 +561,47 @@
561 if( strcmp(backofficeDb,"x")==0 ) return;
562 if( g.db ) return;
563 if( g.repositoryOpen ) return;
564 #if defined(_WIN32)
565 {
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 }
603 }
604 #else /* unix */
605 {
606 pid_t pid = fork();
607 if( pid>0 ){
608
-1
--- src/main.c
+++ src/main.c
@@ -2233,11 +2233,10 @@
22332233
g.useLocalauth = find_option("localauth", 0, 0)!=0;
22342234
g.sslNotAvailable = find_option("nossl", 0, 0)!=0;
22352235
g.fNoHttpCompress = find_option("nocompress",0,0)!=0;
22362236
zInFile = find_option("in",0,1);
22372237
if( zInFile ){
2238
- backoffice_disable();
22392238
g.httpIn = fossil_fopen(zInFile, "rb");
22402239
if( g.httpIn==0 ) fossil_fatal("cannot open \"%s\" for reading", zInFile);
22412240
}else{
22422241
g.httpIn = stdin;
22432242
}
22442243
--- src/main.c
+++ src/main.c
@@ -2233,11 +2233,10 @@
2233 g.useLocalauth = find_option("localauth", 0, 0)!=0;
2234 g.sslNotAvailable = find_option("nossl", 0, 0)!=0;
2235 g.fNoHttpCompress = find_option("nocompress",0,0)!=0;
2236 zInFile = find_option("in",0,1);
2237 if( zInFile ){
2238 backoffice_disable();
2239 g.httpIn = fossil_fopen(zInFile, "rb");
2240 if( g.httpIn==0 ) fossil_fatal("cannot open \"%s\" for reading", zInFile);
2241 }else{
2242 g.httpIn = stdin;
2243 }
2244
--- src/main.c
+++ src/main.c
@@ -2233,11 +2233,10 @@
2233 g.useLocalauth = find_option("localauth", 0, 0)!=0;
2234 g.sslNotAvailable = find_option("nossl", 0, 0)!=0;
2235 g.fNoHttpCompress = find_option("nocompress",0,0)!=0;
2236 zInFile = find_option("in",0,1);
2237 if( zInFile ){
 
2238 g.httpIn = fossil_fopen(zInFile, "rb");
2239 if( g.httpIn==0 ) fossil_fatal("cannot open \"%s\" for reading", zInFile);
2240 }else{
2241 g.httpIn = stdin;
2242 }
2243
+1 -1
--- src/popen.c
+++ src/popen.c
@@ -93,11 +93,11 @@
9393
NULL, /* Application Name */
9494
zCmd, /* Command-line */
9595
NULL, /* Process attributes */
9696
NULL, /* Thread attributes */
9797
TRUE, /* Inherit Handles */
98
- 0, /* Create flags */
98
+ CREATE_NO_WINDOW, /* Create flags */
9999
NULL, /* Environment */
100100
NULL, /* Current directory */
101101
&si, /* Startup Info */
102102
&pi /* Process Info */
103103
);
104104
--- src/popen.c
+++ src/popen.c
@@ -93,11 +93,11 @@
93 NULL, /* Application Name */
94 zCmd, /* Command-line */
95 NULL, /* Process attributes */
96 NULL, /* Thread attributes */
97 TRUE, /* Inherit Handles */
98 0, /* Create flags */
99 NULL, /* Environment */
100 NULL, /* Current directory */
101 &si, /* Startup Info */
102 &pi /* Process Info */
103 );
104
--- src/popen.c
+++ src/popen.c
@@ -93,11 +93,11 @@
93 NULL, /* Application Name */
94 zCmd, /* Command-line */
95 NULL, /* Process attributes */
96 NULL, /* Thread attributes */
97 TRUE, /* Inherit Handles */
98 CREATE_NO_WINDOW, /* Create flags */
99 NULL, /* Environment */
100 NULL, /* Current directory */
101 &si, /* Startup Info */
102 &pi /* Process Info */
103 );
104

Keyboard Shortcuts

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