/* #define SERVER_DEBUG 1 */ int main(int argc, char *argv[]) { int status; rsComm_t rsComm; char *tmpStr; ProcessType = AGENT_PT; #ifdef RUN_SERVER_AS_ROOT #ifndef windows_platform if (initServiceUser() < 0) { exit (1); } #endif #endif #ifdef windows_platform iRODSNtAgentInit(argc, argv); #endif #ifndef windows_platform signal(SIGINT, signalExit); signal(SIGHUP, signalExit); signal(SIGTERM, signalExit); /* set to SIG_DFL as recommended by andy.salnikov so that system() * call returns real values instead of 1 */ signal(SIGCHLD, SIG_DFL); signal(SIGUSR1, signalExit); signal(SIGPIPE, rsPipSigalHandler); #endif #ifndef windows_platform #ifdef SERVER_DEBUG if (isPath ("/tmp/rodsdebug")) sleep (20); #endif #endif #ifdef SYS_TIMING rodsLogLevel(LOG_NOTICE); printSysTiming ("irodsAgent", "exec", 1); #endif memset (&rsComm, 0, sizeof (rsComm)); status = initRsCommWithStartupPack (&rsComm, NULL); if (status < 0) { sendVersion (rsComm.sock, status, 0, NULL, 0); cleanupAndExit (status); } /* Handle option to log sql commands */ tmpStr = getenv (SP_LOG_SQL); if (tmpStr != NULL) { #ifdef IRODS_SYSLOG int j = atoi(tmpStr); rodsLogSqlReq(j); #else rodsLogSqlReq(1); #endif } /* Set the logging level */ tmpStr = getenv (SP_LOG_LEVEL); if (tmpStr != NULL) { int i; i = atoi(tmpStr); rodsLogLevel(i); } else { rodsLogLevel(LOG_NOTICE); /* default */ } #ifdef IRODS_SYSLOG /* Open a connection to syslog */ #ifdef SYSLOG_FACILITY_CODE openlog("rodsAgent",LOG_ODELAY|LOG_PID,SYSLOG_FACILITY_CODE); #else openlog("rodsAgent",LOG_ODELAY|LOG_PID,LOG_DAEMON); #endif #endif status = getRodsEnv (&rsComm.myEnv); if (status < 0) { sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0); cleanupAndExit (status); } #if RODS_CAT if (strstr(rsComm.myEnv.rodsDebug, "CAT") != NULL) { chlDebug(rsComm.myEnv.rodsDebug); } #endif #ifdef RULE_ENGINE_N status = initAgent (RULE_ENGINE_TRY_CACHE, &rsComm); #else status = initAgent (&rsComm); #endif #ifdef SYS_TIMING printSysTiming ("irodsAgent", "initAgent", 0); #endif if (status < 0) { sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0); cleanupAndExit (status); } /* move configConnectControl behind initAgent for now. need zoneName if * the user does not specify one in the input */ initConnectControl (); if (rsComm.clientUser.userName[0] != '\0') { status = chkAllowedUser (rsComm.clientUser.userName, rsComm.clientUser.rodsZone); if (status < 0) { sendVersion (rsComm.sock, status, 0, NULL, 0); cleanupAndExit (status); } } /* send the server version and atatus as part of the protocol. Put * rsComm.reconnPort as the status */ status = sendVersion (rsComm.sock, status, rsComm.reconnPort, rsComm.reconnAddr, rsComm.cookie); if (status < 0) { sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0); cleanupAndExit (status); } #ifdef SYS_TIMING printSysTiming ("irodsAgent", "sendVersion", 0); #endif logAgentProc (&rsComm); status = agentMain (&rsComm); cleanupAndExit (status); return (status); }
int main(int argc, char **argv) { int status; int c; rsComm_t rsComm; int runMode = IRODS_SERVER; int flagval = 0; char *logDir = NULL; char *tmpStr; int logFd; char *ruleExecId = NULL; int jobType = 0; ProcessType = RE_SERVER_PT; #ifdef RUN_SERVER_AS_ROOT #ifndef windows_platform if (initServiceUser() < 0) { exit (1); } #endif #endif #ifndef _WIN32 signal(SIGINT, signalExit); signal(SIGHUP, signalExit); signal(SIGTERM, signalExit); signal(SIGUSR1, signalExit); signal(SIGPIPE, rsPipSigalHandler); /* XXXXX switched to SIG_DFL for embedded python. child process * went away. But probably have to call waitpid. * signal(SIGCHLD, SIG_IGN); */ signal(SIGCHLD, SIG_DFL); #endif /* Handle option to log sql commands */ tmpStr = getenv (SP_LOG_SQL); if (tmpStr != NULL) { #ifdef IRODS_SYSLOG int j = atoi(tmpStr); rodsLogSqlReq(j); #else rodsLogSqlReq(1); #endif } /* Set the logging level */ tmpStr = getenv (SP_LOG_LEVEL); if (tmpStr != NULL) { int i; i = atoi(tmpStr); rodsLogLevel(i); } else { rodsLogLevel(LOG_NOTICE); /* default */ } #ifdef IRODS_SYSLOG /* Open a connection to syslog */ openlog("rodsReServer",LOG_ODELAY|LOG_PID,LOG_DAEMON); #endif while ((c=getopt(argc, argv,"sSvD:j:t:")) != EOF) { switch (c) { case 's': runMode = SINGLE_PASS; break; case 'S': runMode = STANDALONE_SERVER; break; case 'v': /* verbose */ flagval |= v_FLAG; break; case 'D': /* user specified a log directory */ logDir = strdup (optarg); break; case 'j': runMode = SINGLE_PASS; ruleExecId = strdup (optarg); break; case 't': jobType = atoi (optarg); break; default: usage (argv[0]); exit (1); } } status = initRsComm (&rsComm); if (status < 0) { cleanupAndExit (status); } if ((logFd = logFileOpen (runMode, logDir, RULE_EXEC_LOGFILE)) < 0) { exit (1); } daemonize (runMode, logFd); #ifdef RULE_ENGINE_N status = initAgent (RULE_ENGINE_INIT_CACHE, &rsComm); #else status = initAgent (&rsComm); #endif if (status < 0) { cleanupAndExit (status); } if (ruleExecId != NULL) { status = reServerSingleExec (&rsComm, ruleExecId, jobType); if (status >= 0) { exit (0); } else { exit (1); } } else { reServerMain (&rsComm); } cleanupAndExit (status); exit (0); }