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 status = agentMain (&rsComm);
00163
00164 cleanupAndExit (status);
00165
00166 return (status);
00167 }
00168
00169 int
00170 agentMain (rsComm_t *rsComm)
00171 {
00172 int status = 0;
00173
00174
00175
00176
00177 eirods::dynamic_cast_hack();
00178
00179 while (1) {
00180
00181 if (rsComm->gsiRequest==1) {
00182 status = igsiServersideAuth(rsComm) ;
00183 rsComm->gsiRequest=0;
00184 }
00185 if (rsComm->gsiRequest==2) {
00186 status = ikrbServersideAuth(rsComm) ;
00187 rsComm->gsiRequest=0;
00188 }
00189
00190 status = readAndProcClientMsg (rsComm, READ_HEADER_TIMEOUT);
00191
00192 if (status >= 0) {
00193 continue;
00194 } else {
00195 if (status == DISCONN_STATUS) {
00196 status = 0;
00197 break;
00198 } else {
00199 break;
00200 }
00201 }
00202 }
00203
00204
00205
00206
00207 if( !resc_mgr.need_maintenance_operations() ) {
00208 return status;
00209 }
00210
00211
00212
00213 rodsServerHost_t *rodsServerHost = 0;
00214 status = getRcatHost( MASTER_RCAT, 0, &rodsServerHost );
00215 if( status < 0 ) {
00216 eirods::log( ERROR( -1, "agentMain - getRcatHost failed." ) );
00217 return status;
00218 }
00219
00220
00221
00222 status = svrToSvrConnect ( rsComm, rodsServerHost );
00223 if( status < 0 ) {
00224 eirods::log( ERROR( -1, "agentMain - svrToSvrConnect failed." ) );
00225 return status;
00226 }
00227
00228
00229
00230 status = resc_mgr.call_maintenance_operations( rodsServerHost->conn );
00231
00232 return (status);
00233 }
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262