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 sendVersion ( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0);
00123 unregister_handlers();
00124 cleanupAndExit (status);
00125 }
00126
00127 #if RODS_CAT
00128 if (strstr(rsComm.myEnv.rodsDebug, "CAT") != NULL) {
00129 chlDebug(rsComm.myEnv.rodsDebug);
00130 }
00131 #endif
00132
00133 status = initAgent (RULE_ENGINE_TRY_CACHE, &rsComm);
00134
00135 #ifdef SYS_TIMING
00136 printSysTiming ("irodsAgent", "initAgent", 0);
00137 #endif
00138
00139 if (status < 0) {
00140 sendVersion ( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0);
00141 unregister_handlers();
00142 cleanupAndExit (status);
00143 }
00144
00145
00146
00147 initConnectControl ();
00148
00149 if (rsComm.clientUser.userName[0] != '\0') {
00150 status = chkAllowedUser (rsComm.clientUser.userName,
00151 rsComm.clientUser.rodsZone);
00152
00153 if (status < 0) {
00154 sendVersion ( net_obj, status, 0, NULL, 0);
00155 unregister_handlers();
00156 cleanupAndExit (status);
00157 }
00158 }
00159
00160
00161
00162 std::string neg_results;
00163 ret = eirods::client_server_negotiation_for_server( net_obj, neg_results );
00164 if( !ret.ok() || neg_results == eirods::CS_NEG_FAILURE ) {
00165 eirods::log( PASS( ret ) );
00166
00167
00168
00169 sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
00170 unregister_handlers();
00171 cleanupAndExit( ret.code() );
00172
00173 } else {
00174
00175
00176 strncpy( rsComm.negotiation_results, neg_results.c_str(), MAX_NAME_LEN );
00177
00178
00179 }
00180
00181
00182
00183 ret = sendVersion( net_obj, status, rsComm.reconnPort,
00184 rsComm.reconnAddr, rsComm.cookie);
00185
00186 if( !ret.ok() ) {
00187 sendVersion (net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0);
00188 unregister_handlers();
00189 cleanupAndExit (status);
00190 }
00191
00192 #ifdef SYS_TIMING
00193 printSysTiming ("irodsAgent", "sendVersion", 0);
00194 #endif
00195
00196 logAgentProc (&rsComm);
00197
00198 bool done = true;
00199 while(!done) {
00200 sleep(1);
00201 }
00202 #if 1
00203
00204
00205 eirods::network_object_ptr new_net_obj;
00206 ret = eirods::network_factory( &rsComm, new_net_obj );
00207 if( !ret.ok() ) {
00208 return ret.code();
00209 }
00210
00211 ret = sockAgentStart( new_net_obj );
00212 if( !ret.ok() ) {
00213 eirods::log( PASS( ret ) );
00214 return ret.code();
00215 }
00216
00217 new_net_obj->to_server( &rsComm );
00218 #endif
00219 status = agentMain( &rsComm );
00220
00221 #if 1
00222
00223
00224 ret = sockAgentStop( new_net_obj );
00225 if( !ret.ok() ) {
00226 eirods::log( PASS( ret ) );
00227 return ret.code();
00228 }
00229
00230 new_net_obj->to_server( &rsComm );
00231 #endif
00232 unregister_handlers();
00233 cleanupAndExit (status);
00234
00235 return (status);
00236 }
00237
00238 int
00239 agentMain (rsComm_t *rsComm)
00240 {
00241 int status = 0;
00242
00243
00244
00245
00246 eirods::dynamic_cast_hack();
00247
00248 while (1) {
00249
00250 if (rsComm->gsiRequest==1) {
00251 status = igsiServersideAuth(rsComm) ;
00252 rsComm->gsiRequest=0;
00253 }
00254 if (rsComm->gsiRequest==2) {
00255 status = ikrbServersideAuth(rsComm) ;
00256 rsComm->gsiRequest=0;
00257 }
00258
00259 if (rsComm->ssl_do_accept) {
00260 status = sslAccept(rsComm);
00261 rsComm->ssl_do_accept = 0;
00262 }
00263 if (rsComm->ssl_do_shutdown) {
00264 status = sslShutdown(rsComm);
00265 rsComm->ssl_do_shutdown = 0;
00266 }
00267
00268 status = readAndProcClientMsg (rsComm, READ_HEADER_TIMEOUT);
00269
00270 if (status >= 0) {
00271 continue;
00272 } else {
00273 if (status == DISCONN_STATUS) {
00274 status = 0;
00275 break;
00276 } else {
00277 break;
00278 }
00279 }
00280 }
00281
00282
00283
00284
00285 if( !resc_mgr.need_maintenance_operations() ) {
00286 return status;
00287 }
00288
00289
00290
00291 rodsServerHost_t *rodsServerHost = 0;
00292 status = getRcatHost( MASTER_RCAT, 0, &rodsServerHost );
00293 if( status < 0 ) {
00294 eirods::log( ERROR( status, "getRcatHost failed." ) );
00295 return status;
00296 }
00297
00298
00299
00300 status = svrToSvrConnect ( rsComm, rodsServerHost );
00301 if( status < 0 ) {
00302 eirods::log( ERROR( status, "svrToSvrConnect failed." ) );
00303 return status;
00304 }
00305
00306
00307
00308 status = resc_mgr.call_maintenance_operations( rodsServerHost->conn );
00309
00310 return (status);
00311 }
00312
00313
00314
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