예제 #1
0
파일: send.c 프로젝트: kitech/gearmand
ssize_t send(int sockfd, const void *buf, size_t len, int flags)
{

  hostile_initialize();

  (void) pthread_once(&function_lookup_once, set_local);

  if (is_called() == false)
  {
    if (__function.frequency)
    {
      if (--not_until < 0 && random() % __function.frequency)
      {
        __function._used++;
        shutdown(sockfd, SHUT_RDWR);
        close(sockfd);
        errno= ECONNRESET;
        return -1;
      }
    }
  }

  set_called();
  ssize_t ret= __function.function.send(sockfd, buf, len, flags);
  reset_called();

  return ret;
}
예제 #2
0
int getaddrinfo(const char *node, const char *service,
                const struct addrinfo *hints,
                struct addrinfo **res)
{
  hostile_initialize();

  (void) pthread_once(&function_lookup_once, set_local);

  if (is_called() == false)
  {
    if (__function.frequency)
    {
      if (--not_until < 0 && random() % __function.frequency)
      {
#if 0
        perror("HOSTILE CLOSE() of socket during getaddrinfo()");
#endif
        return EAI_FAIL;
      }
    }
  }

  set_called();
  int ret= __function.function.getaddrinfo(node, service, hints, res);
  reset_called();

  return ret;
}
예제 #3
0
파일: pipe.c 프로젝트: kitech/gearmand
int pipe2(int pipefd[2], int flags)
{
  hostile_initialize();

  (void) pthread_once(&function_lookup_once, set_local);

  set_called();
  int ret= __function.function.pipe2(pipefd, flags);
  reset_called();

  return ret;
}
예제 #4
0
파일: poll.c 프로젝트: FataliBud/gearmand
int poll(struct pollfd *fds, nfds_t nfds, int timeout)
{

  hostile_initialize();

  (void) pthread_once(&function_lookup_once, set_local);

  if (is_called() == false)
  {
    if (__function.frequency)
    {
      if (--not_until < 0 && random() % __function.frequency)
      {
        for (nfds_t x= 0; x < nfds; nfds++)
        {
          switch (hostile_poll_type)
          {
            case HOSTILE_POLL_CLOSED:
              shutdown(fds[x].fd, SHUT_RDWR);
              close(fds[x].fd);
              fds[x].revents= POLLIN|POLLHUP;
              break;

            case HOSTILE_POLL_SHUT_WR:
              shutdown(fds[x].fd, SHUT_WR);
              close(fds[x].fd);
              fds[x].revents= POLLIN;
              break;

            case HOSTILE_POLL_SHUT_RD:
              shutdown(fds[x].fd, SHUT_RD);
              fds[x].revents= POLLIN;
              break;

            default:
              assert(0);
              abort();
          }
        }
        return nfds;
      }
    }
  }

  set_called();
  int ret= __function.function.poll(fds, nfds, timeout);
  reset_called();

  return ret;
}
예제 #5
0
파일: accept.c 프로젝트: kitech/gearmand
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
{

  hostile_initialize();

  (void) pthread_once(&function_lookup_once, set_local);

  if (is_called() == false)
  {
    if (__function.frequency)
    {
      if (--not_until < 0 && random() % __function.frequency)
      {
        if (random() % 1)
        {
          shutdown(sockfd, SHUT_RDWR);
          close(sockfd);
          errno= ECONNABORTED;
          return -1;
        }
        else
        {
          shutdown(sockfd, SHUT_RDWR);
          close(sockfd);
          errno= EMFILE;
          return -1;
        }
      }
    }
  }

  set_called();
  int ret= __function.function.accept(sockfd, addr, addrlen);
  reset_called();

  return ret;
}