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 unregister_handlers();
00080 cleanupAndExit (status);
00081 }
00082
00083
00084 tmpStr = getenv (SP_LOG_SQL);
00085 if (tmpStr != NULL) {
00086 #ifdef IRODS_SYSLOG
00087 int j = atoi(tmpStr);
00088 rodsLogSqlReq(j);
00089 #else
00090 rodsLogSqlReq(1);
00091 #endif
00092 }
00093
00094
00095 tmpStr = getenv (SP_LOG_LEVEL);
00096 if (tmpStr != NULL) {
00097 int i;
00098 i = atoi(tmpStr);
00099 rodsLogLevel(i);
00100 } else {
00101 rodsLogLevel(LOG_NOTICE);
00102 }
00103
00104 #ifdef IRODS_SYSLOG
00105
00106 openlog("rodsAgent",LOG_ODELAY|LOG_PID,LOG_DAEMON);
00107 #endif
00108
00109 status = getRodsEnv (&rsComm.myEnv);
00110
00111 if (status < 0) {
00112 sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0);
00113 unregister_handlers();
00114 cleanupAndExit (status);
00115 }
00116
00117 #if RODS_CAT
00118 if (strstr(rsComm.myEnv.rodsDebug, "CAT") != NULL) {
00119 chlDebug(rsComm.myEnv.rodsDebug);
00120 }
00121 #endif
00122
00123 status = initAgent (RULE_ENGINE_TRY_CACHE, &rsComm);
00124
00125 #ifdef SYS_TIMING
00126 printSysTiming ("irodsAgent", "initAgent", 0);
00127 #endif
00128
00129 if (status < 0) {
00130 sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0);
00131 unregister_handlers();
00132 cleanupAndExit (status);
00133 }
00134
00135
00136
00137 initConnectControl ();
00138
00139 if (rsComm.clientUser.userName[0] != '\0') {
00140 status = chkAllowedUser (rsComm.clientUser.userName,
00141 rsComm.clientUser.rodsZone);
00142
00143 if (status < 0) {
00144 sendVersion (rsComm.sock, status, 0, NULL, 0);
00145 unregister_handlers();
00146 cleanupAndExit (status);
00147 }
00148 }
00149
00150
00151
00152
00153 status = sendVersion (rsComm.sock, status, rsComm.reconnPort,
00154 rsComm.reconnAddr, rsComm.cookie);
00155
00156 if (status < 0) {
00157 sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0);
00158 unregister_handlers();
00159 cleanupAndExit (status);
00160 }
00161 #ifdef SYS_TIMING
00162 printSysTiming ("irodsAgent", "sendVersion", 0);
00163 #endif
00164
00165 logAgentProc (&rsComm);
00166
00167 bool done = true;
00168 while(!done) {
00169 sleep(1);
00170 }
00171
00172 status = agentMain (&rsComm);
00173
00174
00175 unregister_handlers();
00176 cleanupAndExit (status);
00177
00178 return (status);
00179 }
00180
00181 int
00182 agentMain (rsComm_t *rsComm)
00183 {
00184 int status = 0;
00185
00186
00187
00188
00189 eirods::dynamic_cast_hack();
00190
00191 while (1) {
00192
00193 if (rsComm->gsiRequest==1) {
00194 status = igsiServersideAuth(rsComm) ;
00195 rsComm->gsiRequest=0;
00196 }
00197 if (rsComm->gsiRequest==2) {
00198 status = ikrbServersideAuth(rsComm) ;
00199 rsComm->gsiRequest=0;
00200 }
00201
00202 #ifdef USE_SSL
00203 if (rsComm->ssl_do_accept) {
00204 status = sslAccept(rsComm);
00205 rsComm->ssl_do_accept = 0;
00206 }
00207 if (rsComm->ssl_do_shutdown) {
00208 status = sslShutdown(rsComm);
00209 rsComm->ssl_do_shutdown = 0;
00210 }
00211 #endif
00212 status = readAndProcClientMsg (rsComm, READ_HEADER_TIMEOUT);
00213
00214 if (status >= 0) {
00215 continue;
00216 } else {
00217 if (status == DISCONN_STATUS) {
00218 status = 0;
00219 break;
00220 } else {
00221 break;
00222 }
00223 }
00224 }
00225
00226
00227
00228
00229 if( !resc_mgr.need_maintenance_operations() ) {
00230 return status;
00231 }
00232
00233
00234
00235 rodsServerHost_t *rodsServerHost = 0;
00236 status = getRcatHost( MASTER_RCAT, 0, &rodsServerHost );
00237 if( status < 0 ) {
00238 eirods::log( ERROR( status, "getRcatHost failed." ) );
00239 return status;
00240 }
00241
00242
00243
00244 status = svrToSvrConnect ( rsComm, rodsServerHost );
00245 if( status < 0 ) {
00246 eirods::log( ERROR( status, "svrToSvrConnect failed." ) );
00247 return status;
00248 }
00249
00250
00251
00252 status = resc_mgr.call_maintenance_operations( rodsServerHost->conn );
00253
00254 return (status);
00255 }
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284