/* #define SERVER_DEBUG 1 */ int main(int argc, char *argv[]) { int status; rsComm_t rsComm; char *tmpStr; ProcessType = AGENT_PT; #ifdef RUN_SERVER_AS_ROOT #ifndef windows_platform if (initServiceUser() < 0) { exit (1); } #endif #endif #ifdef windows_platform iRODSNtAgentInit(argc, argv); #endif #ifndef windows_platform signal(SIGINT, signalExit); signal(SIGHUP, signalExit); signal(SIGTERM, signalExit); /* set to SIG_DFL as recommended by andy.salnikov so that system() * call returns real values instead of 1 */ signal(SIGCHLD, SIG_DFL); signal(SIGUSR1, signalExit); signal(SIGPIPE, rsPipSigalHandler); #endif #ifndef windows_platform #ifdef SERVER_DEBUG if (isPath ("/tmp/rodsdebug")) sleep (20); #endif #endif #ifdef SYS_TIMING rodsLogLevel(LOG_NOTICE); printSysTiming ("irodsAgent", "exec", 1); #endif memset (&rsComm, 0, sizeof (rsComm)); status = initRsCommWithStartupPack (&rsComm, NULL); if (status < 0) { sendVersion (rsComm.sock, status, 0, NULL, 0); cleanupAndExit (status); } /* Handle option to log sql commands */ tmpStr = getenv (SP_LOG_SQL); if (tmpStr != NULL) { #ifdef IRODS_SYSLOG int j = atoi(tmpStr); rodsLogSqlReq(j); #else rodsLogSqlReq(1); #endif } /* Set the logging level */ tmpStr = getenv (SP_LOG_LEVEL); if (tmpStr != NULL) { int i; i = atoi(tmpStr); rodsLogLevel(i); } else { rodsLogLevel(LOG_NOTICE); /* default */ } #ifdef IRODS_SYSLOG /* Open a connection to syslog */ #ifdef SYSLOG_FACILITY_CODE openlog("rodsAgent",LOG_ODELAY|LOG_PID,SYSLOG_FACILITY_CODE); #else openlog("rodsAgent",LOG_ODELAY|LOG_PID,LOG_DAEMON); #endif #endif status = getRodsEnv (&rsComm.myEnv); if (status < 0) { sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0); cleanupAndExit (status); } #if RODS_CAT if (strstr(rsComm.myEnv.rodsDebug, "CAT") != NULL) { chlDebug(rsComm.myEnv.rodsDebug); } #endif #ifdef RULE_ENGINE_N status = initAgent (RULE_ENGINE_TRY_CACHE, &rsComm); #else status = initAgent (&rsComm); #endif #ifdef SYS_TIMING printSysTiming ("irodsAgent", "initAgent", 0); #endif if (status < 0) { sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0); cleanupAndExit (status); } /* move configConnectControl behind initAgent for now. need zoneName if * the user does not specify one in the input */ initConnectControl (); if (rsComm.clientUser.userName[0] != '\0') { status = chkAllowedUser (rsComm.clientUser.userName, rsComm.clientUser.rodsZone); if (status < 0) { sendVersion (rsComm.sock, status, 0, NULL, 0); cleanupAndExit (status); } } /* send the server version and atatus as part of the protocol. Put * rsComm.reconnPort as the status */ status = sendVersion (rsComm.sock, status, rsComm.reconnPort, rsComm.reconnAddr, rsComm.cookie); if (status < 0) { sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0); cleanupAndExit (status); } #ifdef SYS_TIMING printSysTiming ("irodsAgent", "sendVersion", 0); #endif logAgentProc (&rsComm); status = agentMain (&rsComm); cleanupAndExit (status); return (status); }
/* #define SERVER_DEBUG 1 */ int main( int, char ** ) { int status; rsComm_t rsComm; char *tmpStr; ProcessType = AGENT_PT; // capture server properties irods::server_properties& props = irods::server_properties::getInstance(); irods::error result = props.capture_if_needed(); if ( !result.ok() ) { irods::log( PASSMSG( "failed to read server configuration", result ) ); } #ifdef windows_platform iRODSNtAgentInit( argc, argv ); #endif #ifndef windows_platform signal( SIGINT, signalExit ); signal( SIGHUP, signalExit ); signal( SIGTERM, signalExit ); /* set to SIG_DFL as recommended by andy.salnikov so that system() * call returns real values instead of 1 */ signal( SIGCHLD, SIG_DFL ); signal( SIGUSR1, signalExit ); signal( SIGPIPE, SIG_IGN ); // register irods signal handlers register_handlers(); #endif #ifndef windows_platform #ifdef SERVER_DEBUG if ( isPath( "/tmp/rodsdebug" ) ) { sleep( 20 ); } #endif #endif memset( &rsComm, 0, sizeof( rsComm ) ); rsComm.thread_ctx = ( thread_context* )malloc( sizeof( thread_context ) ); status = initRsCommWithStartupPack( &rsComm, NULL ); // =-=-=-=-=-=-=- // manufacture a network object for comms irods::network_object_ptr net_obj; irods::error ret = irods::network_factory( &rsComm, net_obj ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); } if ( status < 0 ) { sendVersion( net_obj, status, 0, NULL, 0 ); cleanupAndExit( status ); } /* Handle option to log sql commands */ tmpStr = getenv( SP_LOG_SQL ); if ( tmpStr != NULL ) { #ifdef SYSLOG int j = atoi( tmpStr ); rodsLogSqlReq( j ); #else rodsLogSqlReq( 1 ); #endif } /* Set the logging level */ tmpStr = getenv( SP_LOG_LEVEL ); if ( tmpStr != NULL ) { int i; i = atoi( tmpStr ); rodsLogLevel( i ); } else { rodsLogLevel( LOG_NOTICE ); /* default */ } #ifdef SYSLOG /* Open a connection to syslog */ openlog( "rodsAgent", LOG_ODELAY | LOG_PID, LOG_DAEMON ); #endif status = getRodsEnv( &rsComm.myEnv ); if ( status < 0 ) { rodsLog( LOG_ERROR, "agentMain :: getRodsEnv failed" ); sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 ); cleanupAndExit( status ); } ret = setRECacheSaltFromEnv(); if ( !ret.ok() ) { rodsLog( LOG_ERROR, "rodsAgent::main: Failed to set RE cache mutex name\n%s", ret.result().c_str() ); exit( 1 ); } // =-=-=-=-=-=-=- // load server side pluggable api entries irods::api_entry_table& RsApiTable = irods::get_server_api_table(); irods::pack_entry_table& ApiPackTable = irods::get_pack_table(); ret = irods::init_api_table( RsApiTable, ApiPackTable, false ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return 1; } // =-=-=-=-=-=-=- // load client side pluggable api entries irods::api_entry_table& RcApiTable = irods::get_client_api_table(); ret = irods::init_api_table( RcApiTable, ApiPackTable, true ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return 1; } #if RODS_CAT if ( strstr( rsComm.myEnv.rodsDebug, "CAT" ) != NULL ) { chlDebug( rsComm.myEnv.rodsDebug ); } #endif status = initAgent( RULE_ENGINE_TRY_CACHE, &rsComm ); if ( status < 0 ) { rodsLog( LOG_ERROR, "agentMain :: initAgent failed: %d", status ); sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 ); cleanupAndExit( status ); } /* move configConnectControl behind initAgent for now. need zoneName if * the user does not specify one in the input */ initConnectControl(); if ( rsComm.clientUser.userName[0] != '\0' ) { status = chkAllowedUser( rsComm.clientUser.userName, rsComm.clientUser.rodsZone ); if ( status < 0 ) { sendVersion( net_obj, status, 0, NULL, 0 ); cleanupAndExit( status ); } } // =-=-=-=-=-=-=- // handle negotiations with the client regarding TLS if requested // this scope block makes valgrind happy { std::string neg_results; ret = irods::client_server_negotiation_for_server( net_obj, neg_results ); if ( !ret.ok() || neg_results == irods::CS_NEG_FAILURE ) { irods::log( PASS( ret ) ); // =-=-=-=-=-=-=- // send a 'we failed to negotiate' message here?? // or use the error stack rule engine thingie irods::log( PASS( ret ) ); sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 ); cleanupAndExit( ret.code() ); } else { // =-=-=-=-=-=-=- // copy negotiation results to comm for action by network objects snprintf( rsComm.negotiation_results, sizeof( rsComm.negotiation_results ), "%s", neg_results.c_str() ); //rsComm.ssl_do_accept = 1; } } /* send the server version and atatus as part of the protocol. Put * rsComm.reconnPort as the status */ ret = sendVersion( net_obj, status, rsComm.reconnPort, rsComm.reconnAddr, rsComm.cookie ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 ); cleanupAndExit( status ); } logAgentProc( &rsComm ); // call initialization for network plugin as negotiated irods::network_object_ptr new_net_obj; ret = irods::network_factory( &rsComm, new_net_obj ); if ( !ret.ok() ) { return ret.code(); } ret = sockAgentStart( new_net_obj ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return ret.code(); } new_net_obj->to_server( &rsComm ); status = agentMain( &rsComm ); // call initialization for network plugin as negotiated ret = sockAgentStop( new_net_obj ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return ret.code(); } new_net_obj->to_server( &rsComm ); cleanup(); free( rsComm.thread_ctx ); free( rsComm.auth_scheme ); rodsLog( LOG_NOTICE, "Agent exiting with status = %d", status ); return status; }