00001
00002
00003
00004
00005
00006
00007 #include <syslog.h>
00008 #include "rodsAgent.h"
00009 #include "reconstants.h"
00010 #include "rsApiHandler.h"
00011 #include "icatHighLevelRoutines.h"
00012 #include "miscServerFunct.h"
00013 #ifdef windows_platform
00014 #include "rsLog.h"
00015 static void NtAgentSetEnvsFromArgs(int ac, char **av);
00016 #endif
00017
00018
00019 int
00020 main(int argc, char *argv[])
00021 {
00022 int status;
00023 rsComm_t rsComm;
00024 char *tmpStr;
00025
00026 ProcessType = AGENT_PT;
00027
00028 #ifdef RUN_SERVER_AS_ROOT
00029 #ifndef windows_platform
00030 if (initServiceUser() < 0) {
00031 exit (1);
00032 }
00033 #endif
00034 #endif
00035
00036 #ifdef windows_platform
00037 iRODSNtAgentInit(argc, argv);
00038 #endif
00039
00040 #ifndef windows_platform
00041 signal(SIGINT, signalExit);
00042 signal(SIGHUP, signalExit);
00043 signal(SIGTERM, signalExit);
00044
00045
00046 signal(SIGCHLD, SIG_DFL);
00047 signal(SIGUSR1, signalExit);
00048 signal(SIGPIPE, rsPipSigalHandler);
00049 #endif
00050
00051 #ifndef windows_platform
00052 #ifdef SERVER_DEBUG
00053 if (isPath ("/tmp/rodsdebug"))
00054 sleep (20);
00055 #endif
00056 #endif
00057
00058 #ifdef SYS_TIMING
00059 rodsLogLevel(LOG_NOTICE);
00060 printSysTiming ("irodsAgent", "exec", 1);
00061 #endif
00062
00063 memset (&rsComm, 0, sizeof (rsComm));
00064
00065 status = initRsCommWithStartupPack (&rsComm, NULL);
00066
00067 if (status < 0) {
00068 sendVersion (rsComm.sock, status, 0, NULL, 0);
00069 cleanupAndExit (status);
00070 }
00071
00072
00073 tmpStr = getenv (SP_LOG_SQL);
00074 if (tmpStr != NULL) {
00075 #ifdef IRODS_SYSLOG
00076 int j = atoi(tmpStr);
00077 rodsLogSqlReq(j);
00078 #else
00079 rodsLogSqlReq(1);
00080 #endif
00081 }
00082
00083
00084 tmpStr = getenv (SP_LOG_LEVEL);
00085 if (tmpStr != NULL) {
00086 int i;
00087 i = atoi(tmpStr);
00088 rodsLogLevel(i);
00089 } else {
00090 rodsLogLevel(LOG_NOTICE);
00091 }
00092
00093 #ifdef IRODS_SYSLOG
00094
00095 openlog("rodsAgent",LOG_ODELAY|LOG_PID,LOG_DAEMON);
00096 #endif
00097
00098 status = getRodsEnv (&rsComm.myEnv);
00099
00100 if (status < 0) {
00101 sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0);
00102 cleanupAndExit (status);
00103 }
00104
00105 #if RODS_CAT
00106 if (strstr(rsComm.myEnv.rodsDebug, "CAT") != NULL) {
00107 chlDebug(rsComm.myEnv.rodsDebug);
00108 }
00109 #endif
00110
00111 #ifdef RULE_ENGINE_N
00112 status = initAgent (RULE_ENGINE_TRY_CACHE, &rsComm);
00113 #else
00114 status = initAgent (&rsComm);
00115 #endif
00116 #ifdef SYS_TIMING
00117 printSysTiming ("irodsAgent", "initAgent", 0);
00118 #endif
00119
00120 if (status < 0) {
00121 sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0);
00122 cleanupAndExit (status);
00123 }
00124
00125
00126
00127 initConnectControl ();
00128
00129 if (rsComm.clientUser.userName[0] != '\0') {
00130 status = chkAllowedUser (rsComm.clientUser.userName,
00131 rsComm.clientUser.rodsZone);
00132
00133 if (status < 0) {
00134 sendVersion (rsComm.sock, status, 0, NULL, 0);
00135 cleanupAndExit (status);
00136 }
00137 }
00138
00139
00140
00141
00142 status = sendVersion (rsComm.sock, status, rsComm.reconnPort,
00143 rsComm.reconnAddr, rsComm.cookie);
00144
00145 if (status < 0) {
00146 sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0);
00147 cleanupAndExit (status);
00148 }
00149 #ifdef SYS_TIMING
00150 printSysTiming ("irodsAgent", "sendVersion", 0);
00151 #endif
00152
00153 logAgentProc (&rsComm);
00154
00155 status = agentMain (&rsComm);
00156
00157 cleanupAndExit (status);
00158
00159 return (status);
00160 }
00161
00162 int
00163 agentMain (rsComm_t *rsComm)
00164 {
00165 int status = 0;
00166 int retryCnt = 0;
00167
00168 while (1) {
00169
00170 if (rsComm->gsiRequest==1) {
00171 status = igsiServersideAuth(rsComm) ;
00172 rsComm->gsiRequest=0;
00173 }
00174 if (rsComm->gsiRequest==2) {
00175 status = ikrbServersideAuth(rsComm) ;
00176 rsComm->gsiRequest=0;
00177 }
00178
00179 status = readAndProcClientMsg (rsComm, READ_HEADER_TIMEOUT);
00180 #if 0
00181 status = readAndProcClientMsg (rsComm, 0);
00182 #endif
00183
00184 if (status >= 0) {
00185 retryCnt = 0;
00186 continue;
00187 } else {
00188 if (status == DISCONN_STATUS) {
00189 status = 0;
00190 break;
00191 } else {
00192 break;
00193 }
00194 }
00195 }
00196 return (status);
00197 }
00198