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)  

rodsAgent.cpp
Go to the documentation of this file.
1 
4 /* rodsAgent.cpp - The main code for rodsAgent
5  */
6 
7 #include <syslog.h>
8 #include "rodsAgent.hpp"
9 #include "reconstants.hpp"
10 #include "rsApiHandler.hpp"
12 #include "miscServerFunct.hpp"
14 // =-=-=-=-=-=-=-
15 #include "irods_dynamic_cast.hpp"
16 #include "irods_signal.hpp"
19 #include "irods_auth_object.hpp"
20 #include "irods_auth_factory.hpp"
21 #include "irods_auth_manager.hpp"
22 #include "irods_auth_plugin.hpp"
23 #include "irods_auth_constants.hpp"
28 #include "irods_pack_table.hpp"
29 #include "irods_server_state.hpp"
30 #include "irods_threads.hpp"
31 #include "irods_re_plugin.hpp"
33 #include "procLog.h"
34 #include "initServer.hpp"
35 
37 #include "sslSockComm.h"
38 
39 #include "sys/socket.h"
40 #include "sys/un.h"
41 #include "sys/wait.h"
42 
43 ssize_t receiveSocketFromSocket( int readFd, int *socket) {
44  struct msghdr msg;
45  memset(&msg, 0, sizeof(msg));
46  ssize_t n;
47 
48  char message_buf[1024];
49  struct iovec io = { .iov_base = message_buf, .iov_len = sizeof(message_buf) };
50  msg.msg_iov = &io;
51  msg.msg_iovlen = 1;
52 
53  char control_buf[1024];
54  msg.msg_control = control_buf;
55  msg.msg_controllen = sizeof(control_buf);
56 
57  struct cmsghdr *cmptr;
58 
59  if ( ( n = recvmsg( readFd, &msg, MSG_WAITALL ) ) <= 0) {
60  return n;
61  }
62  cmptr = CMSG_FIRSTHDR( &msg );
63  unsigned char* data = CMSG_DATA(cmptr);
64  int theSocket = *((int*) data);
65  *socket = theSocket;
66 
67  return n;
68 }
69 
70 static void set_agent_process_name(const InformationRequiredToSafelyRenameProcess& info, const int socket_fd) {
71  try {
72  std::string remote_address = socket_fd_to_remote_address(socket_fd);
73  if (remote_address.size() > 0) {
74  const std::string desired_name = "irodsServer: " + remote_address;
75  const auto l_desired = desired_name.size();
76  if (l_desired <= info.argv0_size) {
77  strncpy(info.argv0, desired_name.c_str(), info.argv0_size);
78  }
79  }
80  } catch ( const irods::exception& e ) {
81  rodsLog(LOG_ERROR, "set_agent_process_name: failed to get remote address of socket\n%s", e.what());
82  }
83 }
84 
85 int receiveDataFromServer( int conn_tmp_socket ) {
86  int status;
87  ssize_t num_bytes;
88  char in_buf[1024];
89  memset( in_buf, 0, 1024 );
90  bool data_complete = false;
91 
92  char ack_buffer[256]{};
93  unsigned int len = snprintf( ack_buffer, 256, "OK" );
94 
95  while (!data_complete) {
96  memset( in_buf, 0, 1024 );
97  num_bytes = recv( conn_tmp_socket, &in_buf, 1024, 0 );
98 
99  if ( num_bytes < 0 ) {
100  rodsLog( LOG_ERROR, "Error receiving data from rodsServer, errno = [%d]", errno, strerror( errno ) );
101  return SYS_SOCK_READ_ERR;
102  } else if ( num_bytes == 0 ) {
103  rodsLog( LOG_ERROR, "Received 0 bytes from rodsServer" );
104  return SYS_SOCK_READ_ERR;
105  }
106 
107  char* tokenized_strings = strtok(in_buf, ";");
108 
109  while (tokenized_strings != NULL) {
110  std::string tmpStr = tokenized_strings;
111 
112  if ( tmpStr == "end_of_vars" ) {
113  data_complete = true;
114 
115  // Send acknowledgement that all data has been received
116  num_bytes = send ( conn_tmp_socket, ack_buffer, strlen(ack_buffer) + 1, 0 );
117  if ( num_bytes < 0 ) {
118  rodsLog( LOG_ERROR, "Error sending acknowledgment to rodsServer, errno = [%d]", errno, strerror( errno ) );
119  return SYS_SOCK_READ_ERR;
120  }
121 
122  break;
123  }
124 
125  unsigned long i = 0;
126  for ( auto& a : tmpStr) {
127  if (a == '=') {
128  break;
129  }
130  ++i;
131  }
132 
133  if (i == tmpStr.size()) {
134  // No equal sign was found
135  continue;
136  }
137 
138  std::string lhs = tmpStr.substr(0, i);
139  std::string rhs = tmpStr.substr(i+1, tmpStr.size());
140 
141  status = setenv( lhs.c_str(), rhs.c_str(), 1 );
142 
143  tokenized_strings = strtok(NULL, ";");
144  }
145  }
146 
147  int newSocket;
148  num_bytes = receiveSocketFromSocket( conn_tmp_socket, &newSocket );
149  if ( num_bytes < 0 ) {
150  rodsLog( LOG_ERROR, "Error receiving socket from rodsServer, errno = [%d]", errno, strerror( errno ) );
151  return SYS_SOCK_READ_ERR;
152  } else if ( num_bytes == 0 ) {
153  rodsLog( LOG_ERROR, "Received 0 bytes from rodsServer" );
154  return SYS_SOCK_READ_ERR;
155  }
156 
157  char socket_buf[16];
158  snprintf(socket_buf, 16, "%d", newSocket);
159 
160  len = snprintf( ack_buffer, 256, "%d", getpid() );
161  num_bytes = send ( conn_tmp_socket, ack_buffer, len, 0 );
162  if ( num_bytes < 0 ) {
163  rodsLog( LOG_ERROR, "Error sending agent pid to rodsServer, errno = [%d]", errno, strerror( errno ) );
164  return SYS_SOCK_READ_ERR;
165  }
166 
167  status = setenv( SP_NEW_SOCK, socket_buf, 1 );
168 
169  status = close( conn_tmp_socket );
170  if ( status < 0 ) {
171  rodsLog( LOG_ERROR, "close(conn_tmp_socket) failed with errno = [%d]: %s", errno, strerror( errno ) );
172  }
173 
174  return status;
175 }
176 
177 void
179  int reaped_pid, child_status;
180  while( ( reaped_pid = waitpid( -1, &child_status, WNOHANG ) ) > 0 ) {
181  rmProcLog( reaped_pid );
182  }
183 
184  exit( 1 );
185 }
186 
187 int
188 runIrodsAgentFactory( sockaddr_un agent_addr ) {
189  int status{};
190  rsComm_t rsComm;
191 
192  signal( SIGINT, irodsAgentSignalExit );
193  signal( SIGHUP, irodsAgentSignalExit );
194  signal( SIGTERM, irodsAgentSignalExit );
195  /* set to SIG_DFL as recommended by andy.salnikov so that system()
196  * call returns real values instead of 1 */
197  signal( SIGCHLD, SIG_DFL );
198  signal( SIGUSR1, irodsAgentSignalExit );
199  signal( SIGPIPE, SIG_IGN );
200 
201  // register irods signal handlers
203 
204  initProcLog();
205 
206  int listen_socket, conn_socket, conn_tmp_socket;
207  struct sockaddr_un client_addr;
208  unsigned int len = sizeof(agent_addr);
209 
210  listen_socket = socket(AF_UNIX, SOCK_STREAM, 0);
211  if ( listen_socket < 0 ) {
212  rodsLog( LOG_ERROR, "Unable to create socket in runIrodsAgent, errno = [%d]: %s", errno, strerror( errno ) );
213  return SYS_SOCK_OPEN_ERR;
214  }
215 
216  // Delete socket if it already exists
217  unlink( agent_addr.sun_path );
218 
219  if ( bind( listen_socket, (struct sockaddr*) &agent_addr, len ) < 0 ) {
220  rodsLog( LOG_ERROR, "Unable to bind socket in runIrodsAgent, errno [%d]: %s", errno, strerror( errno ) );
221  return SYS_SOCK_BIND_ERR;
222  }
223 
224  if ( listen( listen_socket, 5) < 0 ) {
225  rodsLog( LOG_ERROR, "Unable to set up socket for listening in runIrodsAgent, errno [%d]: %s", errno, strerror( errno ) );
226  return SYS_SOCK_LISTEN_ERR;
227  }
228 
229  conn_socket = accept( listen_socket, (struct sockaddr*) &client_addr, &len);
230  if ( conn_socket < 0 ) {
231  rodsLog( LOG_ERROR, "Failed to accept client socket in runIrodsAgent, errno [%d]: %s", errno, strerror( errno ) );
232  return SYS_SOCK_ACCEPT_ERR;
233  }
234 
235  // [#3563] reproduce serverize log behavior
236  char* logFile = NULL;
237  getLogfileName( &logFile, NULL, RODS_LOGFILE );
238  LogFd = open( logFile, O_CREAT | O_WRONLY | O_APPEND, 0644 );
239  if ( LogFd < 0 ) {
240  rodsLog( LOG_NOTICE, "runIrodsAgent: Unable to open %s. errno = %d",
241  logFile, errno );
242  free( logFile );
243  return -1;
244  }
245  ( void ) dup2( LogFd, 0 );
246  ( void ) dup2( LogFd, 1 );
247  ( void ) dup2( LogFd, 2 );
248  close( LogFd );
249  LogFd = 2;
250 
251  while ( true ) {
252  // [#3563] check for log file roll over
254 
255  // Reap any zombie processes from completed agents
256  int reaped_pid, child_status;
257  while ( ( reaped_pid = waitpid( -1, &child_status, WNOHANG ) ) > 0 ) {
258  if (WIFEXITED(child_status)) {
259  const int exit_status = WEXITSTATUS(child_status);
260  const int log_level = exit_status == 0 ? LOG_DEBUG : LOG_ERROR;
261  rodsLog( log_level, "Agent process [%d] exited with status [%d]", reaped_pid, exit_status );
262  } else if (WIFSIGNALED(child_status)) {
263  const int exit_signal = WTERMSIG(child_status);
264  rodsLog( LOG_ERROR, "Agent process [%d] terminated by signal [%d]", reaped_pid, exit_signal );
265  } else {
266  rodsLog( LOG_ERROR, "Agent process [%d] terminated with unusual status [%d]", reaped_pid, child_status );
267  }
268  rmProcLog( reaped_pid );
269  }
270 
271  fd_set read_socket;
272  FD_ZERO( &read_socket );
273  FD_SET( conn_socket, &read_socket);
274  struct timeval time_out;
275  time_out.tv_sec = 0;
276  time_out.tv_usec = 30 * 1000;
277  const int ready = select(conn_socket + 1, &read_socket, nullptr, nullptr, &time_out);
278  // Check the ready socket
279  if ( ready == -1 && errno == EINTR ) {
280  // Caught a signal, return to the select() call
281  rodsLog( LOG_DEBUG, "select() was interrupted in the agent factory process, continuing..." );
282  continue;
283  } else if ( ready == -1 ) {
284  // select() failed, quit
285  rodsLog( LOG_ERROR, "select() failed with errno = [%d]: %s", errno, strerror( errno ) );
286  return SYS_SOCK_SELECT_ERR;
287  } else if (ready == 0) {
288  continue;
289  } else {
290  // select returned, attempt to receive data
291  // If 0 bytes are received, socket has been closed
292  // If a socket address is on the line, create it and fork a child process
293  char in_buf[1024]{};
294  int tmp_socket{};
295  const ssize_t bytes_received = recv( conn_socket, &in_buf, sizeof(in_buf), 0 );
296  if ( bytes_received == -1 ) {
297  rodsLog(LOG_ERROR, "Error receiving data from rodsServer, errno = [%d]: %s", errno, strerror( errno ) );
298  return SYS_SOCK_READ_ERR;
299  } else if ( bytes_received == 0 ) {
300  // The socket peer has shut down
301  rodsLog(LOG_NOTICE, "The rodsServer socket peer has shut down");
302  return 0;
303  } else {
304  // Assume that we have received valid data over the socket connection
305  // Set up the temporary (per-agent) sockets
306  sockaddr_un tmp_socket_addr{};
307  tmp_socket_addr.sun_family = AF_UNIX;
308  strncpy( tmp_socket_addr.sun_path, in_buf, sizeof(tmp_socket_addr.sun_path) );
309  unsigned int len = sizeof(tmp_socket_addr);
310 
311  tmp_socket = socket( AF_UNIX, SOCK_STREAM, 0 );
312 
313  // Delete socket if it already exists
314  unlink( tmp_socket_addr.sun_path );
315 
316  if ( bind( tmp_socket, (struct sockaddr*) &tmp_socket_addr, len ) == -1 ) {
317  rodsLog(LOG_ERROR, "[%s:%d] Unable to bind socket in receiveDataFromServer", __FUNCTION__, __LINE__);
318  return SYS_SOCK_BIND_ERR;
319  }
320 
321  if ( listen( tmp_socket, 5) == -1 ) {
322  rodsLog(LOG_ERROR, "[%s:%d] Failed to set up socket for listening in receiveDataFromServer", __FUNCTION__, __LINE__);
323  return SYS_SOCK_LISTEN_ERR;
324  }
325 
326  // Send acknowledgement that socket has been created
327  char ack_buffer[256]{};
328  len = snprintf( ack_buffer, sizeof(ack_buffer), "OK" );
329  const auto bytes_sent{send(conn_socket, ack_buffer, len, 0)};
330  if (bytes_sent < 0) {
331  rodsLog(LOG_ERROR, "[%s] - Error sending acknowledgment to rodsServer, errno = [%d][%s]", __FUNCTION__, errno, strerror(errno));
332  return SYS_SOCK_READ_ERR;
333  }
334 
335  // Wait for connection message from main server
336  memset(in_buf, 0, sizeof(in_buf));
337  recv(conn_socket, in_buf, sizeof(in_buf), 0);
338  if (0 != std::string(in_buf).compare("connection_successful")) {
339  rodsLog(LOG_ERROR, "[%s:%d] - received failure message in connecting to socket from server", __FUNCTION__, __LINE__);
340  status = close( tmp_socket );
341  if (status < 0) {
342  rodsLog(LOG_ERROR, "close(tmp_socket) failed with errno = [%d]: %s", errno, strerror(errno));
343  }
344  continue;
345  }
346 
347  conn_tmp_socket = accept( tmp_socket, (struct sockaddr*) &tmp_socket_addr, &len);
348  if ( conn_tmp_socket == -1 ) {
349  rodsLog(LOG_ERROR, "[%s:%d] Failed to accept client socket in receiveDataFromServer", __FUNCTION__, __LINE__);
350  return SYS_SOCK_ACCEPT_ERR;
351  }
352  }
353 
354  // Data is ready on conn_socket, fork a child process to handle it
355  pid_t child_pid = fork();
356  if ( child_pid == 0 ) {
357  // Child process - reload properties and receive data from server process
359 
360  status = receiveDataFromServer( conn_tmp_socket );
361 
363 
365  if ( !ret2.ok() ) {
366  rodsLog( LOG_ERROR, "rodsAgent::main: Failed to set RE cache mutex name\n%s", ret2.result().c_str() );
367  return SYS_INTERNAL_ERR;
368  }
369 
370  break;
371  } else if ( child_pid > 0 ) {
372  // Parent process - want to return to select() call
373  status = close( conn_tmp_socket );
374  if ( status < 0 ) {
375  rodsLog( LOG_ERROR, "close(conn_tmp_socket) failed with errno = [%d]: %s", errno, strerror( errno ) );
376  }
377 
378  status = close( tmp_socket );
379  if ( status < 0 ) {
380  rodsLog( LOG_ERROR, "close(tmp_socket) failed with errno = [%d]: %s", errno, strerror( errno ) );
381  }
382 
383  continue;
384  } else {
385  rodsLog( LOG_ERROR, "fork() failed in rodsAgent process factory" );
386 
387  status = close( conn_socket );
388  if ( status < 0 ) {
389  rodsLog( LOG_ERROR, "close(conn_socket) failed with errno = [%d]: %s", errno, strerror( errno ) );
390  }
391 
392  status = close( listen_socket );
393  if ( status < 0 ) {
394  rodsLog( LOG_ERROR, "close(listen_socket) failed with errno = [%d]: %s", errno, strerror( errno ) );
395  }
396 
397  return SYS_FORK_ERROR;
398  }
399  }
400  }
401 
402  memset( &rsComm, 0, sizeof( rsComm ) );
403  rsComm.thread_ctx = ( thread_context* )malloc( sizeof( thread_context ) );
404 
405  status = initRsCommWithStartupPack( &rsComm, NULL );
406 
407  // =-=-=-=-=-=-=-
408  // manufacture a network object for comms
410  irods::error ret = irods::network_factory( &rsComm, net_obj );
411  if ( !ret.ok() ) {
412  irods::log( PASS( ret ) );
413  }
414 
415  if ( status < 0 ) {
416  sendVersion( net_obj, status, 0, NULL, 0 );
418  }
419 
421  irods::re_plugin_globals->global_re_mgr.call_start_operations();
422 
423  status = getRodsEnv( &rsComm.myEnv );
424 
425  if ( status < 0 ) {
426  rodsLog( LOG_ERROR, "agentMain :: getRodsEnv failed" );
427  sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
429  }
430 
431  // =-=-=-=-=-=-=-
432  // load server side pluggable api entries
435  ret = irods::init_api_table(RsApiTable, ApiPackTable, false);
436  if ( !ret.ok() ) {
437  irods::log( PASS( ret ) );
438  return 1;
439  }
440 
441  // =-=-=-=-=-=-=-
442  // load client side pluggable api entries
444  ret = irods::init_api_table(RcApiTable, ApiPackTable, false);
445  if ( !ret.ok() ) {
446  irods::log( PASS( ret ) );
447  return 1;
448  }
449 
450  std::string svc_role;
451  ret = get_catalog_service_role(svc_role);
452  if(!ret.ok()) {
453  irods::log(PASS(ret));
454  return ret.code();
455  }
456  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
457  if ( strstr( rsComm.myEnv.rodsDebug, "CAT" ) != NULL ) {
458  chlDebug( rsComm.myEnv.rodsDebug );
459  }
460  }
461 
462  status = initAgent( RULE_ENGINE_TRY_CACHE, &rsComm );
463 
464  if ( status < 0 ) {
465  rodsLog( LOG_ERROR, "agentMain :: initAgent failed: %d", status );
466  sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
468  }
469 
470  if ( rsComm.clientUser.userName[0] != '\0' ) {
472  rsComm.clientUser.rodsZone );
473 
474  if ( status < 0 ) {
475  sendVersion( net_obj, status, 0, NULL, 0 );
477  }
478  }
479 
480  // =-=-=-=-=-=-=-
481  // handle negotiations with the client regarding TLS if requested
482  // this scope block makes valgrind happy
483  {
484  std::string neg_results;
485  ret = irods::client_server_negotiation_for_server( net_obj, neg_results );
486  if ( !ret.ok() || neg_results == irods::CS_NEG_FAILURE ) {
487  irods::log( PASS( ret ) );
488  // =-=-=-=-=-=-=-
489  // send a 'we failed to negotiate' message here??
490  // or use the error stack rule engine thingie
491  irods::log( PASS( ret ) );
492  sendVersion( net_obj, SERVER_NEGOTIATION_ERROR, 0, NULL, 0 );
493  cleanupAndExit( ret.code() );
494 
495  }
496  else {
497  // =-=-=-=-=-=-=-
498  // copy negotiation results to comm for action by network objects
499  snprintf( rsComm.negotiation_results, sizeof( rsComm.negotiation_results ), "%s", neg_results.c_str() );
500 
501  }
502  }
503 
504  /* send the server version and status as part of the protocol. Put
505  * rsComm.reconnPort as the status */
506  ret = sendVersion( net_obj, status, rsComm.reconnPort,
507  rsComm.reconnAddr, rsComm.cookie );
508 
509  if ( !ret.ok() ) {
510  irods::log( PASS( ret ) );
511  sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
513  }
514 
515  logAgentProc( &rsComm );
516 
517  // call initialization for network plugin as negotiated
518  irods::network_object_ptr new_net_obj;
519  ret = irods::network_factory( &rsComm, new_net_obj );
520  if ( !ret.ok() ) {
521  return ret.code();
522  }
523 
524  ret = sockAgentStart( new_net_obj );
525  if ( !ret.ok() ) {
526  irods::log( PASS( ret ) );
527  return ret.code();
528  }
529 
530  new_net_obj->to_server( &rsComm );
531  status = agentMain( &rsComm );
532 
533  // call initialization for network plugin as negotiated
534  ret = sockAgentStop( new_net_obj );
535  if ( !ret.ok() ) {
536  irods::log( PASS( ret ) );
537  return ret.code();
538  }
539 
540  new_net_obj->to_server( &rsComm );
541  cleanup();
542  free( rsComm.thread_ctx );
543  free( rsComm.auth_scheme );
544 
545  const int log_level = status == 0 ? LOG_DEBUG : LOG_ERROR;
546  rodsLog( log_level, "Agent [%d] exiting with status = %d", getpid(), status );
547  return status;
548 }
549 
551  rsComm_t* _comm ) {
552 
553  irods::set_server_property<std::string>(irods::CLIENT_USER_NAME_KW, _comm->clientUser.userName);
554  irods::set_server_property<std::string>(irods::CLIENT_USER_ZONE_KW, _comm->clientUser.rodsZone);
555  irods::set_server_property<int>(irods::CLIENT_USER_PRIV_KW, _comm->clientUser.authInfo.authFlag);
556  irods::set_server_property<std::string>(irods::PROXY_USER_NAME_KW, _comm->proxyUser.userName);
557  irods::set_server_property<std::string>(irods::PROXY_USER_ZONE_KW, _comm->proxyUser.rodsZone);
558  irods::set_server_property<int>(irods::PROXY_USER_PRIV_KW, _comm->clientUser.authInfo.authFlag);
559 
560 } // set_rule_engine_globals
561 
563  rsComm_t *rsComm ) {
564  if ( !rsComm ) {
566 
567  }
568 
569  int status = 0;
570 
571  // =-=-=-=-=-=-=-
572  // compiler backwards compatibility hack
573  // see header file for more details
575 
576  irods::error result = SUCCESS();
577  while ( result.ok() && status >= 0 ) {
578 
579  // set default to the native auth scheme here.
580  if ( rsComm->auth_scheme == NULL ) {
581  rsComm->auth_scheme = strdup( "native" );
582  }
583  // construct an auth object based on the scheme specified in the comm
584  irods::auth_object_ptr auth_obj;
585  irods::error ret = irods::auth_factory( rsComm->auth_scheme, &rsComm->rError, auth_obj );
586  if ( ( result = ASSERT_PASS( ret, "Failed to factory an auth object for scheme: \"%s\".", rsComm->auth_scheme ) ).ok() ) {
587 
588  irods::plugin_ptr ptr;
589  ret = auth_obj->resolve( irods::AUTH_INTERFACE, ptr );
590  if ( ( result = ASSERT_PASS( ret, "Failed to resolve the auth plugin for scheme: \"%s\".",
591  rsComm->auth_scheme ) ).ok() ) {
592 
593  irods::auth_ptr auth_plugin = boost::dynamic_pointer_cast< irods::auth >( ptr );
594 
595  // Call agent start
596  char* foo = "";
597  ret = auth_plugin->call < const char* > ( rsComm, irods::AUTH_AGENT_START, auth_obj, foo );
598  result = ASSERT_PASS( ret, "Failed during auth plugin agent start for scheme: \"%s\".", rsComm->auth_scheme );
599  }
600 
601  // =-=-=-=-=-=-=-
602  // add the user info to the server properties for
603  // reach by the operation wrapper for access by the
604  // dynamic policy enforcement points
605  try {
606  set_rule_engine_globals( rsComm );
607  } catch ( const irods::exception& e ) {
608  rodsLog( LOG_ERROR, "set_rule_engine_globals failed:\n%s", e.what());
609  }
610  }
611 
612  if ( result.ok() ) {
613  if ( rsComm->ssl_do_accept ) {
614  status = sslAccept( rsComm );
615  if ( status < 0 ) {
616  rodsLog( LOG_ERROR, "sslAccept failed in agentMain with status %d", status );
617  }
618  rsComm->ssl_do_accept = 0;
619  }
620  if ( rsComm->ssl_do_shutdown ) {
621  status = sslShutdown( rsComm );
622  if ( status < 0 ) {
623  rodsLog( LOG_ERROR, "sslShutdown failed in agentMain with status %d", status );
624  }
625  rsComm->ssl_do_shutdown = 0;
626  }
627 
629  if ( status < 0 ) {
630  if ( status == DISCONN_STATUS ) {
631  status = 0;
632  break;
633  }
634  }
635  }
636  }
637 
638  if ( !result.ok() ) {
639  irods::log( result );
640  status = result.code();
641  return status;
642  }
643 
644  // =-=-=-=-=-=-=-
645  // determine if we even need to connect, break the
646  // infinite reconnect loop.
648  return status;
649  }
650 
651  // =-=-=-=-=-=-=-
652  // find the icat host
655  if ( status < 0 ) {
656  irods::log( ERROR( status, "getRcatHost failed." ) );
657  return status;
658  }
659 
660  // =-=-=-=-=-=-=-
661  // connect to the icat host
663  if ( status < 0 ) {
664  irods::log( ERROR( status, "svrToSvrConnect failed." ) );
665  return status;
666  }
667 
668  // =-=-=-=-=-=-=-
669  // call post disconnect maintenance operations before exit
671 
672  return status;
673 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
receiveDataFromServer
int receiveDataFromServer(int conn_tmp_socket)
Definition: rodsAgent.cpp:85
irods::plugin_ptr
boost::shared_ptr< plugin_base > plugin_ptr
Definition: irods_first_class_object.hpp:18
irods::CLIENT_USER_PRIV_KW
const std::string CLIENT_USER_PRIV_KW("client_user_priv")
NULL
#define NULL
Definition: rodsDef.h:70
rsComm_t
Definition: rcConnect.h:145
sendVersion
irods::error sendVersion(irods::network_object_ptr, int, int, char *, int)
Definition: sockComm.cpp:1168
irods::environment_properties::capture
void capture()
Definition: irods_environment_properties.cpp:81
irods::CS_NEG_FAILURE
const std::string CS_NEG_FAILURE("CS_NEG_FAILURE")
SYS_INTERNAL_NULL_INPUT_ERR
@ SYS_INTERNAL_NULL_INPUT_ERR
Definition: rodsErrorTable.h:92
getRodsEnv
int getRodsEnv(rodsEnv *myRodsEnv)
Definition: getRodsEnv.cpp:112
irods_server_properties.hpp
chkLogfileName
int chkLogfileName(const char *logDir, const char *logFileName)
Definition: rsLog.cpp:88
SYS_AGENT_INIT_ERR
@ SYS_AGENT_INIT_ERR
Definition: rodsErrorTable.h:105
rsComm_t::ssl_do_shutdown
int ssl_do_shutdown
Definition: rcConnect.h:183
irods::environment_properties::instance
static environment_properties & instance()
Definition: irods_environment_properties.cpp:72
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
irods::CLIENT_USER_NAME_KW
const std::string CLIENT_USER_NAME_KW("client_user_name")
cleanup
void cleanup()
Definition: initServer.cpp:550
setRECacheSaltFromEnv
irods::error setRECacheSaltFromEnv()
Definition: miscServerFunct.cpp:3021
set_rule_engine_globals
static void set_rule_engine_globals(rsComm_t *_comm)
Definition: rodsAgent.cpp:550
userInfo_t::userName
char userName[64]
Definition: rodsUser.h:66
irods_environment_properties.hpp
rsComm_t::auth_scheme
char * auth_scheme
Definition: rcConnect.h:177
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
resc_mgr
irods::resource_manager resc_mgr
Definition: irods_resource_manager.cpp:31
sslSockComm.h
irods::auth_factory
irods::error auth_factory(const std::string &, rError_t *, irods::auth_object_ptr &)
Definition: irods_auth_factory.cpp:16
irods::PROXY_USER_NAME_KW
const std::string PROXY_USER_NAME_KW("proxy_user_name")
irods_re_serialization.hpp
LogFd
int LogFd
Definition: irods_server_globals.cpp:16
irodsAgentSignalExit
void irodsAgentSignalExit(int)
Definition: rodsAgent.cpp:178
irods::resource_manager::call_maintenance_operations
int call_maintenance_operations(rcComm_t *)
Definition: irods_resource_manager.cpp:1016
irods::init_api_table
error init_api_table(api_entry_table &_api_tbl, pack_entry_table &_pack_tbl, bool _cli_flg=true)
Definition: apiHandler.cpp:103
irods_signal.hpp
irods_threads.hpp
irods::auth_object_ptr
boost::shared_ptr< auth_object > auth_object_ptr
Definition: irods_auth_object.hpp:86
SERVER_NEGOTIATION_ERROR
@ SERVER_NEGOTIATION_ERROR
Definition: rodsErrorTable.h:774
register_handlers
void register_handlers(void)
Definition: irods_signal.cpp:22
SP_NEW_SOCK
#define SP_NEW_SOCK
Definition: rodsDef.h:252
READ_HEADER_TIMEOUT
#define READ_HEADER_TIMEOUT
Definition: rsApiHandler.hpp:28
rsComm_t::thread_ctx
struct thread_context * thread_ctx
Definition: rcConnect.h:171
RsApiTable
irods::api_entry_table RsApiTable
SYS_SOCK_ACCEPT_ERR
@ SYS_SOCK_ACCEPT_ERR
Definition: rodsErrorTable.h:71
irods::AUTH_INTERFACE
const std::string AUTH_INTERFACE("irods_auth_interface")
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
rsComm_t::cookie
int cookie
Definition: rcConnect.h:169
socket_fd_to_remote_address
std::string socket_fd_to_remote_address(const int fd)
Definition: irods_socket_information.cpp:14
irods_auth_constants.hpp
irods_pack_table.hpp
receiveSocketFromSocket
ssize_t receiveSocketFromSocket(int readFd, int *socket)
Definition: rodsAgent.cpp:43
irods_re_plugin.hpp
SYS_INTERNAL_ERR
@ SYS_INTERNAL_ERR
Definition: rodsErrorTable.h:211
rsComm_t::myEnv
rodsEnv myEnv
Definition: rcConnect.h:154
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
irods_network_factory.hpp
SYS_SOCK_OPEN_ERR
@ SYS_SOCK_OPEN_ERR
Definition: rodsErrorTable.h:68
irods_auth_object.hpp
rsComm_t::rError
rError_t rError
Definition: rcConnect.h:158
irods::error::code
long long code() const
Definition: irods_error.cpp:194
irods::CLIENT_USER_ZONE_KW
const std::string CLIENT_USER_ZONE_KW("client_user_zone")
irods::network_factory
irods::error network_factory(rcComm_t *, irods::network_object_ptr &)
Definition: irods_network_factory.cpp:8
irods_auth_factory.hpp
sockAgentStart
irods::error sockAgentStart(irods::network_object_ptr)
SYS_SOCK_READ_ERR
@ SYS_SOCK_READ_ERR
Definition: rodsErrorTable.h:181
LOG_DEBUG
#define LOG_DEBUG
Definition: rodsLog.h:23
rsComm_t::proxyUser
userInfo_t proxyUser
Definition: rcConnect.h:152
rodsAgent.hpp
sslShutdown
int sslShutdown(rsComm_t *rsComm)
Definition: sslSockComm.cpp:194
rsComm_t::negotiation_results
char negotiation_results[(1024+64)]
Definition: rcConnect.h:185
irods::get_server_api_table
api_entry_table & get_server_api_table()
Definition: irods_server_api_table.cpp:8
InformationRequiredToSafelyRenameProcess::argv0
char * argv0
Definition: initServer.hpp:17
irods::CFG_SERVICE_ROLE_PROVIDER
const std::string CFG_SERVICE_ROLE_PROVIDER("provider")
irods_server_api_table.hpp
chlDebug
int chlDebug(const char *debugMode)
Definition: icatHighLevelRoutines.cpp:51
terminate_irods_processes.e
e
Definition: terminate_irods_processes.py:19
logAgentProc
int logAgentProc(rsComm_t *)
Definition: procLog.cpp:33
irods::resource_manager::need_maintenance_operations
bool need_maintenance_operations()
Definition: irods_resource_manager.cpp:990
SYS_SOCK_LISTEN_ERR
@ SYS_SOCK_LISTEN_ERR
Definition: rodsErrorTable.h:69
rsComm_t::reconnPort
int reconnPort
Definition: rcConnect.h:166
SYS_FORK_ERROR
@ SYS_FORK_ERROR
Definition: rodsErrorTable.h:116
runIrodsAgentFactory
int runIrodsAgentFactory(sockaddr_un agent_addr)
Definition: rodsAgent.cpp:188
ASSERT_PASS
#define ASSERT_PASS(prev_error_, format_,...)
Definition: irods_error.hpp:124
InformationRequiredToSafelyRenameProcess
Definition: initServer.hpp:15
readAndProcClientMsg
int readAndProcClientMsg(rsComm_t *rsComm, int retApiStatus)
Definition: rsApiHandler.cpp:488
rsComm_t::reconnAddr
char * reconnAddr
Definition: rcConnect.h:168
rmProcLog
int rmProcLog(int pid)
Definition: procLog.cpp:100
set_agent_process_name
static void set_agent_process_name(const InformationRequiredToSafelyRenameProcess &info, const int socket_fd)
Definition: rodsAgent.cpp:70
initAgent
int initAgent(int processType, rsComm_t *rsComm)
Definition: initServer.cpp:463
svrToSvrConnect
int svrToSvrConnect(rsComm_t *rsComm, rodsServerHost_t *rodsServerHost)
Definition: miscServerFunct.cpp:106
irods::dynamic_cast_hack
void dynamic_cast_hack()
Definition: irods_dynamic_cast.hpp:17
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
irods_auth_manager.hpp
userInfo_t::rodsZone
char rodsZone[64]
Definition: rodsUser.h:67
irods::log
void log(const error &)
Definition: irods_log.cpp:13
RODS_LOGFILE
#define RODS_LOGFILE
Definition: rsLog.hpp:11
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
rodsEnv::rodsDebug
char rodsDebug[64]
Definition: getRodsEnv.h:21
irods::AUTH_AGENT_START
const std::string AUTH_AGENT_START("auth_agent_start")
irods_dynamic_cast.hpp
rsComm_t::clientUser
userInfo_t clientUser
Definition: rcConnect.h:153
getRcatHost
int getRcatHost(int rcatType, const char *rcatZoneHint, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:88
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
irods::error
Definition: irods_error.hpp:23
irods::global_re_plugin_mgr
Definition: irods_re_plugin.hpp:834
miscServerFunct.hpp
chkAllowedUser
int chkAllowedUser(const char *userName, const char *rodsZone)
Definition: initServer.cpp:1008
irods_client_api_table.hpp
getLogfileName
void getLogfileName(char **logFile, const char *logDir, const char *logFileName)
Definition: rsLog.cpp:45
irods::api_entry_table
Definition: apiHandler.hpp:353
SYS_SOCK_SELECT_ERR
@ SYS_SOCK_SELECT_ERR
Definition: rodsErrorTable.h:212
reconstants.hpp
irods_auth_plugin.hpp
cleanupAndExit
void cleanupAndExit(int status)
Definition: initServer.cpp:571
irods::server_properties::instance
static server_properties & instance()
Definition: irods_server_properties.cpp:30
MASTER_RCAT
#define MASTER_RCAT
Definition: rodsDef.h:85
get_catalog_service_role
irods::error get_catalog_service_role(std::string &_role)
Definition: miscServerFunct.cpp:3153
rodsServerHost
Definition: rodsConnect.h:62
procLog.h
irods::network_object_ptr
boost::shared_ptr< network_object > network_object_ptr
Definition: irods_network_object.hpp:78
DISCONN_STATUS
#define DISCONN_STATUS
Definition: rsApiHandler.hpp:18
irods_server_state.hpp
InformationRequiredToSafelyRenameProcess::argv0_size
size_t argv0_size
Definition: initServer.hpp:18
irods::get_pack_table
irods::pack_entry_table & get_pack_table()
Definition: irods_pack_table.cpp:15
sslAccept
int sslAccept(rsComm_t *rsComm)
Definition: sslSockComm.cpp:142
irods::exception
Definition: irods_exception.hpp:15
icatHighLevelRoutines.hpp
SYS_SOCK_BIND_ERR
@ SYS_SOCK_BIND_ERR
Definition: rodsErrorTable.h:70
irods_socket_information.hpp
irods::pack_entry_table
Definition: irods_pack_table.hpp:13
thread_context
Definition: irods_threads.hpp:10
initServer.hpp
initRsCommWithStartupPack
int initRsCommWithStartupPack(rsComm_t *rsComm, startupPack_t *startupPack)
Definition: initServer.cpp:834
irods::server_properties::capture
void capture()
Definition: irods_server_properties.cpp:39
userInfo_t::authInfo
authInfo_t authInfo
Definition: rodsUser.h:70
agentMain
int agentMain(rsComm_t *rsComm)
Definition: rodsAgent.cpp:562
rsApiHandler.hpp
irods::get_client_api_table
api_entry_table & get_client_api_table()
Definition: irods_client_api_table.cpp:8
irods::PROXY_USER_PRIV_KW
const std::string PROXY_USER_PRIV_KW("proxy_user_priv")
RULE_ENGINE_TRY_CACHE
#define RULE_ENGINE_TRY_CACHE
Definition: reconstants.hpp:37
authInfo_t::authFlag
int authFlag
Definition: rodsUser.h:42
irods::PROXY_USER_ZONE_KW
const std::string PROXY_USER_ZONE_KW("proxy_user_zone")
sockCommNetworkInterface.hpp
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
rsComm_t::ssl_do_accept
int ssl_do_accept
Definition: rcConnect.h:182
irods::auth_ptr
boost::shared_ptr< auth > auth_ptr
Definition: irods_auth_types.hpp:19
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
initProcLog
int initProcLog()
Definition: procLog.cpp:26
irods::client_server_negotiation_for_server
error client_server_negotiation_for_server(irods::network_object_ptr, std::string &)
Definition: irods_server_negotiation.cpp:93
sockAgentStop
irods::error sockAgentStop(irods::network_object_ptr)