diff options
author | Phil Mesnier <mesnier_p@ociweb.com> | 2014-06-18 21:09:12 +0000 |
---|---|---|
committer | Phil Mesnier <mesnier_p@ociweb.com> | 2014-06-18 21:09:12 +0000 |
commit | aa98b9621da001bc50922d4462ad859d3fb008ea (patch) | |
tree | 90a86232d9b118c529a3b6192131ada29307861b | |
parent | 05790a2e6a7973a70065eaf1a0edc568e3fb33a2 (diff) | |
download | ATCD-aa98b9621da001bc50922d4462ad859d3fb008ea.tar.gz |
Wed Jun 18 20:33:36 UTC 2014 Phil Mesnier <mesnier_p@ociweb.com>
* orbsvcs/Naming_Service/NT_Naming_Server.cpp:
* orbsvcs/Naming_Service/NT_Naming_Service.h:
* orbsvcs/Naming_Service/NT_Naming_Service.cpp:
* orbsvcs/Naming_Service/README:
Added command line interface for populating the service command line
arguments without the need to invoke regedit.
-rw-r--r-- | TAO/ChangeLog | 9 | ||||
-rw-r--r-- | TAO/NEWS | 3 | ||||
-rw-r--r-- | TAO/orbsvcs/Naming_Service/NT_Naming_Server.cpp | 28 | ||||
-rw-r--r-- | TAO/orbsvcs/Naming_Service/NT_Naming_Service.cpp | 135 | ||||
-rw-r--r-- | TAO/orbsvcs/Naming_Service/NT_Naming_Service.h | 8 | ||||
-rw-r--r-- | TAO/orbsvcs/Naming_Service/README | 17 |
6 files changed, 169 insertions, 31 deletions
diff --git a/TAO/ChangeLog b/TAO/ChangeLog index 8ed6891020f..8be94390eb6 100644 --- a/TAO/ChangeLog +++ b/TAO/ChangeLog @@ -1,3 +1,12 @@ +Wed Jun 18 20:33:36 UTC 2014 Phil Mesnier <mesnier_p@ociweb.com> + + * orbsvcs/Naming_Service/NT_Naming_Server.cpp: + * orbsvcs/Naming_Service/NT_Naming_Service.h: + * orbsvcs/Naming_Service/NT_Naming_Service.cpp: + * orbsvcs/Naming_Service/README: + Added command line interface for populating the service command line + arguments without the need to invoke regedit. + Tue Jun 17 16:10:49 UTC 2014 Phil Mesnier <mesnier_p@ociweb.com> * orbsvcs/orbsvcs/Naming/FaultTolerant/FT_Naming_Manager.cpp: @@ -9,6 +9,9 @@ USER VISIBLE CHANGES BETWEEN TAO-2.2.6 and TAO-2.2.7 . Fixed active server detection when switching from the primary ImR locator to the backup. +. Added a new command for the windows NT Naming service CLI to set the service's + start up argv list without invoking regedit. + USER VISIBLE CHANGES BETWEEN TAO-2.2.5 and TAO-2.2.6 ==================================================== diff --git a/TAO/orbsvcs/Naming_Service/NT_Naming_Server.cpp b/TAO/orbsvcs/Naming_Service/NT_Naming_Server.cpp index 4fbe16cfa9e..1c158829aeb 100644 --- a/TAO/orbsvcs/Naming_Service/NT_Naming_Server.cpp +++ b/TAO/orbsvcs/Naming_Service/NT_Naming_Server.cpp @@ -60,6 +60,8 @@ private: private: ACE_TCHAR progname[128]; + int opt_setargs; + const ACE_TCHAR *opt_args; int opt_install; int opt_remove; int opt_start; @@ -73,7 +75,9 @@ private: typedef ACE_Singleton<Options, ACE_Mutex> OPTIONS; Options::Options (void) - : opt_install (0), + : opt_setargs (0), + opt_args (0), + opt_install (0), opt_remove (0), opt_start (0), opt_kill (0), @@ -96,7 +100,8 @@ Options::print_usage_and_die (void) { ORBSVCS_DEBUG ((LM_INFO, ACE_TEXT("Usage: %s") - ACE_TEXT(" -in -r -s -k -tn -d\n") + ACE_TEXT(" -c [<args>] -in -r -s -k -tn -d\n") + ACE_TEXT(" -c: set or retrieve command line arguments for NT service\n") ACE_TEXT(" -i: Install this program as an NT service, with specified startup\n") ACE_TEXT(" -r: Remove this program from the Service Manager\n") ACE_TEXT(" -s: Start the service\n") @@ -111,12 +116,16 @@ Options::print_usage_and_die (void) void Options::parse_args (int argc, ACE_TCHAR *argv[]) { - ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("i:rskt:d")); + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("c:i:rskt:d")); int c; while ((c = get_opt ()) != -1) switch (c) { + case 'c': + opt_setargs = 1; + opt_args = get_opt.opt_arg (); + break; case 'i': opt_install = 1; opt_startup = ACE_OS::atoi (get_opt.opt_arg ()); @@ -142,13 +151,19 @@ Options::parse_args (int argc, ACE_TCHAR *argv[]) //opt_debug = 1; break; default: - // -i can also be given without a value - if so, it defaults + // -c and -i can also be given without a value - if so, it defaults // to defined value. - if (ACE_OS::strcmp (get_opt.argv ()[get_opt.opt_ind () - 1], ACE_TEXT ("-i")) == 0) + const ACE_TCHAR *lastarg = get_opt.argv ()[get_opt.opt_ind () - 1]; + if (ACE_OS::strcmp (lastarg, ACE_TEXT ("-i")) == 0) { opt_install = 1; opt_startup = DEFAULT_SERVICE_INIT_STARTUP; } + else if (ACE_OS::strcmp (lastarg, ACE_TEXT ("-c")) == 0) + { + opt_setargs = 1; + opt_args = 0; + } else this->print_usage_and_die (); break; @@ -185,6 +200,9 @@ Options::run (int argc, ACE_TCHAR* argv[]) if (opt_start && opt_kill) print_usage_and_die (); + if (opt_setargs) + return SERVICE::instance ()->set_args (opt_args); + if (opt_start) return SERVICE::instance ()->start_svc (); diff --git a/TAO/orbsvcs/Naming_Service/NT_Naming_Service.cpp b/TAO/orbsvcs/Naming_Service/NT_Naming_Service.cpp index 0e125d67d8f..e23c4c968b5 100644 --- a/TAO/orbsvcs/Naming_Service/NT_Naming_Service.cpp +++ b/TAO/orbsvcs/Naming_Service/NT_Naming_Service.cpp @@ -88,45 +88,132 @@ TAO_NT_Naming_Service::handle_exception (ACE_HANDLE) return 0; } -int -TAO_NT_Naming_Service::init (int argc, - ACE_TCHAR *argv[]) +void +TAO_NT_Naming_Service::report_error (const ACE_TCHAR *format, + const ACE_TCHAR *val, + LONG result) { - HKEY hkey = 0; - BYTE buf[ACE_DEFAULT_ARGV_BUFSIZ]; + ACE_TCHAR msg[100]; + ACE_TEXT_FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, + 0, + result, + LANG_SYSTEM_DEFAULT, + msg, + 100,0); + ORBSVCS_DEBUG ((LM_DEBUG, format, val, msg)); +} - *buf = '\0'; +void +TAO_NT_Naming_Service::arg_manip (char *args, DWORD arglen, bool query) +{ + HKEY hkey = 0; - // This solution is very kludgy. It looks in the NT Registry under + // It looks in the NT Registry under // \\HKEY_LOCAL_MACHINE\SOFTWARE\ACE\TAO for the value of // "TaoNamingServiceOptions" for any Naming Service options such as - // "-ORBEndpoint". + // "-ORBListenEndpoints". - // Get Naming Service options from the NT Registry. + // Get/Set Naming Service options from the NT Registry. - ACE_TEXT_RegOpenKeyEx (REGISTRY_KEY_ROOT, - TAO_REGISTRY_SUBKEY, - 0, - KEY_READ, - &hkey); + LONG result = ACE_TEXT_RegOpenKeyEx (REGISTRY_KEY_ROOT, + TAO_REGISTRY_SUBKEY, + 0, + query ? KEY_READ : KEY_WRITE, + &hkey); - DWORD type; - DWORD bufSize = sizeof (buf); + DWORD type = REG_EXPAND_SZ; - ACE_TEXT_RegQueryValueEx (hkey, - TAO_NAMING_SERVICE_OPTS_NAME, - 0, - &type, - buf, - &bufSize); + if (query) + { + *args = '\0'; + if (result == ERROR_SUCCESS) + { + result = ACE_TEXT_RegQueryValueEx (hkey, + TAO_NAMING_SERVICE_OPTS_NAME, + 0, + &type, + (BYTE *)args, + &arglen); + if (result != ERROR_SUCCESS) + { + this->report_error (ACE_TEXT ("Could not query %s, %s\n"), + TAO_NAMING_SERVICE_OPTS_NAME, result); + } + } + else + { + this->report_error (ACE_TEXT ("No key for %s, %s\n"), + TAO_REGISTRY_SUBKEY, result); + } + } + else + { + if (result != ERROR_SUCCESS) + { + result = ACE_TEXT_RegCreateKeyEx (REGISTRY_KEY_ROOT, + TAO_REGISTRY_SUBKEY, + 0, + 0, + 0, + KEY_WRITE, + 0, + &hkey, + 0); + } + DWORD bufSize = static_cast<DWORD>(ACE_OS::strlen (args) + 1); + if (result == ERROR_SUCCESS) + { + result = ACE_TEXT_RegSetValueEx (hkey, + TAO_NAMING_SERVICE_OPTS_NAME, + 0, + type, + (BYTE *)args, + bufSize); + if (result != ERROR_SUCCESS) + { + this->report_error (ACE_TEXT ("Could not set %s, %s\n"), + TAO_NAMING_SERVICE_OPTS_NAME, result); + } + } + else + { + this->report_error (ACE_TEXT ("Could not create key %s, %s\n"), + TAO_REGISTRY_SUBKEY, result); + } + } RegCloseKey (hkey); +} + +int +TAO_NT_Naming_Service::set_args (const ACE_TCHAR *args) +{ + char argbuf[ACE_DEFAULT_ARGV_BUFSIZ]; + if (args == 0) + { + this->arg_manip (argbuf, ACE_DEFAULT_ARGV_BUFSIZ, true); + ACE_OS::printf ("%s\n", argbuf); + } + else + { + ACE_OS::strcpy (argbuf, ACE_TEXT_ALWAYS_CHAR (args)); + this->arg_manip (argbuf, 0, false); + } + return 0; +} + +int +TAO_NT_Naming_Service::init (int argc, + ACE_TCHAR *argv[]) +{ // Add options to the args list (if any). + char argbuf[ACE_DEFAULT_ARGV_BUFSIZ]; + this->arg_manip (argbuf, ACE_DEFAULT_ARGV_BUFSIZ, true); - if (ACE_OS::strlen ((char *) buf) > 0) + if (ACE_OS::strlen (argbuf) > 0) { - ACE_ARGV args ((const char*) buf); + ACE_ARGV args (argbuf); // Allocate the internal args list to be one bigger than the // args list passed into the function. We use a 'save' list in // case we use a 'destructive' args list processor - this way we diff --git a/TAO/orbsvcs/Naming_Service/NT_Naming_Service.h b/TAO/orbsvcs/Naming_Service/NT_Naming_Service.h index 1a6c81d6369..706633fbeb7 100644 --- a/TAO/orbsvcs/Naming_Service/NT_Naming_Service.h +++ b/TAO/orbsvcs/Naming_Service/NT_Naming_Service.h @@ -55,7 +55,15 @@ public: virtual int init (int argc, ACE_TCHAR *argv[]); + /// Helper function for setting or reporting command line args + int set_args (const ACE_TCHAR *args); + private: + void arg_manip (char *args, DWORD arglen, bool query); + void report_error (const ACE_TCHAR *format, + const ACE_TCHAR *val, + LONG result); + // = Keep track of the "command-line" arguments. /// Argument count. int argc_; diff --git a/TAO/orbsvcs/Naming_Service/README b/TAO/orbsvcs/Naming_Service/README index 7030d444f6a..0e7303b5efb 100644 --- a/TAO/orbsvcs/Naming_Service/README +++ b/TAO/orbsvcs/Naming_Service/README @@ -273,6 +273,7 @@ standard out. 1. Syntax % NT_Naming_Server [-i value] + [-c [args]] [-r] [-s] [-k] @@ -282,7 +283,10 @@ standard out. 2. Optional Command-line Arguments -i value - Install this program as an NT service, with specified startup + Install this program as an NT service, with specified startup mode + + -c [args] + Query or supply command line arguments for NT service. -r Remove this program from the Service Manager @@ -293,7 +297,7 @@ standard out. Kill the service -t value - Set startup for an existing service + Set startup mode for an existing service -d Debug; run as a regular application @@ -333,6 +337,15 @@ standard out. other values above. To do this, run NT_Naming_Service with -tn option. n is as explained above for -i. + Use the -c option to supply command line arguments to the service, or + to see what command line is currently set. Note that the arg parameter + must be quoted. Use of environment variables, such as %TAO_ROOT% or + %computername% is allowed in the arg parameter. Any existing arg value + is overwritten, and an empty quoted string will clear the argument list. + The current setting is printed to stdout when -c is used with no arg + parameter. Only Administrator can set args, but any user is able to + retrieve the setting. + In order to debug the service's execution itself, use the -d option. |