Example #1
0
extern "C" int dup2(int oldfd, int newfd)
{
  DMTCP_DISABLE_CKPT();
  int res = _real_dup2(oldfd, newfd);
  if (res != -1 && newfd != oldfd && dmtcp_is_running_state()) {
    process_fd_event(SYS_dup, oldfd, newfd);
  }
  DMTCP_ENABLE_CKPT();
  return newfd;
}
void dmtcp::ConnectionRewirer::onConnect ( const jalib::JSocket& sock,  const struct sockaddr* /*remoteAddr*/,socklen_t /*remoteLen*/ )
{
  jalib::JSocket remote = sock;
  DmtcpMessage msg;
  msg.poison();
  remote >> msg;
  msg.assertValid();
  JASSERT ( msg.type == DMT_RESTORE_RECONNECTED ) ( msg.type ).Text ( "unexpected message" );

  iterator i = _pendingIncoming.find ( msg.restorePid );

  JASSERT ( i != _pendingIncoming.end() ) ( msg.restorePid )
  .Text ( "got unexpected incoming restore request" );

  const dmtcp::vector<int>& fds = i->second;
  JASSERT ( fds.size() > 0 );
  int fd0 = fds[0];

  remote.changeFd ( fd0 );

  JTRACE ( "restoring incoming connection" ) ( msg.restorePid ) ( fd0 ) ( fds.size() );

  for ( size_t i = 1; i<fds.size(); ++i )
  {
    JTRACE ( "restoring extra fd" ) ( fd0 ) ( fds[i] );
    JASSERT ( _real_dup2 ( fd0,fds[i] ) == fds[i] ) ( fd0 ) ( fds[i] ) ( msg.restorePid )
    .Text ( "dup2() failed" );
  }

  _pendingIncoming.erase ( i );


  if ( pendingCount() ==0 ) finishup();
#ifdef DEBUG
  else debugPrint();
#endif
}
Example #3
0
void initLogsForRecordReplay()
{
    if (isProcessGDB()) {
        return;
    }
    global_log.initialize(RECORD_LOG_PATH, MAX_LOG_LENGTH);

    if (read_data_fd == -1) {
        int fd;
        JASSERT(SYNC_IS_RECORD || SYNC_IS_REPLAY);
        if (SYNC_IS_RECORD) {
            fd = _real_open(RECORD_READ_DATA_LOG_PATH,
                            O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
        } else if (SYNC_IS_REPLAY) {
            fd = _real_open(RECORD_READ_DATA_LOG_PATH, O_RDONLY, 0);
        } else {
            JASSERT(false) .Text("Not Reached");
        }
        JASSERT(fd != -1);
        read_data_fd = _real_dup2(fd, dmtcp_get_readlog_fd());
        JASSERT(read_data_fd != -1);
        _real_close(fd);
    }
}
void dmtcp::ConnectionRewirer::onData ( jalib::JReaderInterface* sock )
{
  JASSERT ( sock->bytesRead() == sizeof ( DmtcpMessage ) ) ( sock->bytesRead() ) ( sizeof ( DmtcpMessage ) );
  DmtcpMessage& msg = * ( DmtcpMessage* ) sock->buffer();
  msg.assertValid();

  if ( msg.type == DMT_FORCE_RESTART )
  {
    JTRACE ( "got DMT_FORCE_RESTART, exiting ConnectionRewirer" ) ( _pendingOutgoing.size() ) ( _pendingIncoming.size() );
    _pendingIncoming.clear();
    _pendingOutgoing.clear();
    finishup();
    return;
  }

  JASSERT ( msg.type==DMT_RESTORE_WAITING ) ( msg.type ).Text ( "unexpected message" );

  // Find returns iterator 'i' w/ 0 or more elts, with first elt matching key.
  iterator i = _pendingOutgoing.find ( msg.restorePid );

  if ( i == _pendingOutgoing.end() )
  {
    // 'i' is an iterator over 0 elements.
    JTRACE ( "got RESTORE_WAITING MESSAGE [not used]" ) ( msg.restorePid ) ( _pendingOutgoing.size() ) ( _pendingIncoming.size() );
  }
  else
  {
    // 'i' is an iterator over 1 element.
    JTRACE ( "got RESTORE_WAITING MESSAGE, reconnecting..." )
    ( msg.restorePid ) ( msg.restorePort ) ( msg.restoreAddrlen ) ( _pendingOutgoing.size() ) ( _pendingIncoming.size() );
    const dmtcp::vector<int>& fds = i->second;
    JASSERT ( fds.size() > 0 );
    int fd0 = fds[0];

    jalib::JSocket remote = jalib::JSocket::Create();
    remote.changeFd ( fd0 );
    errno = 0;
    JASSERT ( remote.connect ( ( sockaddr* ) &msg.restoreAddr,msg.restoreAddrlen,msg.restorePort ) )
    ( msg.restorePid ) ( msg.restorePort ) ( JASSERT_ERRNO )
    .Text ( "failed to restore connection" );

    {
      DmtcpMessage peerMsg;
      peerMsg.type = DMT_RESTORE_RECONNECTED;
      peerMsg.restorePid = msg.restorePid;
      addWrite ( new jalib::JChunkWriter ( remote, ( char* ) &peerMsg,sizeof ( peerMsg ) ) );
    }

    for ( size_t n = 1; n<fds.size(); ++n )
    {
      JTRACE ( "restoring extra fd" ) ( fd0 ) ( fds[n] );
      JASSERT ( _real_dup2 ( fd0,fds[n] ) == fds[n] ) ( fd0 ) ( fds[n] ) ( msg.restorePid )
      .Text ( "dup2() failed" );
    }
    _pendingOutgoing.erase ( i );
  }

  if ( pendingCount() ==0 ) finishup();
#ifdef DEBUG
  else debugPrint();
#endif
}