示例#1
0
   INT32 utilGetServiceByConfigPath( const string & confPath,
                                     string & svcname,
                                     const string &defaultName,
                                     BOOLEAN allowFileNotExist )
   {
      INT32 rc = SDB_OK ;
      po::options_description desc ;
      po::variables_map vm ;
      desc.add_options()
         ( PMD_OPTION_SVCNAME, po::value<string>(), "" ) ;
      CHAR conf[OSS_MAX_PATHSIZE + 1] = { 0 } ;
      if ( defaultName.empty() )
      {
         svcname = boost::lexical_cast<string>(OSS_DFT_SVCPORT) ;
      }
      else
      {
         svcname = defaultName ;
      }

      rc = utilBuildFullPath ( confPath.c_str(), PMD_DFT_CONF,
                               OSS_MAX_PATHSIZE, conf ) ;
      if ( rc )
      {
         std::cerr << "Failed to build full path, rc: " << rc << std::endl ;
         goto error ;
      }

      if ( allowFileNotExist && SDB_OK != ossAccess( conf ) )
      {
         goto done ;
      }

      rc = utilReadConfigureFile( conf, desc, vm ) ;
      if ( allowFileNotExist && SDB_IO == rc )
      {
         rc = SDB_OK ;
         goto done ;
      }
      if ( rc )
      {
         goto error ;
      }

      if ( vm.count ( PMD_OPTION_SVCNAME ) )
      {
         svcname = vm [ PMD_OPTION_SVCNAME ].as<string>() ;
      }

   done :
      return rc ;
   error :
      goto done ;
   }
示例#2
0
   INT32 utilGetCMService( const string & rootPath,
                           const string & hostname,
                           string & svcname,
                           BOOLEAN allowFileNotExist )
   {
      INT32 rc = SDB_OK ;
      po::options_description desc ;
      po ::variables_map vm ;
      CHAR confFile[ OSS_MAX_PATHSIZE + 1 ] = { 0 } ;
      desc.add_options()
         ( "*", po::value<string>(), "" )
         ;
      string hostnameKey = hostname + string( SDBCM_CONF_PORT ) ;
      svcname = boost::lexical_cast<string>( SDBCM_DFT_PORT ) ;

      rc = utilBuildFullPath( rootPath.c_str(), SDBCM_CONF_PATH_FILE,
                              OSS_MAX_PATHSIZE, confFile ) ;
      if ( rc )
      {
         std::cerr << "Failed to build full path, rc: " << rc << std::endl ;
         goto error ;
      }

      if ( allowFileNotExist && SDB_OK != ossAccess( confFile ) )
      {
         goto done ;
      }

      rc = utilReadConfigureFile( confFile, desc, vm ) ;
      if ( allowFileNotExist && SDB_IO == rc )
      {
         rc = SDB_OK ;
         goto done ;
      }
      if ( rc )
      {
         goto error ;
      }

      if ( vm.count ( hostnameKey ) )
      {
         svcname = vm [ hostnameKey ].as<string>() ;
      }
      else if ( vm.count( SDBCM_CONF_DFTPORT ) )
      {
         svcname = vm [ SDBCM_CONF_DFTPORT ].as<string>() ;
      }

   done:
      return rc ;
   error:
      goto done ;
   }
示例#3
0
   INT32 utilGetDBPathByConfigPath( const string & confPath,
                                    string &dbPath,
                                    BOOLEAN allowFileNotExist )
   {
      INT32 rc = SDB_OK ;
      po::options_description desc ;
      po::variables_map vm ;
      desc.add_options()
         ( PMD_OPTION_DBPATH, po::value<string>(), "" ) ;
      CHAR conf[OSS_MAX_PATHSIZE + 1] = { 0 } ;
      dbPath = PMD_CURRENT_PATH ;

      rc = utilBuildFullPath ( confPath.c_str(), PMD_DFT_CONF,
                               OSS_MAX_PATHSIZE, conf ) ;
      if ( rc )
      {
         std::cerr << "Failed to build full path, rc: " << rc << std::endl ;
         goto error ;
      }

      if ( allowFileNotExist && SDB_OK != ossAccess( conf ) )
      {
         goto done ;
      }

      rc = utilReadConfigureFile( conf, desc, vm ) ;
      if ( allowFileNotExist && SDB_IO == rc )
      {
         rc = SDB_OK ;
         goto done ;
      }
      if ( rc )
      {
         goto error ;
      }

      if ( vm.count ( PMD_OPTION_DBPATH ) )
      {
         dbPath = vm [ PMD_OPTION_DBPATH ].as<string>() ;
      }

   done :
      return rc ;
   error :
      goto done ;
   }
示例#4
0
   INT32 utilGetRoleByConfigPath( const string &confPath, INT32 &role,
                                  BOOLEAN allowFileNotExist )
   {
      INT32 rc = SDB_OK ;
      po::options_description desc ;
      po::variables_map vm ;
      desc.add_options()
         ( PMD_OPTION_ROLE, po::value<string>(), "" ) ;
      CHAR conf[OSS_MAX_PATHSIZE + 1] = { 0 } ;
      role = SDB_ROLE_STANDALONE ;

      rc = utilBuildFullPath ( confPath.c_str(), PMD_DFT_CONF,
                               OSS_MAX_PATHSIZE, conf ) ;
      if ( rc )
      {
         std::cerr << "Failed to build full path, rc: " << rc << std::endl ;
         goto error ;
      }

      if ( allowFileNotExist && SDB_OK != ossAccess( conf ) )
      {
         goto done ;
      }

      rc = utilReadConfigureFile( conf, desc, vm ) ;
      if ( allowFileNotExist && SDB_IO == rc )
      {
         rc = SDB_OK ;
         goto done ;
      }
      if ( rc )
      {
         goto error ;
      }

      if ( vm.count ( PMD_OPTION_ROLE ) )
      {
         string roleStr = vm [ PMD_OPTION_ROLE ].as<string>() ;
         role = utilGetRoleEnum( roleStr.c_str() ) ;
      }

   done :
      return rc ;
   error :
      goto done ;
   }
示例#5
0
   INT32 pmdThreadMainEntry( INT32 argc, CHAR** argv )
   {
      INT32 rc = SDB_OK ;
      pmdKRCB *krcb = pmdGetKRCB() ;
      CHAR currentPath[ OSS_MAX_PATHSIZE + 1 ] = { 0 } ;
      CHAR dialogPath[ OSS_MAX_PATHSIZE + 1 ] = { 0 } ;
      CHAR dialogFile[ OSS_MAX_PATHSIZE + 1 ] = { 0 } ;
      INT32 delSig[] = { 17, 0 } ; // del SIGCHLD
      CHAR verText[ OSS_MAX_PATHSIZE + 1 ] = { 0 } ;
      po::variables_map vm ;

      rc = initArgs( argc, argv, vm ) ;
      if ( rc )
      {
         if ( SDB_PMD_HELP_ONLY == rc || SDB_PMD_VERSION_ONLY == rc )
         {
            rc = SDB_OK ;
         }
         goto done ;
      }

      rc = ossGetEWD( currentPath, OSS_MAX_PATHSIZE ) ;
      if ( rc )
      {
         std::cout << "Get current path failed: " << rc << std::endl ;
         goto error ;
      }
      ossChDir( currentPath ) ;

      rc = utilBuildFullPath( currentPath, SDBCM_LOG_PATH,
                              OSS_MAX_PATHSIZE, dialogPath ) ;
      if ( rc )
      {
         std::cout << "Build dialog path failed: " << rc << std::endl ;
         goto error ;
      }
      rc = ossMkdir( dialogPath ) ;
      if ( rc && SDB_FE != rc )
      {
         std::cout << "Create dialog dir: " << dialogPath << " failed: "
                   << rc << std::endl ;
         goto error ;
      }
      rc = utilBuildFullPath( dialogPath, SDBCM_DIALOG_FILE_NAME,
                              OSS_MAX_PATHSIZE, dialogFile ) ;
      if ( rc )
      {
         std::cout << "Build dialog path failed: " << rc << std::endl ;
         goto error ;
      }
      sdbEnablePD( dialogFile ) ;

      ossSprintVersion( "Version", verText, OSS_MAX_PATHSIZE, FALSE ) ;
      PD_LOG( PDEVENT, "Start cm[%s]...", verText) ;

      rc = sdbGetOMAgentOptions()->init( currentPath ) ;
      if ( rc )
      {
         PD_LOG( PDERROR, "Failed to init config, rc: %d", rc ) ;
         goto error ;
      }
      if ( vm.count( PMD_OPTION_CURUSER ) )
      {
         sdbGetOMAgentOptions()->setCurUser() ;
      }
      if ( vm.count( PMD_OPTION_STANDALONE ) )
      {
         sdbGetOMAgentOptions()->setStandAlone() ;
         if ( vm.count( PMD_OPTION_ALIVE_TIME ) )
         {
            UINT32 timeout = vm[ PMD_OPTION_ALIVE_TIME ].as<INT32>() ;
            sdbGetOMAgentOptions()->setAliveTimeout( timeout ) ;
         }
      }
      if ( vm.count( PMD_OPTION_PORT ) )
      {
         string svcname = vm[ PMD_OPTION_PORT ].as<string>() ;
         sdbGetOMAgentOptions()->setCMServiceName( svcname.c_str() ) ;
         pmdSetLocalPort( (UINT16)ossAtoi( svcname.c_str() ) ) ;
      }
      setPDLevel( sdbGetOMAgentOptions()->getDiagLevel() ) ;

      {
         string configs ;
         sdbGetOMAgentOptions()->toString( configs ) ;
         PD_LOG( PDEVENT, "All configs:\n%s", configs.c_str() ) ;
      }

      pmdSetDBRole( SDB_ROLE_OMA ) ;

      rc = pmdEnableSignalEvent( dialogPath, (PMD_ON_QUIT_FUNC)pmdOnQuit,
                                 delSig ) ;
      PD_RC_CHECK ( rc, PDERROR, "Failed to enable trap, rc: %d", rc ) ;

#if defined( _LINUX )
      signal( SIGCHLD, SIG_IGN ) ;
#endif // _LINUX

      PMD_REGISTER_CB( sdbGetOMAgentMgr() ) ;

      rc = krcb->init() ;
      PD_RC_CHECK( rc, PDERROR, "Failed to init krcb, rc: %d", rc ) ;

      {
         EDUID agentEDU = PMD_INVALID_EDUID ;
         pmdEDUMgr *eduMgr = krcb->getEDUMgr() ;
         rc = eduMgr->startEDU ( EDU_TYPE_PIPESLISTENER,
                                 (void*)sdbGetOMAgentOptions()->getCMServiceName(),
                                 &agentEDU ) ;
         PD_RC_CHECK( rc, PDERROR, "Start PIPELISTENER failed, rc: %d",
                      rc ) ;

         rc = eduMgr->waitUntil( agentEDU, PMD_EDU_RUNNING ) ;
         PD_RC_CHECK( rc, PDERROR, "Wait pipe listener to running "
                      "failed, rc: %d", rc ) ;
      }

#if defined (_LINUX)
      {
         CHAR pmdProcessName [ OSS_RENAME_PROCESS_BUFFER_LEN + 1 ] = {0} ;
         ossSnprintf ( pmdProcessName, OSS_RENAME_PROCESS_BUFFER_LEN,
                       "%s(%s)", utilDBTypeStr( pmdGetDBType() ),
                       sdbGetOMAgentOptions()->getCMServiceName() ) ;
         ossEnableNameChanges ( argc, argv ) ;
         ossRenameProcess ( pmdProcessName ) ;
      }
#endif // _LINUX

      while ( PMD_IS_DB_UP() )
      {
         ossSleepsecs ( 1 ) ;
      }
      rc = krcb->getShutdownCode() ;

   done:
      PMD_SHUTDOWN_DB( rc ) ;
      pmdSetQuit() ;
      krcb->destroy () ;
      PD_LOG ( PDEVENT, "Stop programme, exit code: %d",
               krcb->getShutdownCode() ) ;
      return rc == SDB_OK ? 0 : 1 ;
   error:
      goto done ;
   }
示例#6
0
   INT32 _pmdController::initForeignModule( const CHAR *moduleName )
   {
      INT32 rc = SDB_OK ;
      UINT16 protocolPort = 0 ;
      CHAR rootPath[ OSS_MAX_PATHSIZE + 1 ] = { 0 } ;
      CHAR path[ OSS_MAX_PATHSIZE + 1 ] = { 0 } ;

      if (  NULL == moduleName || '\0' == moduleName[ 0 ] )
      {
         goto done ;
      }

      _fapMongo = SDB_OSS_NEW pmdModuleLoader() ;
      if ( NULL == _fapMongo )
      {
         PD_LOG( PDERROR, "Failed to alloc foreign access protocol module" ) ;
         rc = SDB_OOM ;
         goto error ;
      }
      rc = ossGetEWD( rootPath, OSS_MAX_PATHSIZE ) ;
      if ( rc )
      {
         ossPrintf ( "Failed to get excutable file's working "
                     "directory"OSS_NEWLINE ) ;
         goto error ;
      }
      rc = utilBuildFullPath( rootPath, FAP_MODULE_PATH,
                              OSS_MAX_PATHSIZE, path );
      if ( rc )
      {
         ossPrintf( "Failed to build module path: %d"OSS_NEWLINE, rc ) ;
         goto error ;
      }
      rc = _fapMongo->load( moduleName, path ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to load module: %s, path: %s"
                   " rc: %d", moduleName, FAP_MODULE_PATH, rc ) ;
      rc = _fapMongo->create( _protocol ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to create protocol service" ) ;

      SDB_ASSERT( _protocol, "Foreign access protocol can not be NULL" ) ;
      rc = _protocol->init( pmdGetKRCB() ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to init protocol" ) ;

      // memory will be freed in fini
      protocolPort = ossAtoi( _protocol->getServiceName() ) ;
      _pMongoListener = SDB_OSS_NEW ossSocket( protocolPort ) ;
      if ( !_pMongoListener )
      {
         PD_LOG( PDERROR, "Failed to alloc socket" ) ;
         rc = SDB_OOM ;
         goto error ;
      }
      rc = _pMongoListener->initSocket() ;
      PD_RC_CHECK( rc, PDERROR, "Failed to init FAP listener socket[%d], "
                   "rc: %d", protocolPort, rc ) ;

      rc = _pMongoListener->bind_listen() ;
      PD_RC_CHECK( rc, PDERROR, "Failed to bind FAP listener socket[%d], "
                   "rc: %d", protocolPort, rc ) ;
      PD_LOG( PDEVENT, "Listerning on port[%d]", protocolPort ) ;

   done:
      return rc ;
   error:
      goto done ;
   }