Index: src/winhttp.c ================================================================== --- src/winhttp.c +++ src/winhttp.c @@ -267,24 +267,40 @@ ** message string. Call fossil_mbcs_free() to deallocate any memory used ** to store the message string when done. */ static char *win32_get_last_errmsg(void){ DWORD nMsg; + DWORD nErr = GetLastError(); LPTSTR tmp = NULL; char *zMsg = NULL; + /* Try first to get the error text in english. */ nMsg = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, - GetLastError(), + nErr, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPTSTR) &tmp, 0, NULL ); + if( !nMsg ){ + /* No english, get what the system has available. */ + nMsg = FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + nErr, + 0, + (LPTSTR) &tmp, + 0, + NULL + ); + } if( nMsg ){ zMsg = fossil_mbcs_to_utf8(tmp); }else{ fossil_fatal("unable to get system error message."); } @@ -301,11 +317,11 @@ static void win32_report_service_status( DWORD dwCurrentState, /* The current state of the service */ DWORD dwWin32ExitCode, /* The error code to report */ DWORD dwWaitHint /* The estimated time for a pending operation */ ){ - if( dwCurrentState==SERVICE_START_PENDING) { + if( dwCurrentState==SERVICE_START_PENDING ){ ssStatus.dwControlsAccepted = 0; }else{ ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; } ssStatus.dwCurrentState = dwCurrentState; @@ -477,11 +493,11 @@ ** Password for the user account. ** ** The following options are more or less the same as for the "server" ** command and influence the behaviour of the http server: ** -** -p|--port TCPPORT +** -P|--port TCPPORT ** ** Specifies the TCP port (default port is 8080) on which the ** server should listen. ** ** -R|--repository REPOSITORY @@ -544,69 +560,62 @@ if( g.argc<3 ){ usage("create|delete|show|start|stop ..."); } zMethod = g.argv[2]; n = strlen(zMethod); - if( g.argc==4 ){ - zSvcName = g.argv[3]; - } if( strncmp(zMethod, "create", n)==0 ){ SC_HANDLE hScm; SC_HANDLE hSvc; SERVICE_DESCRIPTION svcDescr = {"Fossil - Distributed Software Configuration Management"}; char *zErrFmt = "unable to create service '%s': %s"; DWORD dwStartType = SERVICE_DEMAND_START; - const char *zDisplay; - const char *zStart; - const char *zUsername; - const char *zPassword; - const char *zPort; - const char *zNotFound; - const char *zLocalAuth; - const char *zRepository; + const char *zDisplay = find_option("display", "D", 1); + const char *zStart = find_option("start", "S", 1); + const char *zUsername = find_option("username", "U", 1); + const char *zPassword = find_option("password", "W", 1); + const char *zPort = find_option("port", "P", 1); + const char *zNotFound = find_option("notfound", 0, 1); + const char *zLocalAuth = find_option("localauth", 0, 0); + const char *zRepository = find_option("repository", "R", 1); Blob binPath; + verify_all_options(); + if( g.argc==4 ){ + zSvcName = g.argv[3]; + }else if( g.argc>4 ){ + fossil_fatal("to much arguments for create method."); + } /* Process service creation specific options. */ - zDisplay = find_option("display", "D", 1); if( !zDisplay ){ zDisplay = zSvcName; } - zStart = find_option("start", "S", 1); if( zStart ){ if( strncmp(zStart, "auto", strlen(zStart))==0 ){ dwStartType = SERVICE_AUTO_START; - }else if( strncmp(zStart, "manual", strlen(zStart))==0 ){ + }else if( strncmp(zStart, "manual", strlen(zStart))==0 ){ dwStartType = SERVICE_DEMAND_START; }else{ fossil_fatal(zErrFmt, zSvcName, "specify 'auto' or 'manual' for the '-S|--start' option"); } } - zUsername = find_option("username", "U", 1); - zPassword = find_option("password", "W", 1); /* Process options for Fossil running as server. */ - zPort = find_option("port", "P", 1); if( zPort && (atoi(zPort)<=0) ){ fossil_fatal(zErrFmt, zSvcName, "port number must be in the range 1 - 65535."); } - zNotFound = find_option("notfound", 0, 1); - zLocalAuth = find_option("localauth", 0, 0); - zRepository = find_option("repository", "R", 1); if( !zRepository ){ db_must_be_within_tree(); }else if( file_isdir(zRepository)==1 ){ g.zRepositoryName = mprintf("%s", zRepository); file_simplify_name(g.zRepositoryName, -1, 0); }else{ db_open_repository(zRepository); } db_close(0); - verify_all_options(); - if( g.argc>4 ) fossil_fatal("to much arguments for create method."); /* Build the fully-qualified path to the service binary file. */ blob_zero(&binPath); blob_appendf(&binPath, "\"%s\" server", fossil_nameofexe()); if( zPort ) blob_appendf(&binPath, " --port %s", zPort); if( zNotFound ) blob_appendf(&binPath, " --notfound \"%s\"", zNotFound); @@ -642,11 +651,15 @@ SC_HANDLE hSvc; SERVICE_STATUS sstat; char *zErrFmt = "unable to delete service '%s': %s"; verify_all_options(); - if( g.argc>4 ) fossil_fatal("to much arguments for delete method."); + if( g.argc==4 ){ + zSvcName = g.argv[3]; + }else if( g.argc>4 ){ + fossil_fatal("to much arguments for delete method."); + } hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg()); hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS); if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg()); QueryServiceStatus(hSvc, &sstat); @@ -706,11 +719,15 @@ "Continue pending", "Pause pending", "Paused" }; const char *zSvcState = ""; verify_all_options(); - if( g.argc>4 ) fossil_fatal("to much arguments for show method."); + if( g.argc==4 ){ + zSvcName = g.argv[3]; + }else if( g.argc>4 ){ + fossil_fatal("to much arguments for show method."); + } hScm = OpenSCManager(NULL, NULL, GENERIC_READ); if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg()); hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), GENERIC_READ); if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg()); /* Get the service configuration */ @@ -784,11 +801,15 @@ SC_HANDLE hSvc; SERVICE_STATUS sstat; char *zErrFmt = "unable to start service '%s': %s"; verify_all_options(); - if( g.argc>4 ) fossil_fatal("to much arguments for start method."); + if( g.argc==4 ){ + zSvcName = g.argv[3]; + }else if( g.argc>4 ){ + fossil_fatal("to much arguments for start method."); + } hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg()); hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS); if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg()); QueryServiceStatus(hSvc, &sstat); @@ -816,11 +837,15 @@ SC_HANDLE hSvc; SERVICE_STATUS sstat; char *zErrFmt = "unable to stop service '%s': %s"; verify_all_options(); - if( g.argc>4 ) fossil_fatal("to much arguments for stop method."); + if( g.argc==4 ){ + zSvcName = g.argv[3]; + }else if( g.argc>4 ){ + fossil_fatal("to much arguments for stop method."); + } hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg()); hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS); if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg()); QueryServiceStatus(hSvc, &sstat);