irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

irodsXmsgServer.cpp
Go to the documentation of this file.
1 
4 /* irodsXmsgServer.cpp - The irods xmsg server */
5 #include "reconstants.hpp"
6 #include "irodsXmsgServer.hpp"
7 #include "xmsgLib.hpp"
8 #include "irods_exception.hpp"
12 #include "irods_re_plugin.hpp"
13 #include "irods_signal.hpp"
15 #include "initServer.hpp"
16 #include "miscServerFunct.hpp"
17 
18 int loopCnt = -1; /* make it -1 to run infinitely */
19 
20 
21 int
22 main( int argc, char **argv ) {
23  int c;
24  int runMode = SERVER;
25  int flagval = 0;
26  char *logDir = NULL;
27  char *tmpStr;
28  int logFd;
29 
31 
33  if ( !ret.ok() ) {
34  rodsLog( LOG_ERROR, "irodsXmsgServer::main: Failed to set RE cache mutex name\n%s", ret.result().c_str() );
35  exit( 1 );
36  }
37 
39 
40  signal( SIGINT, signalExit );
41  signal( SIGHUP, signalExit );
42  signal( SIGTERM, signalExit );
43  signal( SIGUSR1, signalExit );
44  signal( SIGPIPE, rsPipeSignalHandler );
45 
46  /* Handle option to log sql commands */
47  tmpStr = getenv( SP_LOG_SQL );
48  if ( tmpStr != NULL ) {
49  rodsLogSqlReq( 1 );
50  }
51 
52  /* Set the logging level */
53  tmpStr = getenv( SP_LOG_LEVEL );
54  if ( tmpStr != NULL ) {
55  int i;
56  i = atoi( tmpStr );
57  rodsLogLevel( i );
58  }
59  else {
60  rodsLogLevel( LOG_NOTICE ); /* default */
61  }
62 
63  while ( ( c = getopt( argc, argv, "sSc:vD:" ) ) != EOF ) {
64  switch ( c ) {
65  case 's':
66  runMode = SINGLE_PASS;
67  break;
68  case 'S':
69  runMode = STANDALONE_SERVER;
70  break;
71  case 'v': /* verbose */
72  flagval |= v_FLAG;
73  break;
74  case 'c':
75  loopCnt = atoi( optarg );
76  break;
77  case 'D': /* user specified a log directory */
78  logDir = strdup( optarg );
79  break;
80  default:
81  usage( argv[0] );
82  exit( 1 );
83  }
84  }
85 
86  if ( ( logFd = logFileOpen( runMode, logDir, XMSG_SVR_LOGFILE ) ) < 0 ) {
87  exit( 1 );
88  }
89 
90  daemonize( runMode, logFd );
91 
93  sleep( 5 );
94  exit( 0 );
95 }
96 
97 int usage( char *prog ) {
98  fprintf( stderr, "Usage: %s [-scva] [-D logDir] \n", prog );
99  return 0;
100 }
101 
102 int
104  int status = 0;
105  rsComm_t rsComm;
106  rsComm_t svrComm; /* rsComm is connection to icat, svrComm is the
107  * server's listening socket */
108  fd_set sockMask;
109  int numSock;
110 
111  initThreadEnv();
112  initXmsgHashQue();
113 
115 
116  if ( status < 0 ) {
118  "xmsgServerMain: startXmsgThreads error. status = %d", status );
119  return status;
120  }
121 
122  status = initRsComm( &rsComm );
123 
124  if ( status < 0 ) {
125  rodsLog( LOG_ERROR, "xmsgServerMain: initRsComm error. status = %d",
126  status );
127  return status;
128  }
129 
130  status = initRsComm( &svrComm );
131 
132  if ( status < 0 ) {
133  rodsLog( LOG_ERROR, "xmsgServerMain: initRsComm error. status = %d",
134  status );
135  return status;
136  }
137 
138  status = initAgent( RULE_ENGINE_NO_CACHE, &rsComm );
139 
140  if ( status < 0 ) {
141  rodsLog( LOG_ERROR, "xmsgServerMain: initAgent error. status = %d",
142  status );
143  return status;
144  }
145 
146 
147  // =-=-=-=-=-=-=-
148  // handle negotiations with the client regarding TLS if requested
149  irods::error ret;
150 
151  // =-=-=-=-=-=-=-
152  // manufacture a network object for comms
154  ret = irods::network_factory( &rsComm, net_obj );
155  if ( !ret.ok() ) {
156  irods::log( PASS( ret ) );
157  }
158 
159  std::string neg_results;
160  ret = irods::client_server_negotiation_for_server( net_obj, neg_results );
161  if ( !ret.ok() || neg_results == irods::CS_NEG_FAILURE ) {
162  irods::log( PASS( ret ) );
163  // =-=-=-=-=-=-=-
164  // send a 'we failed to negotiate' message here??
165  // or use the error stack rule engine thingie
166  irods::log( PASS( ret ) );
167  sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
168  cleanupAndExit( ret.code() );
169 
170  }
171  else {
172  // =-=-=-=-=-=-=-
173  // copy negotiation results to comm for action by network objects
174  snprintf( rsComm.negotiation_results, sizeof( rsComm.negotiation_results ),
175  "%s", neg_results.c_str() );
176  //rsComm.ssl_do_accept = 1;
177 
178  }
179 
180  /* open a socket and listen for connection */
181  try {
182  int xmsgPort = irods::get_server_property<const int>(irods::CFG_XMSG_PORT);
183  svrComm.sock = sockOpenForInConn(
184  &svrComm,
185  &xmsgPort,
186  NULL,
187  SOCK_STREAM );
188  } catch ( const irods::exception& e ) {
190  return e.code();
191  }
192 
193  if ( svrComm.sock < 0 ) {
194  rodsLog( LOG_NOTICE, "xmsgServerMain: sockOpenForInConn error. status = %d",
195  svrComm.sock );
196  exit( 1 );
197  }
198 
199  listen( svrComm.sock, MAX_LISTEN_QUE );
200 
201  FD_ZERO( &sockMask );
202 
203  rodsLog( LOG_NOTICE, "xmsgServer version %s is up", RODS_REL_VERSION );
204 
205  while ( 1 ) { /* infinite loop */
206  FD_SET( svrComm.sock, &sockMask );
207  while ( ( numSock = select( svrComm.sock + 1, &sockMask,
208  ( fd_set * ) NULL, ( fd_set * ) NULL, ( struct timeval * ) NULL ) ) < 0 ) {
209 
210  if ( errno == EINTR ) {
211  rodsLog( LOG_NOTICE, "xmsgServerMain: select() interrupted" );
212  FD_SET( svrComm.sock, &sockMask );
213  continue;
214  }
215  else {
216  rodsLog( LOG_NOTICE, "xmsgServerMain: select() error, errno = %d", errno );
217  return -1;
218  }
219  }
220 
221  const int newSock = rsAcceptConn( &svrComm );
222 
223  if ( newSock < 0 ) {
225  "xmsgServerMain: acceptConn () error, errno = %d", errno );
226  continue;
227  }
228 
229  addReqToQue( newSock );
230 
231  if ( loopCnt > 0 ) {
232  loopCnt--;
233  if ( loopCnt == 0 ) {
234  return 0;
235  }
236  }
237 
238  }
239  return 0;
240 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
logFileOpen
int logFileOpen(int runMode, const char *logDir, const char *logFileName)
Definition: initServer.cpp:796
NULL
#define NULL
Definition: rodsDef.h:70
rsComm_t
Definition: rcConnect.h:145
STANDALONE_SERVER
#define STANDALONE_SERVER
Definition: rodsConnect.h:60
sendVersion
irods::error sendVersion(irods::network_object_ptr, int, int, char *, int)
Definition: sockComm.cpp:1168
irods::CS_NEG_FAILURE
const std::string CS_NEG_FAILURE("CS_NEG_FAILURE")
irods_server_properties.hpp
SYS_AGENT_INIT_ERR
@ SYS_AGENT_INIT_ERR
Definition: rodsErrorTable.h:105
optarg
char * optarg
setRECacheSaltFromEnv
irods::error setRECacheSaltFromEnv()
Definition: miscServerFunct.cpp:3021
SERVER
#define SERVER
Definition: rodsConnect.h:59
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
rodsLogSqlReq
void rodsLogSqlReq(int onOrOff)
Definition: rodsLog.cpp:352
sockOpenForInConn
int sockOpenForInConn(rsComm_t *rsComm, int *portNum, char **addr, int proto)
Definition: sockComm.cpp:289
main
int main(int argc, char **argv)
Definition: irodsXmsgServer.cpp:22
XMSG_SERVER_PT
#define XMSG_SERVER_PT
Definition: rodsDef.h:81
usage
int usage(char *prog)
Definition: irodsXmsgServer.cpp:97
XMSG_SVR_LOGFILE
#define XMSG_SVR_LOGFILE
Definition: rsLog.hpp:14
irods_exception.hpp
signalExit
void signalExit(int)
Definition: initServer.cpp:589
irods_signal.hpp
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
ProcessType
int ProcessType
Definition: rcGlobal.cpp:16
irods_re_plugin.hpp
loopCnt
int loopCnt
Definition: irodsXmsgServer.cpp:18
irods_network_factory.hpp
irods::error::code
long long code() const
Definition: irods_error.cpp:194
startXmsgThreads
int startXmsgThreads()
Definition: xmsgLib.cpp:468
irods::network_factory
irods::error network_factory(rcComm_t *, irods::network_object_ptr &)
Definition: irods_network_factory.cpp:8
MAX_LISTEN_QUE
#define MAX_LISTEN_QUE
Definition: sockComm.h:15
rsComm_t::negotiation_results
char negotiation_results[(1024+64)]
Definition: rcConnect.h:185
v_FLAG
#define v_FLAG
Definition: irodsXmsgServer.hpp:21
SP_LOG_SQL
#define SP_LOG_SQL
Definition: rodsDef.h:264
terminate_irods_processes.e
e
Definition: terminate_irods_processes.py:19
initThreadEnv
int initThreadEnv()
Definition: xmsgLib.cpp:42
initAgent
int initAgent(int processType, rsComm_t *rsComm)
Definition: initServer.cpp:463
xmsgServerMain
int xmsgServerMain()
Definition: irodsXmsgServer.cpp:103
irods::CFG_XMSG_PORT
const std::string CFG_XMSG_PORT("xmsg_port")
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
irods::log
void log(const error &)
Definition: irods_log.cpp:13
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
xmsgLib.hpp
daemonize
void daemonize(int runMode, int logFd)
Definition: initServer.cpp:762
irods::error
Definition: irods_error.hpp:23
irods::global_re_plugin_mgr
Definition: irods_re_plugin.hpp:834
miscServerFunct.hpp
rodsLogLevel
void rodsLogLevel(int level)
Definition: rodsLog.cpp:339
SP_LOG_LEVEL
#define SP_LOG_LEVEL
Definition: rodsDef.h:265
reconstants.hpp
cleanupAndExit
void cleanupAndExit(int status)
Definition: initServer.cpp:571
rsAcceptConn
int rsAcceptConn(rsComm_t *svrComm)
Definition: sockComm.cpp:407
RULE_ENGINE_NO_CACHE
#define RULE_ENGINE_NO_CACHE
Definition: reconstants.hpp:38
irods::network_object_ptr
boost::shared_ptr< network_object > network_object_ptr
Definition: irods_network_object.hpp:78
addReqToQue
int addReqToQue(int sock)
Definition: xmsgLib.cpp:405
initXmsgHashQue
int initXmsgHashQue()
Definition: xmsgLib.cpp:564
irods::exception
Definition: irods_exception.hpp:15
SINGLE_PASS
#define SINGLE_PASS
Definition: rodsConnect.h:58
initServer.hpp
rsPipeSignalHandler
void rsPipeSignalHandler(int)
Definition: initServer.cpp:599
irodsXmsgServer.hpp
sockCommNetworkInterface.hpp
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
initRsComm
int initRsComm(rsComm_t *rsComm)
Definition: initServer.cpp:727
rsComm_t::sock
int sock
Definition: rcConnect.h:147
irods::error::result
std::string result() const
Definition: irods_error.cpp:201
irods::re_plugin_globals
std::unique_ptr< struct irods::global_re_plugin_mgr > re_plugin_globals
Definition: irods_re_plugin.cpp:16
irods_client_server_negotiation.hpp
irods::client_server_negotiation_for_server
error client_server_negotiation_for_server(irods::network_object_ptr, std::string &)
Definition: irods_server_negotiation.cpp:93