diff --git a/bin/PerlDDS/Run_Test.pm b/bin/PerlDDS/Run_Test.pm index cf1126496a7..0a599682f61 100644 --- a/bin/PerlDDS/Run_Test.pm +++ b/bin/PerlDDS/Run_Test.pm @@ -595,7 +595,7 @@ sub _process_common { my $self = shift; my $name = shift; my $params = shift; - my $debug_logging = 1; + my $debug_logging = $self->{dcps_log_level}; if ($$params !~ /-DCPSLogLevel / && $self->{dcps_log_level}) { $$params .= " -DCPSLogLevel $self->{dcps_log_level}"; diff --git a/dds/DCPS/Service_Participant.cpp b/dds/DCPS/Service_Participant.cpp index 662563eca3f..97c4b7792b2 100644 --- a/dds/DCPS/Service_Participant.cpp +++ b/dds/DCPS/Service_Participant.cpp @@ -54,6 +54,10 @@ #include "Service_Participant.inl" #endif /* __ACE_INLINE__ */ +#if !defined (ACE_WIN32) +extern char **environ; +#endif + namespace { void set_log_file_name(const char* fname) @@ -388,6 +392,8 @@ Service_Participant::get_domain_participant_factory(int &argc, } } + parse_env(); + if (parse_args(argc, argv) != 0) { return DDS::DomainParticipantFactory::_nil(); } @@ -578,6 +584,56 @@ Service_Participant::get_domain_participant_factory(int &argc, return DDS::DomainParticipantFactory::_duplicate(dp_factory_servant_.in()); } + + +void Service_Participant::parse_env() +{ +#if defined (ACE_WIN32) + LPTCH env_strings = GetEnvironmentStrings(); + + // If the returned pointer is NULL, exit. + if (!env_strings) { + if (log_level >= LogLevel::Error) { + ACE_ERROR((LM_ERROR, + "(%P|%t) ERROR: Service_Participant::parse_env: Could not get environment strings\n")); + } + return; + } + + LPTSTR env_string = (LPTSTR) env_strings; + + while (*env_string) { + parse_env(ACE_TEXT_ALWAYS_CHAR(env_string)); + env_string += lstrlen(env_string) + 1; + } + FreeEnvironmentStrings(env_strings); + +#else + + for (char** e = environ; *e; ++e) { + parse_env(*e); + } + +#endif +} + +void Service_Participant::parse_env(const String& p) +{ + // Only parse environment variables starting with OPENDDS_. + if (p.substr(0, 8) == "OPENDDS_") { + // Extract everything after OPENDDS_. + const String q = p.substr(8); + // q should have the form key=value + String::size_type pos = q.find('='); + if (pos != String::npos) { + // Split into key and value. + const String key = q.substr(0, pos); + const String value = q.substr(pos + 1); + config_store_->set(key.c_str(), value); + } + } +} + int Service_Participant::parse_args(int& argc, ACE_TCHAR* argv[]) { // Process logging options first, so they are in effect if we need to log diff --git a/dds/DCPS/Service_Participant.h b/dds/DCPS/Service_Participant.h index 23ac9f07773..1663a6e4772 100644 --- a/dds/DCPS/Service_Participant.h +++ b/dds/DCPS/Service_Participant.h @@ -608,6 +608,10 @@ class OpenDDS_Dcps_Export Service_Participant { /// Initialize the thread scheduling and initial priority. void initializeScheduling(); + /// Parse environment variables. + void parse_env(); + void parse_env(const String& s); + /** * Parse the command line for user options. e.g. "-DCPSInfoRepo ". * It consumes -DCPS* options and their arguments diff --git a/tests/DCPS/ConfigFile/ConfigFile.cpp b/tests/DCPS/ConfigFile/ConfigFile.cpp index 2eeaf2140c3..c94f8a9c4c9 100644 --- a/tests/DCPS/ConfigFile/ConfigFile.cpp +++ b/tests/DCPS/ConfigFile/ConfigFile.cpp @@ -40,6 +40,10 @@ ACE_TMAIN(int argc, ACE_TCHAR* argv[]) TheParticipantFactoryWithArgs(argc, argv); TEST_CHECK(dpf.in() != 0); + // From commandline + TEST_CHECK(TheServiceParticipant->config_store()->get("MY_CONFIG_KEY1", "") == "value1"); + // From environment variable + TEST_CHECK(TheServiceParticipant->config_store()->get("MY_CONFIG_KEY2", "") == "value2"); TEST_CHECK(OpenDDS::DCPS::DCPS_debug_level == 1); TEST_CHECK(TheServiceParticipant->n_chunks() == 10); TEST_CHECK(TheServiceParticipant->association_chunk_multiplier() == 5); diff --git a/tests/DCPS/ConfigFile/run_test.pl b/tests/DCPS/ConfigFile/run_test.pl index 61b814bbf35..0c1880a3296 100755 --- a/tests/DCPS/ConfigFile/run_test.pl +++ b/tests/DCPS/ConfigFile/run_test.pl @@ -4,8 +4,6 @@ # -*- perl -*- -use Sys::Hostname; - use Env (DDS_ROOT); use lib "$DDS_ROOT/bin"; use Env (ACE_ROOT); @@ -16,50 +14,29 @@ use File::Copy; use strict; -my $status = 0; +my $test = new PerlDDS::TestFramework(); +$test->{add_pending_timeout} = 0; +$test->setup_discovery(); my $dcpsrepo_ior = "repo.ior"; my $dcpsrepo2_ior = "repo2.ior"; my $dcpsrepo3_ior = "repo3.ior"; - -unlink $dcpsrepo_ior; -my $DCPSREPO = PerlDDS::create_process("$ENV{DDS_ROOT}/bin/DCPSInfoRepo", - " -o $dcpsrepo_ior"); -print $DCPSREPO->CommandLine() . "\n"; -$DCPSREPO->Spawn (); -if (PerlACE::waitforfile_timed ($dcpsrepo_ior, 30) == -1) { - print STDERR "ERROR: waiting for Info Repo IOR file\n"; - $DCPSREPO->Kill (); - exit 1; -} - copy($dcpsrepo_ior, $dcpsrepo2_ior); copy($dcpsrepo_ior, $dcpsrepo3_ior); my $cfg = new PerlACE::ConfigList->check_config('NO_BUILT_IN_TOPICS') ? 'test1_nobits.ini' : 'test1.ini'; -my $TST = PerlDDS::create_process("ConfigFile", "-DCPSConfigFile $cfg"); -print $TST->CommandLine() . "\n"; -my $retcode = $TST->SpawnWaitKill(60); -if ($retcode != 0) { - $status = 1; -} -my $ir = $DCPSREPO->TerminateWaitKill(5); -if ($ir != 0) { - print STDERR "ERROR: DCPSInfoRepo returned $ir\n"; - $status = 1; -} +$test->process('ConfigFile', 'ConfigFile', "-DCPSConfigFile $cfg -OpenDDSMyConfigKey1 value1"); + +$ENV{'OPENDDS_MY_CONFIG_KEY2'} = "value2"; + +$test->start_process('ConfigFile'); + +my $status = $test->finish(5); -unlink $dcpsrepo_ior; unlink $dcpsrepo2_ior; unlink $dcpsrepo3_ior; -if ($status == 0) { - print "test PASSED.\n"; -} -else { - print STDERR "test FAILED.\n"; -} exit $status;