void command_zombtest( struct char_buffer* cbuff ) {
	char str_arg1[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg2[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg3[CONFIG_CLI_MAX_CHARACTERS];
	int block_size = 0;
	int num_blocks = 0;

	if(
		next_token( cbuff, str_arg1 ) == 0 ||
		!str_is_integer( str_arg1 ) ||
		next_token( cbuff, str_arg2 ) == 0 ||
		!str_is_integer( str_arg2 ) ||
		next_token( cbuff, str_arg3 ) != 0 ) {
		CommandOutput( "[ZOMB]\tInvalid Arguments" );
		return;
	}

	block_size = str_atoi( str_arg1 );
	num_blocks = str_atoi( str_arg2 );

	CommandOutput( "[ZOMB] STARTING ZOMBIE RECLEMATION TEST [%d blocks of size %d]", num_blocks, block_size );
	struct two_number_message init_msg;
	int zombtesttid = Create( PRIORITY_TEST_ZOMB, &task_test_zombie_reclaim );
	init_msg.num1 = block_size;
	init_msg.num2 = num_blocks;
	Send( zombtesttid, (char *)&init_msg, sizeof (init_msg), (char *)0, 0 );
}
void command_tr( struct char_buffer* cbuff ) {
	char str_arg1[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg2[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg3[CONFIG_CLI_MAX_CHARACTERS];
	int arg1 = 0;
	int arg2 = 0;

	if(
		next_token( cbuff, str_arg1 ) == 0 ||
		!str_is_integer( str_arg1 ) ||
		next_token( cbuff, str_arg2 ) == 0 ||
		!str_is_integer( str_arg2 ) ||
		next_token( cbuff, str_arg3 ) != 0 ) {
		CommandOutput( "[TR]\tInvalid Arguments" );
		return;
	}

	arg1 = str_atoi( str_arg1 );
	arg2 = str_atoi( str_arg2 );

	if( arg2 < 0 || arg2 > 14 ) {
		CommandOutput( "[TR]\tInvalid Train Speed" );
		return;
	}


	if( SetTrainSpeed( arg1, arg2 ) != -1 ) {
		CommandOutput( "[TR]\tSetting Train %d to Speed %d", arg1, arg2 );
	} else {
		CommandOutput( "[TR]\tERROR: Train %d has not been added", arg1 );
	}
}
Int16 SqlSealogEvent::sendEvent(Int16 eventId, Lng32 slSeverity)
{
  Int32 rc = 0;
#ifndef SP_DIS
  char eventidStr[10]="        ";
  Lng32 eventidLen = 0;
  str_sprintf(eventidStr,"10%d%06d",SQEVL_SQL,eventId);
  str_strip_blanks(eventidStr,eventidLen);
  Lng32 eventIdVal = (Lng32)str_atoi(eventidStr,eventidLen);
   common::event_header * eventHeader = sqlInfoEvent_.mutable_header();
  common::info_header * infoHeader = eventHeader->mutable_header();  

   rc = initAMQPInfoHeader(infoHeader, SQEVL_SQL);
   if (rc)
     //add trace log
     return rc;
  sqlInfoEvent_.mutable_header()->set_event_id(eventIdVal);
  sqlInfoEvent_.mutable_header()->set_event_severity(slSeverity);
  setExperienceLevel("ADVANCED");
  setTarget("LOGONLY");

  AMQPRoutingKey routingKey(SP_EVENT, SP_SQLPACKAGE,  SP_INSTANCE, 
                              SP_PUBLIC,  SP_GPBPROTOCOL,  "info_event"); 
  try {
    rc = sendAMQPMessage(true, sqlInfoEvent_.SerializeAsString(), SP_CONTENT_TYPE_APP, routingKey);
  } catch(...) {
    rc = -1;
  }
#endif
  return rc;
}
void command_st( struct char_buffer* cbuff ) {
	char str_arg1[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg2[CONFIG_CLI_MAX_CHARACTERS];
	int arg1 = 0;

	if(
		next_token( cbuff, str_arg1 ) == 0 ||
		!str_is_integer( str_arg1 ) ||
		next_token( cbuff, str_arg2 ) != 0 ) {
		CommandOutput( "[ST]\tInvalid Arguments" );
		return;
	}

	arg1 = str_atoi( str_arg1 );

	//check the switch number
	if( switch_index( arg1 ) == -1 ) {
		CommandOutput( "[ST]\tInvalid Switch Number" );
		return;
	}

	int status = SwitchStatus( arg1 );
	//display the state that the switch was last switched into
	if( status == SWITCH_CURVED ) {
		CommandOutput( "[ST]\tSwitch %d is Curved", arg1 );
	} else if( status == SWITCH_STRAIGHT ) {
		CommandOutput( "[ST]\tSwitch %d is Straight", arg1 );
	} else if( status == SWITCH_UNKNOWN ) {
		CommandOutput( "[ST]\tSwitch %d is in an Unknown state", arg1 );
	} else {
		CommandOutput( "[ST]\t%d", status );
	}
}
Example #5
0
const unsigned char*
vsf_sysutil_parse_uchar_string_sep(
  const struct mystr* p_str, char sep, unsigned char* p_items,
  unsigned int items)
{
  static struct mystr s_tmp_str;
  unsigned int i;
  str_copy(&s_tmp_str, p_str);
  for (i=0; i<items; i++)
  {
    static struct mystr s_rhs_sep_str;
    int this_number;
    /* This puts a single separator delimited field in tmp_str */
    str_split_char(&s_tmp_str, &s_rhs_sep_str, sep);
    /* Sanity - check for too many or two few dots! */
    if ( (i < (items-1) && str_isempty(&s_rhs_sep_str)) ||
         (i == (items-1) && !str_isempty(&s_rhs_sep_str)))
    {
      return 0;
    }
    this_number = str_atoi(&s_tmp_str);
    if (this_number < 0 || this_number > 255)
    {
      return 0;
    }
    /* If this truncates from int to uchar, we don't care */
    p_items[i] = (unsigned char) this_number;
    /* The right hand side of the comma now becomes the new string to
     * breakdown
     */
    str_copy(&s_tmp_str, &s_rhs_sep_str);
  }
  return p_items;
}
Lng32 AQRInfo::setCQDs(Lng32 numCQDs, char * cqdStr,
		      ContextCli * context)
{
  Lng32 rc = 0;
  if (numCQDs > 0)
    {
      for (Lng32 i = 0; i < numCQDs; i++)
	{
	  // for each entry in the cqdStr, extract the corresponding
	  // entry from cqdInfo array and execute that cqd.
	  // Entries in cqdStr are of the form:
	  //  NN:NN:....NN
	  //  For ex:   numCQDs=2 and cqdStr = 01:03   
	  // would indicate that entries #1 and #3 from the cqdInfo
	  // array need to be executed and set.
	  Int64 v = str_atoi(&cqdStr[i*3], 2);
	  if (v <= 0)
	    return -1;

	  rc = context->holdAndSetCQD(cqdInfo[(v-1)*2].str,
				      cqdInfo[(v-1)*2+1].str);
	  if (rc < 0)
	    return rc;
	}
    }
  
  return 0;
}
void command_sos( struct char_buffer* cbuff ) {
	char str_arg1[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg2[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg3[CONFIG_CLI_MAX_CHARACTERS];

	if(
		next_token( cbuff, str_arg1 ) == 0 ||
		!str_is_integer( str_arg1 ) ||
		next_token( cbuff, str_arg2 ) == 0 ||
		next_token( cbuff, str_arg3 ) != 0 ) {
		CommandOutput( "[SOS]\tInvalid Arguments" );
		return;
	}

	int train_num = str_atoi( str_arg1 );

	int sensor_num = 0;
	if( !sensor_str2num( str_arg2, &sensor_num ) ) {
		CommandOutput( "[SOS]\tInvalid Sensor Name" );
		return;
	}

	if( SOSTrain( train_num, sensor_num ) != -1 ) {
		CommandOutput( "[SOS]\tStopping Train [%d] on Trigger of Sensor [%s] aka [%d]", train_num, str_arg2, sensor_num );
	} else {
		CommandOutput( "[SOS]\tERROR: Train %d has not been added", train_num );
	}
}
void command_route( struct char_buffer* cbuff, struct track_node * track_data ) {
	char str_arg1[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg2[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg3[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg4[CONFIG_CLI_MAX_CHARACTERS];
	int destination = 0, offset = 0;

	int train_num;
	struct train_route_request_message reqmsg;
	struct empty_message rpl;
	int tid = WhoIs( "traindispatch" );


	if(
		next_token( cbuff, str_arg1 ) == 0 ||
		!str_is_integer( str_arg1 ) ||
		next_token( cbuff, str_arg2 ) == 0) {
		CommandOutput( "[ROUTE]\tInvalid Arguments" );
		return;
	}
	if( next_token( cbuff, str_arg3 ) != 0 ) {
		offset = str_atoi( str_arg3 );
	}
	if(	next_token( cbuff, str_arg4 ) != 0 ) {
		CommandOutput( "[ROUTE]\tInvalid Arguments" );
		return;
	}

	train_num = str_atoi( str_arg1 );
	if( !track_str2num( track_data, str_arg2, &destination ) ) {
		CommandOutput( "[ROUTE]\tInvalid Landmark Name" );
		return;
	}


	reqmsg.message_type = TRAIN_ROUTE_REQUEST_MESSAGE;
	reqmsg.train = train_num;
	reqmsg.pos1.node = -1;
	reqmsg.pos1.offset = 0;
	reqmsg.pos2.node = destination;
	reqmsg.pos2.offset = offset;

	Send( tid, (char *)&reqmsg, sizeof (reqmsg), (char *)&rpl, sizeof (rpl) );

	CommandOutput( "[ROUTE] Routing Train %d to %s + %d mm", train_num, track_data[destination].name, offset );

}
Example #9
0
static void
handle_port(struct vsf_session* p_sess)
{
  static struct mystr s_tmp_str;
  unsigned short the_port;
  unsigned char vals[6];
  int i;
  pasv_cleanup(p_sess);
  port_cleanup(p_sess);
  str_copy(&s_tmp_str, &p_sess->ftp_arg_str);
  for (i=0; i<6; i++)
  {
    static struct mystr s_rhs_comma_str;
    int this_number;
    /* This puts a single , delimited field in tmp_str */
    str_split_char(&s_tmp_str, &s_rhs_comma_str, ',');
    /* Sanity - check for too many or two few commas! */
    if ( (i<5 && str_isempty(&s_rhs_comma_str)) ||
         (i==5 && !str_isempty(&s_rhs_comma_str)))
    {
      vsf_cmdio_write(p_sess, FTP_BADCMD, "Illegal PORT command.");
      return;
    }
    this_number = str_atoi(&s_tmp_str);
    if (this_number < 0 || this_number > 255)
    {
      vsf_cmdio_write(p_sess, FTP_BADCMD, "Illegal PORT command.");
      return;
    }
    /* If this truncates from int to uchar, we don't care */
    vals[i] = (unsigned char) this_number;
    /* The right hand side of the comma now becomes the new string to
     * breakdown
     */
    str_copy(&s_tmp_str, &s_rhs_comma_str);
  }
  the_port = vals[4] << 8;
  the_port |= vals[5];
  vsf_sysutil_sockaddr_alloc_ipv4(&p_sess->p_port_sockaddr);
  vsf_sysutil_sockaddr_set_ipv4addr(p_sess->p_port_sockaddr, vals);
  vsf_sysutil_sockaddr_set_port(p_sess->p_port_sockaddr, the_port);
  /* SECURITY:
   * 1) Reject requests not connecting to the control socket IP
   * 2) Reject connects to privileged ports
   */
  if (!tunable_port_promiscuous)
  {
    if (!vsf_sysutil_sockaddr_addr_equal(p_sess->p_remote_addr,
                                         p_sess->p_port_sockaddr) ||
        vsf_sysutil_is_port_reserved(the_port))
    {
      vsf_cmdio_write(p_sess, FTP_BADCMD, "Illegal PORT command.");
      port_cleanup(p_sess);
      return;
    }
  }
  vsf_cmdio_write(p_sess, FTP_PORTOK,
                  "PORT command successful. Consider using PASV.");
}
Example #10
0
Lng32 ExpLOBoper::ExpGetLOBnumFromDescName(char * descName, Lng32 descNameLen)
{
  // Desc Name Format: LOBDescHandle_%020Ld_%04d
  char * lobNumPtr = &descName[sizeof(LOB_DESC_HANDLE_PREFIX) + 20 + 1];
  Lng32 lobNum = str_atoi(lobNumPtr, 4);
  
  return lobNum;
}
Lng32 ExpLOBoper::ExpGetLOBnumFromDescName(char * descName, Lng32 descNameLen)
{
  // Desc Name Format: LOBDescHandle_%020Ld_%04d
  char * lobNumPtr = &descName[strlen("LOBDescHandle_") + 20 + 1];
  Lng32 lobNum = str_atoi(lobNumPtr, 4);
  
  return lobNum;
}
void command_tdir( struct char_buffer* cbuff ) {
	char str_arg1[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg2[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg3[CONFIG_CLI_MAX_CHARACTERS];
	int arg1 = 0;
	int arg2 = 0;

	if(
		next_token( cbuff, str_arg1 ) == 0 ||
		!str_is_integer( str_arg1 ) ||
		next_token( cbuff, str_arg2 ) == 0 ||
		str_arg2[0] == '\0' ||
		str_arg2[1] != '\0' ||
		next_token( cbuff, str_arg3 ) != 0 ) {
		CommandOutput( "[TRDIR]\tInvalid Arguments" );
		return;
	}

	arg1 = str_atoi( str_arg1 );

	if( str_arg2[0] != 'f' && str_arg2[0] != 'b' ) {
		CommandOutput( "[TRDIR]\tInvalid Direction" );
		return;
	}

	if( str_arg2[0] == 'f' ) {
		arg2 = DIRECTION_FORWARD;
	} else {
		arg2 = DIRECTION_BACKWARD;
	}

	//TODO: send direction to train


	if( SetTrainDirection( arg1, arg2 ) != -1 ) {
		switch( arg2 ) {
			case DIRECTION_FORWARD:
				CommandOutput( "[TRDIR]\tSetting Train %d to Direction Forward", arg1 );
				break;
			default:
				CommandOutput( "[TRDIR]\tSetting Train %d to Direction Backward", arg1 );
				break;
		}
	} else {
		CommandOutput( "[TR]\tERROR: Train %d has not been added", arg1 );
	}
}
ULng32 NAColumnArray::getMaxTrafHbaseColQualifier() const
{
  NAColumn *column;
  char * colQualPtr;
  Lng32 colQualLen;
  Int64 colQVal;
  ULng32 maxVal = 0;

  for (CollIndex i = 0; i < entries(); i++)
    {
      column = (*this)[i];
      colQualPtr = (char*)column->getHbaseColQual().data();
      colQualLen = column->getHbaseColQual().length();
      colQVal = str_atoi(colQualPtr, colQualLen);
      if (colQVal > maxVal)
	maxVal = colQVal ;
    }
  return maxVal;
}
void command_sw( struct char_buffer* cbuff ) {
	char str_arg1[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg2[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg3[CONFIG_CLI_MAX_CHARACTERS];
	int arg1 = 0;
	char arg2;

	if(
		next_token( cbuff, str_arg1 ) == 0 ||
		!str_is_integer( str_arg1 ) ||
		next_token( cbuff, str_arg2 ) == 0 ||
		str_arg2[0] == '\0' ||
		str_arg2[1] != '\0' ||
		next_token( cbuff, str_arg3 ) != 0 ) {
		CommandOutput( "[SW]\tInvalid Arguments" );
		return;
	}

	arg1 = str_atoi( str_arg1 );

	//check the switch number
	if( switch_index( arg1 ) == -1 ) {
		CommandOutput( "[SW]\tInvalid Switch Number" );
		return;
	}

	//check the switch state
	if( str_arg2[0] != 's' && str_arg2[0] != 'c' ) {
		CommandOutput( "[SW]\tInvalid Switch State" );
		return;
	}

	if( str_arg2[0] == 'c' ) {
		arg2 = (char)SWITCH_CURVED;
		CommandOutput( "[SW]\tSwitching %d To Curved", arg1 );
	} else {
		arg2 = (char)SWITCH_STRAIGHT;
		CommandOutput( "[SW]\tSwitching %d To Straight", arg1 );
	}

	SetSwitch( arg1, arg2 );
}
Lng32 AQRInfo::resetCQDs(Lng32 numCQDs, char * cqdStr,
			  ContextCli * context)
{
  Lng32 rc = 0;
  if (numCQDs > 0)
    {
      for (Lng32 i = 0; i < numCQDs; i++)
	{
	  Int64 v = str_atoi(&cqdStr[i*3], 2);
	  if (v <= 0)
	    return -1;

	  rc = context->restoreCQD(cqdInfo[(v-1)*2].str);
	  if (rc < 0)
	    return rc;
	}
    }

  return rc;
}
void command_delay( struct char_buffer* cbuff ) {
	char str_arg1[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg2[CONFIG_CLI_MAX_CHARACTERS];
	int arg1 = 0;

	if(
		next_token( cbuff, str_arg1 ) == 0 ||
		!str_is_integer( str_arg1 ) ||
		next_token( cbuff, str_arg2 ) != 0 ) {
		CommandOutput( "[DELAY]\tInvalid Arguments" );
		return;
	}

	arg1 = str_atoi( str_arg1 );

	//if(arg1 > 1000){ arg1 = 1000; }

	CommandOutput( "[DELAY]\tDelaying For %d", arg1 );
	Delay( arg1 );
}
void command_rv( struct char_buffer* cbuff ) {
	char str_arg1[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg2[CONFIG_CLI_MAX_CHARACTERS];
	int arg1 = 0;

	if(
		next_token( cbuff, str_arg1 ) == 0 ||
		!str_is_integer( str_arg1 ) ||
		next_token( cbuff, str_arg2 ) != 0 ) {
		CommandOutput( "[RV]\tInvalid Arguments" );
		return;
	}

	arg1 = str_atoi( str_arg1 );

	if( ReverseTrain( arg1 ) != -1 ) {
		CommandOutput( "[RV]\tReversing Train %d", arg1 );
	} else {
		CommandOutput( "[RV]\tERROR: Train %d has not been added", arg1 );
	}


}
void command_add( struct char_buffer* cbuff, int track ) {
	char str_arg1[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg2[CONFIG_CLI_MAX_CHARACTERS];
	int arg1 = 0;

	if(
		next_token( cbuff, str_arg1 ) == 0 ||
		!str_is_integer( str_arg1 ) ||
		next_token( cbuff, str_arg2 ) != 0 ) {
		CommandOutput( "[ADD]\tInvalid Arguments" );
		return;
	}

	arg1 = str_atoi( str_arg1 );

	if( track == TRACK_UNINITIALIZED ) {
		CommandOutput( "[ADD]\tERROR: No track has been selected" );
		return;
	}

	CommandOutput( "[ADD]\tAdding Train %d", arg1 );
	AddTrain( arg1, track );
}
void command_looptest( struct char_buffer* cbuff ) {
	char str_arg1[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg2[CONFIG_CLI_MAX_CHARACTERS];
	int arg1 = 0;

	if(
		next_token( cbuff, str_arg1 ) == 0 ||
		!str_is_integer( str_arg1 ) ||
		next_token( cbuff, str_arg2 ) != 0 ) {
		CommandOutput( "[LOOPTEST]\tInvalid Arguments" );
		return;
	}

	arg1 = str_atoi( str_arg1 );

	//check if priority is valid
	if( arg1 < 0 || arg1 >= PRIORITY_NUM_PRIORITIES ) {
		CommandOutput( "[LOOPTEST]\tInvalid Priority" );
		return;
	}

	CommandOutput( "[LOOPTEST]\tStarting Loop Test" );
	Create( arg1, &task_test_loop_time );
}
 Int32 SQLMXLoggingArea::logSQLMXEventForError( ULng32 sqlcode, 
                                        const char* experienceLevel,
                                        const char* severityLevel,
                                        const char* eventTarget,
					const char *msgTxt,
					const char* sqlId,
					const Lng32 Int0,
					const Lng32 Int1,
					const Lng32 Int2,
					const Lng32 Int3,
					const Lng32 Int4,
				        const char *String0,
					const char * String1,
					const char * String2,
					const char * String3,
					const char * String4,
					const char * serverName,
					const char * connectionName,
					const char * constraintCatalog,
					const char * constraintSchema,
					const char * constraintName,
					const char * triggerCatalog,
					const char * triggerSchema,
					const char *triggerName,
					const char *catalogName,
					const char *schemaName,
					const char *tableName,
					const char *columnName,
					const Int64 currTransid,
					const Lng32 rowNumber,
					const Lng32 platformCode,
					NABoolean isWarning	
					)
{
  Int32 rc = 0;
  // sealog logging of sql error events
  // declare a event stack variable and populate
#ifndef SP_DIS
  bool lockedMutex = lockMutex();

  sql::error_event sql_error_event;
  Int32 qpidNodePort = atoi(getenv("QPID_NODE_PORT"));

  common::event_header * eventHeader = sql_error_event.mutable_header();
  common::info_header * infoHeader = eventHeader->mutable_header();  


  if (!SQLMXLoggingArea::establishedAMQPConnection())
    {
      rc = createAMQPConnection(NULL,-1);
      if (rc)
      {
        if (lockedMutex)
          unlockMutex();
	return rc;
      }
      establishedAMQPConnection_ = TRUE;
    }
 

  char eventidStr[10]="        ";
  Lng32 eventidLen = 0;
  str_sprintf(eventidStr,"10%d%06d",SQEVL_SQL,sqlcode);
  str_strip_blanks(eventidStr,eventidLen);
  Lng32 eventIdVal = (Lng32)str_atoi(eventidStr,eventidLen);
 
  sql_error_event.mutable_header()->set_event_id(eventIdVal);
  sql_error_event.mutable_header()->set_event_severity(sqlToSLSeverity(severityLevel, isWarning));

 
  sql_error_event.set_sqlcode(sqlcode);
  if (sqlId)
    sql_error_event.set_sqlid(sqlId);
  else
    {
      SB_Phandle_Type myphandle;
      XPROCESSHANDLE_GETMINE_(&myphandle);
      char charProcHandle[200];
      char myprocname[30];
      Int32 mycpu,mypin,mynodenumber=0;
      short myproclength = 0;
      XPROCESSHANDLE_DECOMPOSE_(&myphandle, &mycpu, &mypin, &mynodenumber,NULL,100, NULL, myprocname,100, &myproclength); 
      myprocname[myproclength] = '\0';
      str_sprintf(charProcHandle,"%d,%d,%d,%s",mycpu,mypin,mynodenumber,myprocname);
      sql_error_event.set_sqlid(charProcHandle);
    }
  sql_error_event.set_message_text(msgTxt);
  sql_error_event.set_err_experience_level(experienceLevel);
  sql_error_event.set_err_target(eventTarget);
  sql_error_event.set_int0(Int0);
  sql_error_event.set_int1(Int1);
  sql_error_event.set_int2(Int2);
  sql_error_event.set_int3(Int3);
  sql_error_event.set_int4(Int4);

  if (String0)
    sql_error_event.set_string0(String0);
  if (String1)
    sql_error_event.set_string1(String1);
  if (String2)
    sql_error_event.set_string2(String2);
  if (String3)
    sql_error_event.set_string3(String3);
  if (String4)
    sql_error_event.set_string4(String4);
  //LCOV_EXCL_START - unused members of diags are
  if (serverName)
    sql_error_event.set_server_name(serverName);
  if (connectionName)
    sql_error_event.set_connection_name(connectionName);
  //LCOV_EXCL_STOP
  if (constraintCatalog)
    sql_error_event.set_constraint_catalog(constraintCatalog);
  if (constraintSchema)
    sql_error_event.set_constraint_schema(constraintSchema);
  if (constraintName)
    sql_error_event.set_constraint_name(constraintName);
  if (triggerCatalog)
    sql_error_event.set_trigger_catalog(triggerCatalog);
  if (triggerSchema)
    sql_error_event.set_trigger_schema(triggerSchema);
  if (triggerName)
    sql_error_event.set_trigger_name(triggerName);
  
  if (catalogName)
    sql_error_event.set_catalog_name(catalogName);
  if (schemaName)
    sql_error_event.set_schema_name(schemaName);
  if (tableName)
    sql_error_event.set_table_name(tableName);
  if (columnName)
    sql_error_event.set_column_name(columnName);
  
  sql_error_event.set_current_transid(currTransid);
  sql_error_event.set_row_number(rowNumber);  
  sql_error_event.set_platform_error_code(platformCode);

  rc =  initAMQPInfoHeader(infoHeader, SQEVL_SQL);
  if (rc)
    {
      closeAMQPConnection();
      establishedAMQPConnection_ = FALSE;
      if (lockedMutex)
        unlockMutex();
      return rc;
    }
 
  AMQPRoutingKey routingKey(SP_EVENT, SP_SQLPACKAGE,  SP_INSTANCE, 
                              SP_PUBLIC,  SP_GPBPROTOCOL,  "error_event"); 
  try { 
    rc = sendAMQPMessage(true, sql_error_event.SerializeAsString(), 
                         SP_CONTENT_TYPE_APP, routingKey);
    if (rc) throw 1;
  } catch (...) {
    closeAMQPConnection(); 
    establishedAMQPConnection_ = FALSE;
    if (!rc) rc = SP_SEND_FAILED;
    if (lockedMutex)
       unlockMutex();
    return rc;
  }

  if (lockedMutex)
    unlockMutex();
#else
  rc = 0;
#endif

  return rc;

}
Example #21
0
static void
handle_config_setting(struct mystr* p_setting_str, struct mystr* p_value_str)
{
  if (str_isempty(p_value_str))
  {
    die("missing value in config file");
  }
  /* Is it a boolean value? */
  {
    const struct parseconf_bool_setting* p_bool_setting = parseconf_bool_array;
    while (p_bool_setting->p_setting_name != 0)
    {
      if (str_equal_text(p_setting_str, p_bool_setting->p_setting_name))
      {
        /* Got it */
        str_upper(p_value_str);
        if (str_equal_text(p_value_str, "YES") ||
            str_equal_text(p_value_str, "TRUE") ||
            str_equal_text(p_value_str, "1"))
        {
          *(p_bool_setting->p_variable) = 1;
        }
        else if (str_equal_text(p_value_str, "NO") ||
                 str_equal_text(p_value_str, "FALSE") ||
                 str_equal_text(p_value_str, "0"))
        {
          *(p_bool_setting->p_variable) = 0;
        }
        else
        {
          die("bad bool value in config file");
        }
        return;
      }
      p_bool_setting++;
    }
  }
  /* Is it an unsigned integer setting? */
  {
    const struct parseconf_uint_setting* p_uint_setting = parseconf_uint_array;
    while (p_uint_setting->p_setting_name != 0)
    {
      if (str_equal_text(p_setting_str, p_uint_setting->p_setting_name))
      {
        /* Got it */
        /* If the value starts with 0, assume it's an octal value */
        if (!str_isempty(p_value_str) &&
            str_get_char_at(p_value_str, 0) == '0')
        {
          *(p_uint_setting->p_variable) = str_octal_to_uint(p_value_str);
        }
        else
        {
          *(p_uint_setting->p_variable) = str_atoi(p_value_str);
        }
        return;
      }
      p_uint_setting++;
    }
  }
  /* Is it a string setting? */
  {
    const struct parseconf_str_setting* p_str_setting = parseconf_str_array;
    while (p_str_setting->p_setting_name != 0)
    {
      if (str_equal_text(p_setting_str, p_str_setting->p_setting_name))
      {
        /* Got it */
        const char** p_curr_setting = p_str_setting->p_variable;
        if (*p_curr_setting)
        {
          vsf_sysutil_free((char*)*p_curr_setting);
        }
        *p_curr_setting = str_strdup(p_value_str);
        return;
      }
      p_str_setting++;
    }
  }
  die("unrecognised variable in config file");
}
short AQRInfo::setAQREntriesFromInputStr(char * inStr, Lng32 inStrLen)
{
  if ((! inStr) || (inStrLen <= 0))
    return -1;

  char * newStr = new(heap_) char[inStrLen + 1 + 1];
  str_cpy_all(newStr, inStr, inStrLen);
  newStr[inStrLen] = 0;
  Lng32 n = 0;

  Int32 i = 0;
  while (i < inStrLen)
    {
      if ((inStr[i] != '+') &&
	  (inStr[i] != '-') &&
	  (inStr[i] != '.') &&
	  (inStr[i] != ' ') &&
	  (inStr[i] != ',') &&
	  (inStr[i] != '|') &&
	  (NOT ((inStr[i] >= '0') &&
		(inStr[i] <= '9'))))
	return -1;

      if (inStr[i] != ' ')
	{
	  newStr[n] = inStr[i];
	  n++;
	}

      i++;
    }

  if (newStr[n-1] != '|')
    {
      newStr[n] = '|';
      n++;
    }
  newStr[n] = 0;

  i = 0;
  Int32 j = 0;
  Int32 k = 1;
  Lng32 sqlcode = -1;
  Lng32 nskcode = 0;
  Lng32 retries = 1;
  Lng32 delay = 60;
  Lng32 type = 0;
  Lng32 numCQDs = 0;
  char * cqdStr = NULL;
  Lng32 cmpInfo = 0;
  Lng32 intAQR = 0;
  Lng32 task = ComTdbExeUtilAQR::NONE_;
  NABoolean numberSeen = FALSE;
  while (i < n)
    {
      if ((newStr[i] >= '0') &&
	  (newStr[i] <= '9'))
	numberSeen = TRUE;

      if (newStr[i] == '+')
	{
	  if ((numberSeen) ||
	      (task != ComTdbExeUtilAQR::NONE_))
	    return -1;

	  task = ComTdbExeUtilAQR::ADD_;
	  j++;
	}
      else if (newStr[i] == '-')
	{
	  if ((numberSeen) ||
	      (task != ComTdbExeUtilAQR::NONE_))
	    return -1;

	  task = ComTdbExeUtilAQR::DELETE_;
	  j++;
	}
      else if (newStr[i] == '.')
	{
	  if ((numberSeen) ||
	      (task != ComTdbExeUtilAQR::NONE_))
	    return -1;

	  task = ComTdbExeUtilAQR::UPDATE_;
	  j++;
	}

      if ((newStr[i] == ',') ||
	  (newStr[i] == '|'))
	{
	  if (i > j)
	    {
	      Lng32 v = 0;
	      if ((k < 7) || (k == 8) || (k == 9))
		{
		  Int64 bigV = str_atoi(&newStr[j], i-j);
		  if (bigV == -1)
		    return -1;
		  
		  if (bigV > INT_MAX)
		    return -1;

		  v = (Lng32)bigV;
		}

	      switch (k)
		{
		case 1:
		  sqlcode = v;
		  break;
		  
		case 2:
		  nskcode = v;
		  break;
		  
		case 3:
		  retries = v;
		  break;
		  
		case 4:
		  delay = v;
		  break;
		  
		case 5:
		  type = v;
		  break;

		case 6:
		  numCQDs = v;
		  break;

		case 7:
		  cqdStr = new(heap_) char[i-j+1];
		  str_cpy_all(cqdStr, &newStr[j], i-j);
		  cqdStr[i-j] = 0;
		  break;
		  
		case 8:
		  cmpInfo = v;
		  break;

		case 9:
		  intAQR = v;
		  break;

		} // switch
	    }

	  k++;

	  j = i + 1;
	}

      if (newStr[i] == '|')
	{
	  if (task == ComTdbExeUtilAQR::NONE_)
	    task = ComTdbExeUtilAQR::ADD_;

	  if (setAQREntry(task, sqlcode, nskcode, retries, delay, type,
			  numCQDs, cqdStr, cmpInfo, intAQR))
	    return -1;

	  sqlcode = -1;
	  nskcode = 0;
	  retries = 1;
	  delay = 60;
	  type = 0;
	  numCQDs = 0;
	  cqdStr = NULL;
	  cmpInfo = 0;
	  intAQR = 0;

	  numberSeen = FALSE;
	  task = ComTdbExeUtilAQR::NONE_;

	  k = 1;
	  j = i+1;
	}
	
      i++;
    }

  return 0;
}
Example #23
0
void
vsf_parseconf_load_setting(const char* p_setting, int errs_fatal)
{
  static struct mystr s_setting_str;
  static struct mystr s_value_str;
  while (vsf_sysutil_isspace(*p_setting))
  {
    p_setting++;
  }
  str_alloc_text(&s_setting_str, p_setting);
  str_split_char(&s_setting_str, &s_value_str, '=');
  /* Is it a string setting? */
  {
    const struct parseconf_str_setting* p_str_setting = parseconf_str_array;
    while (p_str_setting->p_setting_name != 0)
    {
      if (str_equal_text(&s_setting_str, p_str_setting->p_setting_name))
      {
        /* Got it */
        const char** p_curr_setting = p_str_setting->p_variable;
        if (*p_curr_setting)
        {
          vsf_sysutil_free((char*) *p_curr_setting);
        }
        if (str_isempty(&s_value_str))
        {
          *p_curr_setting = 0;
        }
        else
        {
          *p_curr_setting = str_strdup(&s_value_str);
        }
        return;
      }
      p_str_setting++;
    }
  }
  if (str_isempty(&s_value_str))
  {
    if (errs_fatal)
    {
      die2("missing value in config file for: ", str_getbuf(&s_setting_str));
    }
    else
    {
      return;
    }
  }
  /* Is it a boolean value? */
  {
    const struct parseconf_bool_setting* p_bool_setting = parseconf_bool_array;
    while (p_bool_setting->p_setting_name != 0)
    {
      if (str_equal_text(&s_setting_str, p_bool_setting->p_setting_name))
      {
        /* Got it */
        str_upper(&s_value_str);
        if (str_equal_text(&s_value_str, "YES") ||
            str_equal_text(&s_value_str, "TRUE") ||
            str_equal_text(&s_value_str, "1"))
        {
          *(p_bool_setting->p_variable) = 1;
        }
        else if (str_equal_text(&s_value_str, "NO") ||
                 str_equal_text(&s_value_str, "FALSE") ||
                 str_equal_text(&s_value_str, "0"))
        {
          *(p_bool_setting->p_variable) = 0;
        }
        else if (errs_fatal)
        {
          die2("bad bool value in config file for: ",
               str_getbuf(&s_setting_str));
        }
        return;
      }
      p_bool_setting++;
    }
  }
  /* Is it an unsigned integer setting? */
  {
    const struct parseconf_uint_setting* p_uint_setting = parseconf_uint_array;
    while (p_uint_setting->p_setting_name != 0)
    {
      if (str_equal_text(&s_setting_str, p_uint_setting->p_setting_name))
      {
        /* Got it */
        /* If the value starts with 0, assume it's an octal value */
        if (!str_isempty(&s_value_str) &&
            str_get_char_at(&s_value_str, 0) == '0')
        {
          *(p_uint_setting->p_variable) = str_octal_to_uint(&s_value_str);
        }
        else
        {
          /* TODO: we could reject negatives instead of converting them? */
          *(p_uint_setting->p_variable) = (unsigned int) str_atoi(&s_value_str);
        }
        return;
      }
      p_uint_setting++;
    }
  }
  if (errs_fatal)
  {
    die2("unrecognised variable in config file: ", str_getbuf(&s_setting_str));
  }
}
// Extracts values from the string format of LOB handle 
Lng32 ExpLOBoper::extractFromLOBstring(Int64 &uid, 
				       Lng32 &lobNum,
				       Int64 &descPartnKey,
				       Int64 &descSyskey,
				       Int16 &flags,
				       Lng32 &lobType,
				       short &schNameLen,
				       char * schName,
				       char * handle,
				       Lng32 handleLen)
{
  // opp of:
  ////  // str_sprintf(lobHandleBuf, "LOBH%04d%020Ld%04d%02d%Ld%02d%Ld%03d%s",

  //  str_sprintf(lobHandleBuf, "LOBH%04d%02d%04d%020d%02d%Ld%02d%Ld%03d%s",
  //		  header, flags, lobtype, lobNum, uid, descPartnKey, descSyskey, schNameLen/SchName


  if (handleLen < (4 + 4 + 2 + 4 + 20 + 2))
    return -1;

  Lng32 curPos = 4;
  
  flags = (Lng32)str_atoi(&handle[curPos], 4);
  curPos += 4;

  lobType = (Lng32)str_atoi(&handle[curPos], 2);
  curPos += 2;

  lobNum = (Lng32)str_atoi(&handle[curPos], 4);
  curPos += 4;

  uid = str_atoi(&handle[curPos], 20);
  curPos += 20;

  short len1;
  len1 = (short)str_atoi(&handle[curPos], 2);
  curPos += 2;

  if (handleLen < (curPos + len1 + 2))
    return -1;

  descPartnKey = str_atoi(&handle[curPos], len1);
  curPos += len1;

  short len2;
  len2 = (short)str_atoi(&handle[curPos], 2);
  curPos += 2;

  if (handleLen < (curPos + len2 + 3))
    return -1;
  descSyskey = str_atoi(&handle[curPos], len2);
  curPos += len2;

  schNameLen = (short)str_atoi(&handle[curPos], 3);
  curPos += 3;
  if (handleLen < (curPos + schNameLen))
    return -1;
  
  str_cpy_and_null(schName, &handle[curPos], 
		   schNameLen, '\0', ' ', TRUE);

  //  flags = 0;

  return 0;
}
Example #25
0
SQScratchFile::SQScratchFile(char* path, ScratchSpace *scratchSpace,
            SortError* sorterror, 
            CollHeap* heap, NABoolean breakEnabled,
            Int32 scratchMaxOpens,
            NABoolean asynchReadQueue) :  
  ScratchFile(scratchSpace,
              SCRATCH_FILE_SIZE,
              sorterror,
              heap,
              scratchMaxOpens,
              breakEnabled), 
  vectorSize_(scratchSpace->getScratchIOVectorSize()),
  vector_(NULL)
{
  Int32 error = 0;
  resultFileSize_ = SCRATCH_FILE_SIZE; 
  asynchReadQueue_ = asynchReadQueue;
//------------------------------------------------------------------------
// if the path is a directory and fileSize is bigger than zero, then
// get the name of the temp file and add the FILE_DELETE_ONCLOSE flag.
// Else just copy it in.
//------------------------------------------------------------------------
  if (checkDirectory(path) != SORT_SUCCESS)  
  {

    if (mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))
    {
        if (checkDirectory(path) == 0)
        {
   // some other process probably created the TdmTmp directory
   // in the meantime so the directory exists.. proceed
   
        }
        else
        {
           error = obtainError();
           sortError_->setErrorInfo( ECreateDir        //sort error
                  ,(short)error      //syserr: the actual FS error
                   ,NULL              //syserrdetail
                   ,"SQScratchFile::SQScratchFile1" //methodname
                   );
            return;
        }
    }
  }

  //Inform overflow mode to STFS layer indicating that overflow
  //file be created on SSD or HDD or MMAP media.
  //Error 0 is success, 1 is unknown overflow type
  //error 2 is specified overflow type not configured.
  switch(scratchSpace_->getScratchOverflowMode())
  {
    case SCRATCH_SSD: 
	  error = STFS_set_overflow(STFS_SSD);
      break;
    
    default:
	case SCRATCH_MMAP:
    case SCRATCH_DISK:
      error = STFS_set_overflow(STFS_HDD);
      break;
  }

  //Error 0 is success, 1 is unknown overflow type
  //error 2 is specified overflow type not configured.
  if(error)
  {
    Int32 errorType = EUnexpectErr;
    switch(error)
    {
      case 1: errorType = EUnKnownOvType;
        break;
      case 2: errorType = EOvTypeNotConfigured;
        break;
      default:errorType = EUnexpectErr;
    }
    sortError_->setErrorInfo( errorType //sort error
                              ,0        //syserr: the actual FS error
                              ,0        //syserrdetail
                              ,"SQScratchFile::SQScratchFile2" //methodname
                              );
    return;
  }

  // XXXXXX is required by mkstemp
  str_sprintf(fileName_, "%s/SCRXXXXXX", path);

  if ((scratchSpace_->getScratchOverflowMode() == SCRATCH_DISK) ||
	 (scratchSpace_->getScratchOverflowMode() == SCRATCH_MMAP))
    {
      fileHandle_[0].fileNum = STFS_mkstemp_instnum(fileName_,scratchSpace_->getEspInstance());
    }
  else
    fileHandle_[0].fileNum = STFS_mkstemp(fileName_);
  if (fileHandle_[0].fileNum == STFS_NULL_FHNDL)
  {
      // mkstemp failed.
      sortError_->setErrorInfo( EUnexpectErr        //sort error
                ,(short)errno      //syserr: the actual FS error
                ,0              //syserrdetail
                ,"SQScratchFile::SQScratchFile 3" //methodname
                );
      return;
  }
  fileNameLen_ = str_len(fileName_);

  if(scratchSpace_->getScratchOverflowMode() != SCRATCH_MMAP)
  {
	  // change to non-blocking I/O
	  Int32 flags = STFS_fcntl(fileHandle_[0].fileNum, F_GETFL);

	  //other flags
	  flags |= O_APPEND;
	  flags |= O_NONBLOCK;
	  flags |= O_NOATIME;

	  //O_DIRECT is ON by default. User has to explicitly define 
	  //SCRATCH_NO_ODIRECT to disable O_DIRECT. Note that this 
	  //flag has significant performance implications.
	  if (!getenv("SCRATCH_NO_ODIRECT"))
		flags |= O_DIRECT;

	  error = STFS_fcntl(fileHandle_[0].fileNum, F_SETFL, flags);

	  if (error)
	  {
		  STFS_close(fileHandle_[0].fileNum);
		  fileHandle_[0].fileNum = STFS_NULL_FHNDL;
		  sortError_->setErrorInfo( EUnexpectErr        //sort error
							,(short)error     //syserr: the actual FS error                        
							,0              //syserrdetail
							,"SQScratchFile::SQScratchFile 4" //methodname
						   );
						return;
	  }    

  } 
 
  if(scratchSpace_->getScratchOverflowMode() == SCRATCH_MMAP)
  {
    off_t ret = STFS_lseek(fileHandle_[0].fileNum, resultFileSize_ -1 , SEEK_SET);
    if (ret < 0)
    {
      STFS_close(fileHandle_[0].fileNum);
      fileHandle_[0].fileNum = STFS_NULL_FHNDL;
      sortError_->setErrorInfo( EUnexpectErr        //sort error
                      ,(short)errno     //syserr: the actual FS error

                      ,0              //syserrdetail
                      ,"SQScratchFile::SQScratchFile(5)" //methodname
                     );
                  return;
    }
    error = write(fileHandle_[0].fileNum, "1", 1);
    if (error < 0)
    {
      STFS_close(fileHandle_[0].fileNum);
      fileHandle_[0].fileNum = STFS_NULL_FHNDL;
      sortError_->setErrorInfo( EUnexpectErr        //sort error
                  ,(short)errno     //syserr: the actual FS error

                  ,0              //syserrdetail
                  ,"SQScratchFile::SQScratchFile(6)" //methodname
                 );
              return;
    }
    fileHandle_[0].mmap = (char*) 
           mmap(0, resultFileSize_, PROT_READ | PROT_WRITE, MAP_SHARED,
           fileHandle_[0].fileNum, 0);

    if(fileHandle_[0].mmap == MAP_FAILED) 
    {
      STFS_close(fileHandle_[0].fileNum);
      fileHandle_[0].fileNum = STFS_NULL_FHNDL;
      sortError_->setErrorInfo( EUnexpectErr        //sort error
                  ,(short)errno     //syserr: the actual FS error

                  ,0              //syserrdetail
                  ,"SQScratchFile::SQScratchFile(7)" //methodname
                 );
              return;
    }
    
  } 
 //Memory allocation failure will result in long jump.
  reset();
  if(vectorSize_ > 0)
  {
    vector_ = (struct iovec *)((NAHeap *)heap_)->allocateAlignedHeapMemory(sizeof(struct iovec) * vectorSize_, 512);
  }
  
  vectorWriteMax_ = 0;
  vectorReadMax_ = 0;
  writemmapCursor_ = 0;
  readmmapCursor_ = 0;

  //Initialize other members of the fileHandle structure.
  fileHandle_[0].IOBuffer = NULL;
  fileHandle_[0].bufferLen = 0;
  fileHandle_[0].blockNum = -1;
  fileHandle_[0].IOPending = FALSE;
  fileHandle_[0].scratchFileConn = NULL;
  fileHandle_[0].associatedAsyncIOBuffer = NULL;
  fileHandle_[0].previousError = SCRATCH_SUCCESS;

#ifdef _DEBUG
    // Regression testing support for simulating IO Pending state.
  	envIOPending_ = getenv("SCRATCH_IO_PENDING");
  	if(envIOPending_)
  		envIOBlockCount_ = (Int32) str_atoi(envIOPending_, str_len(envIOPending_));
  	else
  		envIOBlockCount_ = -1;
#endif
}
Example #26
0
string read_roster_players(string roster_filename, RosterPlayerArray& players_arr)
{
    ifstream rosterfile(roster_filename.c_str());

    if (!rosterfile)
        return format_str("Failed to open roster %s", roster_filename.c_str());

    string line;

    // two dummy reads, to read in the header
    //
    getline(rosterfile, line);
    getline(rosterfile, line);

    // read all players from the roster
    //
    for (int line_num = 3;; ++line_num)
    {
        if (!getline(rosterfile, line))
            break;

        vector<string> columns = tokenize(line);

        // Empty lines are skipped
        //
        if (columns.size() == 0)
            continue;

        // If a non-empty line contains an incorrect amount of columns, it's
        // an error
        //
        if (columns.size() != NUM_COLUMNS_IN_ROSTER)
            return format_str(	"In roster %s, line %d: has %d columns (must be %d)",
								roster_filename.c_str(), line_num, columns.size(), NUM_COLUMNS_IN_ROSTER);
		
		RosterPlayer player;

        // Populate the player's data
        // Not much error checking done, since rosters are all machine-generated, 
        // so str_atoi is used (0 is good enough for wrong numeric columns)
        //
		player.name 		= columns[0];
        player.age 			= str_atoi(columns[1]);
		player.nationality 	= columns[2];
		player.pref_side 	= columns[3];
        player.st 			= str_atoi(columns[4]);
        player.tk 			= str_atoi(columns[5]);
        player.ps 			= str_atoi(columns[6]);
        player.sh 			= str_atoi(columns[7]);
        player.stamina 		= str_atoi(columns[8]);
        player.ag 			= str_atoi(columns[9]);
        player.st_ab 		= str_atoi(columns[10]);
        player.tk_ab 		= str_atoi(columns[11]);
        player.ps_ab 		= str_atoi(columns[12]);
        player.sh_ab 		= str_atoi(columns[13]);
        player.games		= str_atoi(columns[14]);
        player.saves 		= str_atoi(columns[15]);
        player.tackles 		= str_atoi(columns[16]);
        player.keypasses 	= str_atoi(columns[17]);
        player.shots 		= str_atoi(columns[18]);
        player.goals 		= str_atoi(columns[19]);
        player.assists 		= str_atoi(columns[20]);
        player.dp 			= str_atoi(columns[21]);
        player.injury 		= str_atoi(columns[22]);
        player.suspension 	= str_atoi(columns[23]);
        player.fitness 		= str_atoi(columns[24]);
		
		players_arr.push_back(player);
    }

    return "";
}
Example #27
0
static void
handle_eprt(struct vsf_session* p_sess)
{
  static struct mystr s_part1_str;
  static struct mystr s_part2_str;
  int proto;
  int port;
  const unsigned char* p_raw_addr;
  int is_ipv6 = vsf_sysutil_sockaddr_is_ipv6(p_sess->p_local_addr);
  port_cleanup(p_sess);
  pasv_cleanup(p_sess);
  str_copy(&s_part1_str, &p_sess->ftp_arg_str);
  str_split_char(&s_part1_str, &s_part2_str, '|');
  if (!str_isempty(&s_part1_str))
  {
    goto bad_eprt;
  }
  /* Split out the protocol and check it */
  str_split_char(&s_part2_str, &s_part1_str, '|');
  proto = str_atoi(&s_part2_str);
  if (!is_ipv6 || proto != 2)
  {
    vsf_cmdio_write(p_sess, FTP_BADCMD, "Bad EPRT protocol.");
    return;
  }
  /* Split out address and parse it */
  str_split_char(&s_part1_str, &s_part2_str, '|');
  p_raw_addr = vsf_sysutil_parse_ipv6(&s_part1_str);
  if (!p_raw_addr)
  {
    goto bad_eprt;
  }
  /* Split out port and parse it */
  str_split_char(&s_part2_str, &s_part1_str, '|');
  if (!str_isempty(&s_part1_str) || str_isempty(&s_part2_str))
  {
    goto bad_eprt;
  }
  port = str_atoi(&s_part2_str);
  if (port < 0 || port > 65535)
  {
    goto bad_eprt;
  }
  vsf_sysutil_sockaddr_alloc_ipv6(&p_sess->p_port_sockaddr);
  vsf_sysutil_sockaddr_set_ipv6addr(p_sess->p_port_sockaddr, p_raw_addr);
  vsf_sysutil_sockaddr_set_port(p_sess->p_port_sockaddr, (unsigned short)port);
  /* SECURITY:
   * 1) Reject requests not connecting to the control socket IP
   * 2) Reject connects to privileged ports
   */
  if (!tunable_port_promiscuous)
  {
    if (!vsf_sysutil_sockaddr_addr_equal(p_sess->p_remote_addr,
                                         p_sess->p_port_sockaddr) ||
        vsf_sysutil_is_port_reserved(port))
    {
      vsf_cmdio_write(p_sess, FTP_BADCMD, "Illegal EPRT command.");
      port_cleanup(p_sess);
      return;
    }
  }
  vsf_cmdio_write(p_sess, FTP_EPRTOK,
                  "EPRT command successful. Consider using EPSV.");
  return;
bad_eprt:
  vsf_cmdio_write(p_sess, FTP_BADCMD, "Bad EPRT command.");
}
Lng32 ComSqlId::getSqlIdAttr
(Lng32 attr,          // which attr (SqlQueryIDAttr)
 char * queryId,     // query ID
 Lng32 queryIdLen,    // query ID len
 Int64 &value,       // If returned attr is numeric, 
                     //    this field contains the returned value.
                     // If attr is of string type, this value is:
                     //   on input,the max length of the buffer pointed to by stringValue
                     //   on output, the actual length of the string attribute
 char * stringValue) // null terminated string returned here
{
  Lng32 retcode = 0;
  
  Int64 version = str_atoi(&queryId[VERSION_OFFSET], VERSION_LEN);

  switch (attr)
    {
    case SQLQUERYID_VERSION:
      value = version;
      if (value < 0)
         return -CLI_INVALID_ATTR_VALUE;
      break;
    case SQLQUERYID_SEGMENTNUM:
      {
        // on SQ, the SEGMENT_NUM and CPUNUM is the same field - 3 digits
        if (version == NEO_SQL_ID_VERSION)
	  value = str_atoi(&queryId[SEGMENT_OFFSET], NEO_SEGMENT_LEN);
        else
	  value = str_atoi(&queryId[SEGMENT_OFFSET], SEGMENT_LEN);
	if (value < 0)
	  return -CLI_INVALID_ATTR_VALUE;
      }
    break;
    
    case SQLQUERYID_SEGMENTNAME:
      {
	// not implemented yet
        if(stringValue && value)
          stringValue[0] = 0;
      }
    break;

    case SQLQUERYID_CPUNUM:
      {
        // on SQ, the SEGMENT_NUM and CPUNUM is the same field - 3 digits
        if (version == NEO_SQL_ID_VERSION)
	  value = str_atoi(&queryId[NEO_CPU_OFFSET], NEO_CPU_LEN);
        else
	  value = str_atoi(&queryId[CPU_OFFSET], CPU_LEN);
	if (value < 0)
	  return -CLI_INVALID_ATTR_VALUE;
      }
    break;

    case SQLQUERYID_PIN:
      {
        if (version == NEO_SQL_ID_VERSION)
	   value = str_atoi(&queryId[NEO_PIN_OFFSET], NEO_PIN_LEN);
        else
	   value = str_atoi(&queryId[PIN_OFFSET], PIN_LEN);
	if (value < 0)
	  return -CLI_INVALID_ATTR_VALUE;
      }
    break;

    case SQLQUERYID_EXESTARTTIME:
      {
	value = str_atoi(&queryId[STARTTS_OFFSET], STARTTS_LEN);
	if (value < 0)
	  return -CLI_INVALID_ATTR_VALUE;
      }
    break;

    case SQLQUERYID_SESSIONNUM:
      {
	value = str_atoi(&queryId[SESSIONNUM_OFFSET], SESSIONNUM_LEN);
	if (value < 0)
	  return -CLI_INVALID_ATTR_VALUE;
      }
    break;

    case SQLQUERYID_USERNAME:
      {
	Lng32 userNameLen = 
	  (Lng32)str_atoi(&queryId[USERNAMELEN_OFFSET], USERNAMELEN_LEN);
	if (userNameLen < 0)
	  return -CLI_INVALID_ATTR_VALUE;
	if (stringValue && value > userNameLen)
	  {
            strncpy(stringValue, &queryId[USERNAME_OFFSET], userNameLen);
            stringValue[userNameLen] = 0;
	  }
        else
            retcode = -CLI_INVALID_ATTR_VALUE ;

        value = userNameLen;
      }
    break;

    case SQLQUERYID_SESSIONNAME:
      {
	Lng32 userNameLen = 
	  (Lng32)str_atoi(&queryId[USERNAMELEN_OFFSET], USERNAMELEN_LEN);
	if (userNameLen < 0)
	  return -CLI_INVALID_ATTR_VALUE;

	Lng32 sessionNameLenOffset =
	  USERNAMELEN_OFFSET + USERNAMELEN_LEN + userNameLen;
	Lng32 sessionNameLen = 
	  (Lng32)str_atoi(&queryId[sessionNameLenOffset], SESSIONNAMELEN_LEN);
	if (sessionNameLen < 0)
	  return -CLI_INVALID_ATTR_VALUE;
	if (stringValue && value > sessionNameLen )
	  {
	    strncpy(stringValue, 
		    &queryId[sessionNameLenOffset+SESSIONNAMELEN_LEN], 
		    sessionNameLen);

	    stringValue[sessionNameLen] = 0;
          }
        else
            retcode = -CLI_INVALID_ATTR_VALUE;
       
        value = sessionNameLen;
      }
    break;

    case SQLQUERYID_SESSIONID:
      {
        // session Id = qid from start thru SessionName
        
        // set current offset to userNameLen
        Int32 currOffset = USERNAMELEN_OFFSET;
        
        // get userNameLen
        Int32 nameLen = (Int32)str_atoi(&queryId[currOffset], USERNAMELEN_LEN);
        
        // go past Username
        currOffset += USERNAMELEN_LEN + nameLen;
        
        // get sessionName length
        nameLen = (Int32)str_atoi(&queryId[currOffset], SESSIONNAMELEN_LEN);
	if (nameLen < 0)
	  return -CLI_INVALID_ATTR_VALUE;
        
        // go past sessionName
        currOffset += SESSIONNAMELEN_LEN + nameLen; 
	
        // check value for length
        if(stringValue && value > currOffset)
        { 
          // copy sessionId to stringValue
          strncpy(stringValue, queryId, currOffset);
          stringValue[currOffset]=0;
        }
        else
            retcode = -CLI_INVALID_ATTR_VALUE;
         
        value = currOffset;
     }
    break;

    case SQLQUERYID_QUERYNUM:
      {
	Lng32 currOffset = USERNAMELEN_OFFSET;
	Lng32 nameLen = 
	  (Lng32)str_atoi(&queryId[currOffset], USERNAMELEN_LEN);
	if (nameLen < 0)
	  return -CLI_INVALID_ATTR_VALUE;

	// skip user name
	currOffset += USERNAMELEN_LEN + nameLen;

	// skip session name
	nameLen = 
	  (Lng32)str_atoi(&queryId[currOffset], SESSIONNAMELEN_LEN);
	if (nameLen < 0)
	  return -CLI_INVALID_ATTR_VALUE;
	currOffset += SESSIONNAMELEN_LEN + nameLen;

	if (currOffset >= queryIdLen)
	  return -CLI_INVALID_ATTR_VALUE;
	
	if (queryId[currOffset] != '_')
	  return -CLI_INVALID_ATTR_VALUE;

	// skip "_" separator
	currOffset += 1;

	// find the next occurance of "_"
	char * us = str_chr(&queryId[currOffset], '_');
	if (us == NULL)
	  return -CLI_INVALID_ATTR_VALUE;

	if ((currOffset + (us - (char *)(&queryId[currOffset]))) >= queryIdLen)
	  return -CLI_INVALID_ATTR_VALUE;

	value = str_atoi(&queryId[currOffset], 
			 us - (char *)(&queryId[currOffset]));
	if (value < 0)
	  return -CLI_INVALID_ATTR_VALUE;
      }
    break;

    case SQLQUERYID_STMTNAME:
      {
	Lng32 currOffset = USERNAMELEN_OFFSET;
	Lng32 nameLen = 
	  (Lng32)str_atoi(&queryId[currOffset], USERNAMELEN_LEN);
	if (nameLen < 0)
	  return -CLI_INVALID_ATTR_VALUE;

	// skip user name
	currOffset += USERNAMELEN_LEN + nameLen;

	// skip session name
	nameLen = 
	  (Lng32)str_atoi(&queryId[currOffset], SESSIONNAMELEN_LEN);
	if (nameLen < 0)
	  return -CLI_INVALID_ATTR_VALUE;
	currOffset += SESSIONNAMELEN_LEN + nameLen;
	
	if (currOffset >= queryIdLen)
	  return -CLI_INVALID_ATTR_VALUE;
	  
	if (queryId[currOffset] != '_')
	  return -CLI_INVALID_ATTR_VALUE;
	  
	// skip "_" separator
	currOffset += 1;

	// find the next occurance of "_"
	char * us = str_chr(&queryId[currOffset], '_');
	if (us == NULL)
	  return -CLI_INVALID_ATTR_VALUE;

	// skip queryNum
	currOffset += us - (char *)(&queryId[currOffset]);

	if (currOffset >= queryIdLen)
	  return -CLI_INVALID_ATTR_VALUE;

	// skip "_" separator
	currOffset += 1;
        
        //get statementName length as remaining string except trailing blanks
        while (queryIdLen && queryId[queryIdLen-1] == ' ')
          queryIdLen--;

        Int32 qidStatementNameLen = queryIdLen - currOffset;
        
        // check for enough space in StringValue
        if(stringValue && value > qidStatementNameLen )
        {        
	  // copy and null terminate 
          strncpy(stringValue, &queryId[currOffset], qidStatementNameLen);
          stringValue[qidStatementNameLen] = 0;
        }
        else
	  retcode = -CLI_INVALID_ATTR_VALUE;
        
        value = qidStatementNameLen;

      }
    break;

    default:
      {
        retcode = -CLI_INVALID_ATTR_NAME;
      } 

    }

  return retcode;
}
void EspNewIncomingConnectionStream::actOnReceive(IpcConnection *connection)
{
  // check for OS errors
  if (getState() == ERROR_STATE)
  {
    ex_assert(FALSE,"Error while receiving first message from client");
  }

  // check for protocol errors
  bool willPassTheAssertion = 
             (getType() == IPC_MSG_SQLESP_DATA_REQUEST OR
              getType() == IPC_MSG_SQLESP_CANCEL_REQUEST) AND
              getVersion() == CurrEspRequestMessageVersion AND
              moreObjects();
  if (!willPassTheAssertion)
  {
    char *doCatchBugCRx = getenv("ESP_BUGCATCHER_CR_NONUMBER");
    if (!doCatchBugCRx ||
        *doCatchBugCRx != '0')
    {
      connection->dumpAndStopOtherEnd(true, false);
      environment_->getControlConnection()->
        castToGuaReceiveControlConnection()->
        getConnection()->dumpAndStopOtherEnd(true, false);
    }
  }

  ex_assert((getType() == IPC_MSG_SQLESP_DATA_REQUEST OR
             getType() == IPC_MSG_SQLESP_CANCEL_REQUEST) AND
	    getVersion() == CurrEspRequestMessageVersion AND
	    moreObjects(),
	    "Invalid first message from client");

  // take a look at the type of the first object in the message
  IpcMessageObjType nextObjType = getNextObjType();
  switch (nextObjType)
  {
    case ESP_OPEN_HDR:
    case ESP_LATE_CANCEL_HDR:
      {
        ExFragKey key;
        Lng32 remoteInstNum;
        NABoolean isParallelExtract = false; 

        // peek at the message header to see for whom it is
        if (nextObjType == ESP_OPEN_HDR)
        {
          ExEspOpenReqHeader reqHdr((NAMemory *) NULL);
	   
	  *this >> reqHdr;
	  key = reqHdr.key_;
	  remoteInstNum = reqHdr.myInstanceNum_;
	  if (reqHdr.getOpenType() == ExEspOpenReqHeader::PARALLEL_EXTRACT) 
          {
            isParallelExtract = true;
	  }
	}
        else
	{
          // note that the late cancel request may or may not
	  // arrive as the first request (only in the former case
	  // will we reach here)
	  ExEspLateCancelReqHeader reqHdr((NAMemory *) NULL);
	   
	  *this >> reqHdr;
	  key = reqHdr.key_;
	  remoteInstNum = reqHdr.myInstanceNum_;
	}

        if (!isParallelExtract) 
        {
          ExFragInstanceHandle handle =
	    espFragInstanceDir_->findHandle(key);

	  if (handle != NullFragInstanceHandle)
	  {
            // the send bottom node # myInstanceNum of this downloaded fragment
            // is the true recipient of this open request
            ex_split_bottom_tcb * receivingTcb =
              espFragInstanceDir_->getTopTcb(handle);
            ex_send_bottom_tcb *receivingSendTcb =
              receivingTcb->getSendNode(remoteInstNum);

            // Check the connection for a co-located client, and if so,
            // tell the split bottom, because it may prefer this send 
            // bottom when using skew buster uniform distribution.
            if (espFragInstanceDir_->
                  getEnvironment()->
                  getMyOwnProcessId(IPC_DOM_GUA_PHANDLE).match(
                    connection->getOtherEnd().getNodeName(),
                    connection->getOtherEnd().getCpuNum()))
              receivingTcb->setLocalSendBottom(remoteInstNum);

            // Portability note for the code above: we pass IPC_DOM_GUA_PHANDLE
            // for IpcEnvironment::getMyOwnProcessId, even though that method
            // can be called with the default param (IpcNetworkDomain 
            // IPC_DOM_INVALID).  In fact it would  probably be better 
            // to call the object without specifying the IpcNetworkDomain so
            // that it can decide for itself what domain it is using.
            // But there is a problem with the Windows implementation
            // of IpcEnvironment::getMyOwnProcessId, it seems to assume
            // that its domain is IPC_DOM_INTERNET and so this will 
            // cause the botch of an assertion that its control connection 
            // (which is type EspGuaControlConnection) can be cast to a 
            // SockControlConnection.  When this problem is fixed, the 
            // IPC_DOM_GUA_PHANDLE param above can be removed.  Also,
            // when this code is ported to run it a domain other than
            // "guardian", it will be necessary to fix this and to
            // fix IpcEnvironment::getMyOwnProcessId to work properly on
            // windows.

            receivingSendTcb->setClient(connection);
            receivingSendTcb->routeMsg(*this);
          }
	  else
	  {
            connection->dumpAndStopOtherEnd(true, false);
	    ex_assert(FALSE,"entry not found, set diagnostics area and reply");
	  }

        } // normal case, not parallel extract

        else 
        {
          // The OPEN request is from a parallel extract consumer. The
          // incoming request contains a user ID which we will compare
          // against the current user ID for this ESP.

          // NOTE: The user ID for the extract security check is
          // currently sent and compared as a C string. On Linux it is
          // possible to send and compare integers which would lead to
          // simpler code. The code to send/compare strings is still
          // used because it works on all platforms.

          char errorStr[150];

	  // check if next msg is of securityInfo type. 
          ex_assert(moreObjects(), "expected object not received");
          ex_assert(getNextObjType() == ESP_SECURITY_INFO,
	            "received message for unknown message type");
          
	  // unpack security info
	  ExMsgSecurityInfo secInfo(environment_->getHeap());
	  *this >> secInfo;

          // Get the auth ID of this ESP in text form and compare it
          // to the auth ID that arrived in the message. Skip this
          // step in the debug build if an environment variable is
          // set.
          NABoolean doAuthIdCheck = TRUE;
          Int32 status = 0;
#ifdef _DEBUG
          const char *envvar = getenv("NO_EXTRACT_AUTHID_CHECK");
          if (envvar && envvar[0])
            doAuthIdCheck = FALSE;
#endif
          if (doAuthIdCheck)
          {
            // Get user ID from ExMsgSecurityInfo -> (secUserID)
            // the user ID is the integer value made into a string
            // Convert it back into its integer value
            short userIDLen = (short) str_len(secInfo.getAuthID());
            Int32 secUserID = str_atoi(secInfo.getAuthID(), userIDLen);

            // Get the current user ID
            Int32 curUserID = ComUser::getSessionUser(); 

            // Report an error if the user ID is not valid
            if (curUserID == NA_UserIdDefault || secUserID == NA_UserIdDefault)
            {
              str_cpy_c(errorStr,
                        "Producer ESP could not authenticate the consumer, "
                        "no valid current user.");
              status = -1;
            }

            // Make sure user id passed in ExMsgSecurityInfo matches
            // the user id associated with the current session

#if defined(_DEBUG)
            NABoolean doDebug = (getenv("DBUSER_DEBUG") ? TRUE : FALSE);
            if (doDebug)
              printf("[DBUSER:%d] ESP extract user ID: "
                     "local [%d], msg [%d]\n",
                     (int) getpid(), curUserID, secUserID);
#endif

              // Compare user ID, Report an error, if comparison fails
              if (curUserID != secUserID)
              {
                str_cpy_c(errorStr,
                          "Producer ESP could not authenticate the consumer, "
                          "user named passed in ExMsgSecurityInfo is not the "
                          "current user");
                status = -1;
              }

          } // if (doAuthIdCheck)
		   
          // get the split bottom TCB that matches the securityKey
          ex_split_bottom_tcb *receivingTcb = NULL;
          if (status == 0) 
          {
            receivingTcb = espFragInstanceDir_->getExtractTop(secInfo.getSecurityKey());
            if (receivingTcb == NULL) 
            {
              str_cpy_c(errorStr, "Producer ESP could not locate extract node");
              status = -1;
            }
          }

	  // get the sendBottom TCB if not already connected to a client
	  ex_send_bottom_tcb *receivingSendTcb = NULL;
	  if (status == 0)
	  {
	    receivingSendTcb = receivingTcb->getConsumerSendBottom();
	    if (receivingSendTcb == NULL) 
	    {
	      str_cpy_c(errorStr, "Producer ESP already connected to a client");
	      status = -1;
	    }
	  }

          // send the error message to the consumer 
	  if (status != 0) 
	  {
            clearAllObjects();
            setType(IPC_MSG_SQLESP_DATA_REPLY);

            NAMemory *heap = environment_->getHeap();

	    IpcMessageObj* baseObj =
	      new(heap)IpcMessageObj(IPC_SQL_DIAG_AREA, CurrEspReplyMessageVersion);
	    *this << *baseObj;

	    // prepare proper error message
	    char phandle[100];
	    MyGuaProcessHandle myHandle;
            myHandle.toAscii(phandle, 100);

	    ComDiagsArea *diags = ComDiagsArea::allocate(heap);
            *diags << DgSqlCode(-EXE_PARALLEL_EXTRACT_OPEN_ERROR)
                   << DgString0(phandle)
                   << DgString1(errorStr);
	    *this  << *diags;

	    diags->decrRefCount();

            send(TRUE /* TRUE indicates waited */);
          }

          // if everything okay, then make the connection
	  if (status == 0) 
          {
            receivingSendTcb->setClient(connection);
            receivingSendTcb->routeMsg(*this);
          }
        } // parallel extract case
      } // open or cancel header
void runServer(Int32 argc, char **argv)
{
  Int32 shmid;
  jmp_buf sscpJmpBuf;
  StatsGlobals *statsGlobals = NULL;
  void *statsGlobalsAddr;
  NABoolean createStatsGlobals = FALSE;
  CliGlobals *cliGlobals = CliGlobals::createCliGlobals(FALSE);
  char tmbuf[64];
  time_t now;
  struct tm *nowtm;

  long maxSegSize = STATS_MAX_SEG_SIZE;
  char *envSegSize = getenv("MX_RTS_STATS_SEG_SIZE");
  if (envSegSize)
  {
    maxSegSize = (long) str_atoi(envSegSize, str_len(envSegSize));
    if (maxSegSize < 32)
      maxSegSize = 32;
    else if (maxSegSize > 256)
      maxSegSize = 256;
    maxSegSize *= 1024 * 1024;
  }
  long enableHugePages = 0;
  int shmFlag = RMS_SHMFLAGS;
  char *envShmHugePages = getenv("SQ_RMS_ENABLE_HUGEPAGES");
  if (envShmHugePages != NULL)
  {
     enableHugePages = (long) str_atoi(envShmHugePages,
                         str_len(envShmHugePages));
     if (enableHugePages > 0)
       shmFlag =  shmFlag | SHM_HUGETLB;
  }

  now = time(NULL);
  nowtm = localtime(&now);
  strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S ", nowtm);

  if ((shmid = shmget((key_t)getStatsSegmentId(),
                         0,  // size doesn't matter unless we are creating.
                         shmFlag)) == -1)
  {
    if (errno == ENOENT)
    {
      // Normal case, segment does not exist yet. Try to create.
      bool didCreate = true;
      if ((shmid = shmget((key_t)getStatsSegmentId(),
                                maxSegSize,
                                shmFlag | IPC_CREAT)) == -1)
      {
        if (enableHugePages > 0)
        {
          enableHugePages = 0;
          // try again withouf hugepages
          shmFlag =  shmFlag & ~SHM_HUGETLB;
          if ((shmid = shmget((key_t)getStatsSegmentId(),
                                    maxSegSize,
                                    shmFlag | IPC_CREAT)) == -1)
            didCreate = false;
        }
        else 
          didCreate = false;
      }

      if (didCreate)
      {
        cout << tmbuf 
             << " RMS Shared segment id = " 
             << shmid << ", key = " 
             << (key_t)getStatsSegmentId() ;
        if (enableHugePages > 0)
          cout << ", created with huge pages support." << endl;
        else
          cout << ", created without huge pages support." << endl;

        createStatsGlobals = TRUE;
      }
      else
      {
        cout << tmbuf
             << " Shmget failed, key = "
             << getStatsSegmentId()
             <<", Error code: "
             << errno
             << " ("
             << strerror(errno)
             << ")" << endl;
        exit(errno);
      }
    } // if ENOENT (i.e., attempting creation.)
  }
  else
  {
     cout << tmbuf << " RMS Shared segment exists, attaching to it, shmid="<< shmid << ", key=" << (key_t)getStatsSegmentId() << "\n";
  }
  if ((statsGlobalsAddr = shmat(shmid, getRmsSharedMemoryAddr(), 0))
		== (void *)-1)
  {
    cout << tmbuf << "Shmat failed, shmid=" <<shmid << ", key=" << (key_t) getStatsSegmentId() << ", Error code : "  << errno << "(" << strerror(errno) << ")\n";
    exit(errno);
  }
  char *statsGlobalsStartAddr = (char *)statsGlobalsAddr;
  if (createStatsGlobals)
  {
     short envType = StatsGlobals::RTS_GLOBAL_ENV;
     statsGlobals = new (statsGlobalsStartAddr)
             StatsGlobals((void *)statsGlobalsAddr, envType, maxSegSize);
     cliGlobals->setSharedMemId(shmid);
     // We really should not squirrel the statsGlobals pointer away like
     // this until the StatsGloblas is initialized, but
     // statsGlobals->init() needs it ......
     cliGlobals->setStatsGlobals(statsGlobals);
     statsGlobals->init();
  }
  else
  {
    statsGlobals = (StatsGlobals *)statsGlobalsAddr;
    cliGlobals->setSharedMemId(shmid);
    cliGlobals->setStatsGlobals(statsGlobals);
  }
  XPROCESSHANDLE_GETMINE_(statsGlobals->getSscpProcHandle());
  NAHeap *sscpHeap = cliGlobals->getExecutorMemory();
  cliGlobals->setJmpBufPtr(&sscpJmpBuf);
  if (setjmp(sscpJmpBuf))
    NAExit(1); // Abend
  IpcEnvironment  *sscpIpcEnv = new (sscpHeap) IpcEnvironment(sscpHeap, cliGlobals->getEventConsumed(),
      FALSE, IPC_SQLSSCP_SERVER, FALSE, TRUE);

  SscpGlobals *sscpGlobals = NULL;

  sscpGlobals = new (sscpHeap) SscpGlobals(sscpHeap, statsGlobals);

  // Currently open $RECEIVE with 256
  SscpGuaReceiveControlConnection *cc =
	 new(sscpHeap) SscpGuaReceiveControlConnection(sscpIpcEnv,
					  sscpGlobals,
                                           256);
  sscpIpcEnv->setControlConnection(cc);
  while (TRUE)
  {
     while (cc->getConnection() == NULL)
      cc->wait(IpcInfiniteTimeout);

#ifdef _DEBUG_RTS
    cerr << "No. of Requesters-1 "  << cc->getNumRequestors() << " \n";
#endif
    while (cc->getNumRequestors() > 0)
    {
      sscpIpcEnv->getAllConnections()->waitOnAll(IpcInfiniteTimeout);
    } // Inner while
  }
}  // runServer