Beispiel #1
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 ;
   }
Beispiel #2
0
   INT32 mainEntry( INT32 argc, CHAR** argv )
   {
      INT32 rc = SDB_OK ;
      CHAR dialogFile[ OSS_MAX_PATHSIZE + 1 ] = {0} ;
      cCMService svc;
      cPmdDaemon daemon( PMDDMN_SVCNAME_DEFAULT ) ;
      BOOLEAN asProc = FALSE ;
      po::variables_map vm ;

      rc = ossGetEWD( dialogFile, OSS_MAX_PATHSIZE ) ;
      if ( rc )
      {
         ossPrintf( "Failed to get working directory, rc: %d"OSS_NEWLINE, rc ) ;
         goto error ;
      }
      rc = engine::utilCatPath( dialogFile, OSS_MAX_PATHSIZE, SDBCM_LOG_PATH ) ;
      if ( rc )
      {
         ossPrintf( "Failed to make dialog path, rc: %d"OSS_NEWLINE, rc ) ;
         goto error ;
      }
      rc = ossMkdir( dialogFile, OSS_CREATE|OSS_READWRITE ) ;
      if ( rc && SDB_FE != rc )
      {
         ossPrintf( "Create dialog dir[%s] failed, rc: %d"OSS_NEWLINE,
                    dialogFile, rc ) ;
         goto error ;
      }
      rc = engine::utilCatPath( dialogFile, OSS_MAX_PATHSIZE,
                                PMDDMN_DIALOG_FILE_NAME ) ;
      if ( rc )
      {
         ossPrintf( "Failed to make dialog path, rc: %d"OSS_NEWLINE, rc ) ;
         goto error ;
      }

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

      sdbEnablePD( dialogFile ) ;
      setPDLevel( PDINFO ) ;

      PD_LOG( PDEVENT, "Start cmd[Ver: %d.%d, Release: %d, Build: %s]...",
              SDB_ENGINE_VERISON_CURRENT, SDB_ENGINE_SUBVERSION_CURRENT,
              SDB_ENGINE_RELEASE_CURRENT, SDB_ENGINE_BUILD_TIME ) ;

      svc.setArgInfo( argc, argv ) ;
      rc = svc.init() ;
      PD_RC_CHECK( rc, PDERROR, "Failed to init cm(rc=%d)", rc ) ;
      rc = daemon.addChildrenProcess( &svc ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to add childrenProcess(rc=%d)", rc ) ;
      rc = daemon.init();
      if ( rc != SDB_OK )
      {
         ossPrintf( "Failed to init daemon process(rc=%d)", rc ) ;
         goto error;
      }

      rc = daemon.run( argc, argv, asProc );
      PD_RC_CHECK( rc, PDERROR, "Execute failed(rc=%d)", rc ) ;

   done:
      daemon.stop() ;
      PD_LOG( PDEVENT, "Stop programme." ) ;
      return SDB_OK == rc ? 0 : 1 ;
   error:
      goto done ;
   }