Author: shuston Date: Tue Sep 11 03:01:25 2012 New Revision: 1383229 URL: http://svn.apache.org/viewvc?rev=1383229&view=rev Log: Fix QPID-4269
Modified: qpid/branches/0.18/qpid/cpp/src/windows/QpiddBroker.cpp (contents, props changed) Modified: qpid/branches/0.18/qpid/cpp/src/windows/QpiddBroker.cpp URL: http://svn.apache.org/viewvc/qpid/branches/0.18/qpid/cpp/src/windows/QpiddBroker.cpp?rev=1383229&r1=1383228&r2=1383229&view=diff ============================================================================== --- qpid/branches/0.18/qpid/cpp/src/windows/QpiddBroker.cpp (original) +++ qpid/branches/0.18/qpid/cpp/src/windows/QpiddBroker.cpp Tue Sep 11 03:01:25 2012 @@ -30,8 +30,15 @@ #include "qpid/broker/Broker.h" #include <iostream> +#include <string> +#include <vector> #include <windows.h> +namespace { + // This will accept args from the command line; augmented with service args. + std::vector<std::string> cmdline_args; +} + namespace qpid { namespace broker { @@ -229,6 +236,25 @@ VOID WINAPI SvcCtrlHandler(DWORD control VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv) { + // The arguments can come from 2 places. Args set with the executable + // name when the service is installed come through main() and are now + // in cmdline_args. Arguments set in StartService come into argc/argv + // above; if they are set, argv[0] is the service name. Make command + // line args first; StartService args come later and can override + // command line args. + int all_argc = argc + cmdline_args.size(); + if (argc == 0 && !cmdline_args.empty()) + ++all_argc; // No StartService args, so need to add prog name argv[0] + const char **all_argv = new const char *[all_argc]; + if (all_argc > 0) { + int i = 0; + all_argv[i++] = argc > 0 ? argv[0] : svcName.c_str(); + for (size_t j = 0; j < cmdline_args.size(); ++j) + all_argv[i++] = cmdline_args[j].c_str(); + for (DWORD k = 1; k < argc; ++k) + all_argv[i++] = argv[k]; + } + ::memset(&svcStatus, 0, sizeof(svcStatus)); svcStatusHandle = ::RegisterServiceCtrlHandler(svcName.c_str(), SvcCtrlHandler); @@ -238,7 +264,9 @@ VOID WINAPI ServiceMain(DWORD argc, LPTS svcStatus.dwCurrentState = SERVICE_START_PENDING; ::SetServiceStatus(svcStatusHandle, &svcStatus); // QpiddBroker class resets state to running. - svcStatus.dwWin32ExitCode = run_broker(argc, argv, true); + svcStatus.dwWin32ExitCode = run_broker(all_argc, + const_cast<char**>(all_argv), + true); svcStatus.dwCurrentState = SERVICE_STOPPED; svcStatus.dwCheckPoint = 0; svcStatus.dwWaitHint = 0; @@ -464,6 +492,11 @@ int main(int argc, char* argv[]) { "", (LPSERVICE_MAIN_FUNCTION)qpid::broker::ServiceMain }, { NULL, NULL } }; + // Copy any command line args to be available in case we're started + // as a service. Pick these back up in ServiceMain. + for (int i = 1; i < argc; ++i) + cmdline_args.push_back(argv[i]); + if (!StartServiceCtrlDispatcher(dispatchTable)) { DWORD err = ::GetLastError(); if (err == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) // Run as console Propchange: qpid/branches/0.18/qpid/cpp/src/windows/QpiddBroker.cpp ------------------------------------------------------------------------------ --- svn:mergeinfo (added) +++ svn:mergeinfo Tue Sep 11 03:01:25 2012 @@ -0,0 +1,8 @@ +/qpid/branches/0.5.x-dev/qpid/cpp/src/windows/QpiddBroker.cpp:892761,894875 +/qpid/branches/0.6-release-windows-installer/cpp/src/windows/QpiddBroker.cpp:926803 +/qpid/branches/0.6-release-windows-installer/qpid/cpp/src/windows/QpiddBroker.cpp:926803,927233 +/qpid/branches/QPID-2519/cpp/src/windows/QpiddBroker.cpp:1072051-1079078 +/qpid/branches/java-network-refactor/qpid/cpp/src/windows/QpiddBroker.cpp:805429-825319 +/qpid/branches/qpid-2935/qpid/cpp/src/windows/QpiddBroker.cpp:1061302-1072333 +/qpid/branches/qpid-3346/qpid/cpp/src/windows/QpiddBroker.cpp:1144319-1179855 +/qpid/trunk/qpid/cpp/src/windows/QpiddBroker.cpp:1359595,1363498,1363520,1380890 --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org