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
00025
00026 int
00027 main(int argc, char *argv[])
00028 {
00029 int status;
00030 rsComm_t rsComm;
00031 char *tmpStr;
00032
00033 ProcessType = AGENT_PT;
00034
00035 #ifdef RUN_SERVER_AS_ROOT
00036 #ifndef windows_platform
00037 if (initServiceUser() < 0) {
00038 exit (1);
00039 }
00040 #endif
00041 #endif
00042
00043 #ifdef windows_platform
00044 iRODSNtAgentInit(argc, argv);
00045 #endif
00046
00047 #ifndef windows_platform
00048 signal(SIGINT, signalExit);
00049 signal(SIGHUP, signalExit);
00050 signal(SIGTERM, signalExit);
00051
00052
00053 signal(SIGCHLD, SIG_DFL);
00054 signal(SIGUSR1, signalExit);
00055 signal(SIGPIPE, rsPipSigalHandler);
00056
00057
00058 register_handlers();
00059 #endif
00060
00061 #ifndef windows_platform
00062 #ifdef SERVER_DEBUG
00063 if (isPath ("/tmp/rodsdebug"))
00064 sleep (20);
00065 #endif
00066 #endif
00067
00068 #ifdef SYS_TIMING
00069 rodsLogLevel(LOG_NOTICE);
00070 printSysTiming ("irodsAgent", "exec", 1);
00071 #endif
00072
00073 memset (&rsComm, 0, sizeof (rsComm));
00074
00075 status = initRsCommWithStartupPack (&rsComm, NULL);
00076
00077 if (status < 0) {
00078 sendVersion (rsComm.sock, status, 0, NULL, 0);
00079 cleanupAndExit (status);
00080 }
00081
00082
00083 tmpStr = getenv (SP_LOG_SQL);
00084 if (tmpStr != NULL) {
00085 #ifdef IRODS_SYSLOG
00086 int j = atoi(tmpStr);
00087 rodsLogSqlReq(j);
00088 #else
00089 rodsLogSqlReq(1);
00090 #endif
00091 }
00092
00093
00094 tmpStr = getenv (SP_LOG_LEVEL);
00095 if (tmpStr != NULL) {
00096 int i;
00097 i = atoi(tmpStr);
00098 rodsLogLevel(i);
00099 } else {
00100 rodsLogLevel(LOG_NOTICE);
00101 }
00102
00103 #ifdef IRODS_SYSLOG
00104
00105 openlog("rodsAgent",LOG_ODELAY|LOG_PID,LOG_DAEMON);
00106 #endif
00107
00108 status = getRodsEnv (&rsComm.myEnv);
00109
00110 if (status < 0) {
00111 sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0);
00112 cleanupAndExit (status);
00113 }
00114
00115 #if RODS_CAT
00116 if (strstr(rsComm.myEnv.rodsDebug, "CAT") != NULL) {
00117 chlDebug(rsComm.myEnv.rodsDebug);
00118 }
00119 #endif
00120
00121 status = initAgent (RULE_ENGINE_TRY_CACHE, &rsComm);
00122
00123 #ifdef SYS_TIMING
00124 printSysTiming ("irodsAgent", "initAgent", 0);
00125 #endif
00126
00127 if (status < 0) {
00128 sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0);
00129 cleanupAndExit (status);
00130 }
00131
00132
00133
00134 initConnectControl ();
00135
00136 if (rsComm.clientUser.userName[0] != '\0') {
00137 status = chkAllowedUser (rsComm.clientUser.userName,
00138 rsComm.clientUser.rodsZone);
00139
00140 if (status < 0) {
00141 sendVersion (rsComm.sock, status, 0, NULL, 0);
00142 cleanupAndExit (status);
00143 }
00144 }
00145
00146
00147
00148
00149 status = sendVersion (rsComm.sock, status, rsComm.reconnPort,
00150 rsComm.reconnAddr, rsComm.cookie);
00151
00152 if (status < 0) {
00153 sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0);
00154 cleanupAndExit (status);
00155 }
00156 #ifdef SYS_TIMING
00157 printSysTiming ("irodsAgent", "sendVersion", 0);
00158 #endif
00159
00160 logAgentProc (&rsComm);
00161
00162 bool done = true;
00163 while(!done) {
00164 sleep(1);
00165 }
00166
00167 status = agentMain (&rsComm);
00168
00169 cleanupAndExit (status);
00170
00171 return (status);
00172 }
00173
00174 int
00175 agentMain (rsComm_t *rsComm)
00176 {
00177 int status = 0;
00178
00179
00180
00181
00182 eirods::dynamic_cast_hack();
00183
00184 while (1) {
00185
00186 if (rsComm->gsiRequest==1) {
00187 status = igsiServersideAuth(rsComm) ;
00188 rsComm->gsiRequest=0;
00189 }
00190 if (rsComm->gsiRequest==2) {
00191 status = ikrbServersideAuth(rsComm) ;
00192 rsComm->gsiRequest=0;
00193 }
00194
00195 #ifdef USE_SSL
00196 if (rsComm->ssl_do_accept) {
00197 status = sslAccept(rsComm);
00198 rsComm->ssl_do_accept = 0;
00199 }
00200 if (rsComm->ssl_do_shutdown) {
00201 status = sslShutdown(rsComm);
00202 rsComm->ssl_do_shutdown = 0;
00203 }
00204 #endif
00205 status = readAndProcClientMsg (rsComm, READ_HEADER_TIMEOUT);
00206
00207 if (status >= 0) {
00208 continue;
00209 } else {
00210 if (status == DISCONN_STATUS) {
00211 status = 0;
00212 break;
00213 } else {
00214 break;
00215 }
00216 }
00217 }
00218
00219
00220
00221
00222 if( !resc_mgr.need_maintenance_operations() ) {
00223 return status;
00224 }
00225
00226
00227
00228 rodsServerHost_t *rodsServerHost = 0;
00229 status = getRcatHost( MASTER_RCAT, 0, &rodsServerHost );
00230 if( status < 0 ) {
00231 eirods::log( ERROR( status, "getRcatHost failed." ) );
00232 return status;
00233 }
00234
00235
00236
00237 status = svrToSvrConnect ( rsComm, rodsServerHost );
00238 if( status < 0 ) {
00239 eirods::log( ERROR( status, "svrToSvrConnect failed." ) );
00240 return status;
00241 }
00242
00243
00244
00245 status = resc_mgr.call_maintenance_operations( rodsServerHost->conn );
00246
00247 return (status);
00248 }
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277