00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <syslog.h>
00010 #include "rodsAgent.h"
00011 #include "reconstants.h"
00012 #include "rsApiHandler.h"
00013 #include "icatHighLevelRoutines.h"
00014 #include "miscServerFunct.h"
00015 #ifdef windows_platform
00016 #include "rsLog.h"
00017 static void NtAgentSetEnvsFromArgs(int ac, char **av);
00018 #endif
00019
00020
00021
00022 #include "eirods_dynamic_cast.h"
00023 #include "eirods_signal.h"
00024 #include "eirods_client_server_negotiation.h"
00025 #include "eirods_network_factory.h"
00026
00027
00028 int
00029 main(int argc, char *argv[])
00030 {
00031 int status;
00032 rsComm_t rsComm;
00033 char *tmpStr;
00034
00035 ProcessType = AGENT_PT;
00036
00037 #ifdef RUN_SERVER_AS_ROOT
00038 #ifndef windows_platform
00039 if (initServiceUser() < 0) {
00040 exit (1);
00041 }
00042 #endif
00043 #endif
00044
00045 #ifdef windows_platform
00046 iRODSNtAgentInit(argc, argv);
00047 #endif
00048
00049 #ifndef windows_platform
00050 signal(SIGINT, signalExit);
00051 signal(SIGHUP, signalExit);
00052 signal(SIGTERM, signalExit);
00053
00054
00055 signal(SIGCHLD, SIG_DFL);
00056 signal(SIGUSR1, signalExit);
00057 signal(SIGPIPE, rsPipSigalHandler);
00058
00059
00060 register_handlers();
00061 #endif
00062
00063 #ifndef windows_platform
00064 #ifdef SERVER_DEBUG
00065 if (isPath ("/tmp/rodsdebug"))
00066 sleep (20);
00067 #endif
00068 #endif
00069
00070 #ifdef SYS_TIMING
00071 rodsLogLevel(LOG_NOTICE);
00072 printSysTiming ("irodsAgent", "exec", 1);
00073 #endif
00074
00075 memset (&rsComm, 0, sizeof (rsComm));
00076
00077 status = initRsCommWithStartupPack (&rsComm, NULL);
00078
00079
00080
00081 eirods::network_object_ptr net_obj;
00082 eirods::error ret = eirods::network_factory( &rsComm, net_obj );
00083 if( !ret.ok() ) {
00084 eirods::log( PASS( ret ) );
00085 }
00086
00087 if (status < 0) {
00088 sendVersion ( net_obj, status, 0, NULL, 0);
00089 unregister_handlers();
00090 cleanupAndExit (status);
00091 }
00092
00093
00094 tmpStr = getenv (SP_LOG_SQL);
00095 if (tmpStr != NULL) {
00096 #ifdef IRODS_SYSLOG
00097 int j = atoi(tmpStr);
00098 rodsLogSqlReq(j);
00099 #else
00100 rodsLogSqlReq(1);
00101 #endif
00102 }
00103
00104
00105 tmpStr = getenv (SP_LOG_LEVEL);
00106 if (tmpStr != NULL) {
00107 int i;
00108 i = atoi(tmpStr);
00109 rodsLogLevel(i);
00110 } else {
00111 rodsLogLevel(LOG_NOTICE);
00112 }
00113
00114 #ifdef IRODS_SYSLOG
00115
00116 openlog("rodsAgent",LOG_ODELAY|LOG_PID,LOG_DAEMON);
00117 #endif
00118
00119 status = getRodsEnv (&rsComm.myEnv);
00120
00121 if (status < 0) {
00122 rodsLog( LOG_ERROR, "agentMain :: getRodsEnv failed" );
00123 sendVersion ( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0);
00124 unregister_handlers();
00125 cleanupAndExit (status);
00126 }
00127
00128 #if RODS_CAT
00129 if (strstr(rsComm.myEnv.rodsDebug, "CAT") != NULL) {
00130 chlDebug(rsComm.myEnv.rodsDebug);
00131 }
00132 #endif
00133
00134 status = initAgent (RULE_ENGINE_TRY_CACHE, &rsComm);
00135
00136 #ifdef SYS_TIMING
00137 printSysTiming ("irodsAgent", "initAgent", 0);
00138 #endif
00139
00140 if (status < 0) {
00141 rodsLog( LOG_ERROR, "agentMain :: initAgent failed: %d", status );
00142 sendVersion ( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0);
00143 unregister_handlers();
00144 cleanupAndExit (status);
00145 }
00146
00147
00148
00149 initConnectControl ();
00150
00151 if (rsComm.clientUser.userName[0] != '\0') {
00152 status = chkAllowedUser (rsComm.clientUser.userName,
00153 rsComm.clientUser.rodsZone);
00154
00155 if (status < 0) {
00156 sendVersion ( net_obj, status, 0, NULL, 0);
00157 unregister_handlers();
00158 cleanupAndExit (status);
00159 }
00160 }
00161
00162
00163
00164 std::string neg_results;
00165 ret = eirods::client_server_negotiation_for_server( net_obj, neg_results );
00166 if( !ret.ok() || neg_results == eirods::CS_NEG_FAILURE ) {
00167 eirods::log( PASS( ret ) );
00168
00169
00170
00171 eirods::log( PASS( ret ) );
00172 sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
00173 unregister_handlers();
00174 cleanupAndExit( ret.code() );
00175
00176 } else {
00177
00178
00179 strncpy( rsComm.negotiation_results, neg_results.c_str(), MAX_NAME_LEN );
00180
00181
00182 }
00183
00184
00185
00186 ret = sendVersion( net_obj, status, rsComm.reconnPort,
00187 rsComm.reconnAddr, rsComm.cookie);
00188
00189 if( !ret.ok() ) {
00190 eirods::log( PASS( ret ) );
00191 sendVersion (net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0);
00192 unregister_handlers();
00193 cleanupAndExit (status);
00194 }
00195
00196 #ifdef SYS_TIMING
00197 printSysTiming ("irodsAgent", "sendVersion", 0);
00198 #endif
00199
00200 logAgentProc (&rsComm);
00201
00202 bool done = true;
00203 while(!done) {
00204 sleep(1);
00205 }
00206 #if 1
00207
00208
00209 eirods::network_object_ptr new_net_obj;
00210 ret = eirods::network_factory( &rsComm, new_net_obj );
00211 if( !ret.ok() ) {
00212 return ret.code();
00213 }
00214
00215 ret = sockAgentStart( new_net_obj );
00216 if( !ret.ok() ) {
00217 eirods::log( PASS( ret ) );
00218 return ret.code();
00219 }
00220
00221 new_net_obj->to_server( &rsComm );
00222 #endif
00223 status = agentMain( &rsComm );
00224
00225 #if 1
00226
00227
00228 ret = sockAgentStop( new_net_obj );
00229 if( !ret.ok() ) {
00230 eirods::log( PASS( ret ) );
00231 return ret.code();
00232 }
00233
00234 new_net_obj->to_server( &rsComm );
00235 #endif
00236 unregister_handlers();
00237 cleanupAndExit (status);
00238
00239 return (status);
00240 }
00241
00242 int
00243 agentMain (rsComm_t *rsComm)
00244 {
00245 int status = 0;
00246
00247
00248
00249
00250 eirods::dynamic_cast_hack();
00251
00252 while (1) {
00253
00254 if (rsComm->gsiRequest==1) {
00255 status = igsiServersideAuth(rsComm) ;
00256 rsComm->gsiRequest=0;
00257 }
00258 if (rsComm->gsiRequest==2) {
00259 status = ikrbServersideAuth(rsComm) ;
00260 rsComm->gsiRequest=0;
00261 }
00262
00263 if (rsComm->ssl_do_accept) {
00264 status = sslAccept(rsComm);
00265 rsComm->ssl_do_accept = 0;
00266 }
00267 if (rsComm->ssl_do_shutdown) {
00268 status = sslShutdown(rsComm);
00269 rsComm->ssl_do_shutdown = 0;
00270 }
00271
00272 status = readAndProcClientMsg (rsComm, READ_HEADER_TIMEOUT);
00273
00274 if (status >= 0) {
00275 continue;
00276 } else {
00277 if (status == DISCONN_STATUS) {
00278 status = 0;
00279 break;
00280 } else {
00281 break;
00282 }
00283 }
00284 }
00285
00286
00287
00288
00289 if( !resc_mgr.need_maintenance_operations() ) {
00290 return status;
00291 }
00292
00293
00294
00295 rodsServerHost_t *rodsServerHost = 0;
00296 status = getRcatHost( MASTER_RCAT, 0, &rodsServerHost );
00297 if( status < 0 ) {
00298 eirods::log( ERROR( status, "getRcatHost failed." ) );
00299 return status;
00300 }
00301
00302
00303
00304 status = svrToSvrConnect ( rsComm, rodsServerHost );
00305 if( status < 0 ) {
00306 eirods::log( ERROR( status, "svrToSvrConnect failed." ) );
00307 return status;
00308 }
00309
00310
00311
00312 status = resc_mgr.call_maintenance_operations( rodsServerHost->conn );
00313
00314 return (status);
00315 }
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344