X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fconfig%2Fconfig.cpp;h=ab44693e2bba1770606bc2ba927c5555c86688a6;hb=f899326dd481903988b1b947ccff2aca45b3dc27;hp=5259a17025075f7f5c3f16a566040a687cfbaa2d;hpb=9e05c5a9b2fcbf71f7b96bee76a59aab62ec3f9c;p=ric-plt%2Fxapp-frame-cpp.git diff --git a/src/config/config.cpp b/src/config/config.cpp index 5259a17..ab44693 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -111,7 +112,7 @@ void xapp::Config::Listener( ) { if( errno == EAGAIN ) { continue; } else { - fprintf( stderr, " ### CRIT ### config listener read err: %s\n", strerror( errno ) ); return; } } @@ -143,6 +144,10 @@ std::shared_ptr xapp::Config::jparse( std::string ufname ) { fname = ufname; std::ifstream ifs( fname ); + if( ! ifs.is_open() ) { + fprintf( stderr, " ### WARN ### unable to open %s; %s\n", fname.c_str(), strerror( errno ) ); + } + std::string st( (std::istreambuf_iterator( ifs ) ), (std::istreambuf_iterator() ) ); auto new_jh = std::shared_ptr( new xapp::Jhash( st.c_str() ) ); @@ -156,18 +161,30 @@ std::shared_ptr xapp::Config::jparse( std::string ufname ) { The actual meaning of the environment variable is confusing. The name is "path" which should mean that this is the directory in which the config file lives, but the examples - elsewhere suggest that this is a filename (either fully qualified or relative). For now - we will assume that it's a file name, though we could add some intelligence to determine - if it's a directory name or not if it comes to it. + elsewhere suggest that this is a filename (either fully qualified or relative). To prevent + errors, we use some intelligence to determine if it's a directory name or not if it comes to it. */ std::shared_ptr xapp::Config::jparse( ) { const char* data; + std::string filename; + struct stat sb; + + data = getenv( (const char *) "XAPP_DESCRIPTOR_PATH" ); + if( data != NULL ) { + filename = data; + if( stat( data, &sb ) == 0 ) { + if( S_ISDIR( sb.st_mode ) ) { + filename.append( "/config-file.json" ); + } + } else { + fprintf( stderr, " ### ERR ### unable to stat env XAPP_DESCRIPTOR_PATH: %s\n", strerror( errno ) ); + } - if( (data = getenv( (const char *) "XAPP_DESCRIPTOR_PATH" )) == NULL ) { - data = (const char *) "./config-file.json"; + } else { + filename = "./config-file.json"; } - return jparse( std::string( data ) ); + return jparse( filename ); } // --------------------- construction, destruction -------------------------------------------