Index: src/alerts.c ================================================================== --- src/alerts.c +++ src/alerts.c @@ -843,14 +843,24 @@ 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"); Index: src/backoffice.c ================================================================== --- src/backoffice.c +++ src/backoffice.c @@ -284,11 +284,11 @@ 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 +#endif } /* ** Check to see if the process identified by pid has finished. If ** we cannot prove the the process is still running, return true. @@ -296,11 +296,11 @@ 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 +#endif } /* ** Return a process id number for the current process */ @@ -470,10 +470,12 @@ 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 @@ -600,11 +602,11 @@ Blob cmd; if( !file_isfile(g.argv[i], ExtFILE) ) continue; if( iNow && iNow>file_mtime(g.argv[i],ExtFILE) ) continue; blob_init(&cmd, 0, 0); blob_append_escaped_arg(&cmd, g.nameOfExe); - blob_append(&cmd, " backoffice --nodelay", -1); + blob_append(&cmd, " backoffice --nocgi --nodelay", -1); if( g.fAnyTrace ){ blob_append(&cmd, " --trace", -1); } blob_append_escaped_arg(&cmd, g.argv[i]); nCmd++; @@ -643,26 +645,47 @@ 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; + 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 ){ Index: src/main.c ================================================================== --- src/main.c +++ src/main.c @@ -682,11 +682,11 @@ sqlite3_vfs_register(pVfs, 1); }else{ fossil_fatal("no such VFS: \"%s\"", g.zVfsName); } } - if( fossil_getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){ + if( !find_option("nocgi", 0, 0) && fossil_getenv("GATEWAY_INTERFACE")!=0 ){ zCmdName = "cgi"; g.isHTTP = 1; }else if( g.argc<2 && !fossilExeHasAppendedRepo() ){ fossil_print( "Usage: %s COMMAND ...\n" @@ -2282,11 +2282,10 @@ 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; } Index: src/popen.c ================================================================== --- src/popen.c +++ src/popen.c @@ -93,11 +93,11 @@ NULL, /* Application Name */ zCmd, /* Command-line */ NULL, /* Process attributes */ NULL, /* Thread attributes */ TRUE, /* Inherit Handles */ - 0, /* Create flags */ + CREATE_NO_WINDOW, /* Create flags */ NULL, /* Environment */ NULL, /* Current directory */ &si, /* Startup Info */ &pi /* Process Info */ );