コード例 #1
0
ファイル: lib-24.c プロジェクト: SuperLu/gcc
int
main (int argc, char **argv)
{
  const int N = 256;
  int i;
  unsigned char *h;
  void *d;

  h = (unsigned char *) malloc (N);

  d = acc_create (h, N);
  if (!d)
    abort ();

  for (i = 0; i < N; i++)
    {
      if (acc_is_present (h + i, 1) != 1)
	abort ();
    }

  acc_delete (h, N);

  for (i = 0; i < N; i++)
    {
      if (acc_is_present (h + i, 1) != 0)
	abort ();
    }

  d = acc_create (h, N);
  if (!d)
    abort ();

  for (i = 0; i < N; i++)
    {
      if (acc_is_present (h + i, 1) != 1)
	abort ();
    }

  acc_delete (h, N);

  for (i = 0; i < N; i++)
    {
      if (acc_is_present (h + i, 1) != 0)
	abort ();
    }

  free (h);

  return 0;
}
コード例 #2
0
END_TEST

START_TEST(tc_core_tail)
{
	struct achat_channel    *c  = NULL;
	achat_rc                 rc = ACHAT_RC_ERROR;

	c = acc_create();
	fail_if(c == NULL, "couldn't create channel");
	mark_point();

	rc = acc_settail(NULL, ACC_TAIL_NONE);
	fail_if(rc != ACHAT_RC_INVALPARAM,
	    "settail expected to fail with rc=%d but returned rc=%d",
	    ACHAT_RC_INVALPARAM, rc);
	mark_point();

	rc = acc_settail(c, 1024);
	fail_if(rc != ACHAT_RC_INVALPARAM,
	    "settail expected to fail with rc=%d but returned rc=%d",
	    ACHAT_RC_INVALPARAM, rc);
	mark_point();

	rc = acc_settail(c, ACC_TAIL_SERVER);
	fail_if(rc != ACHAT_RC_OK, "settail failed with rc=%d", rc);
	fail_if(c->tail != ACC_TAIL_SERVER, "tail not set correctly");
	mark_point();

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "destroy failed with rc=%d", rc);
}
コード例 #3
0
END_TEST

START_TEST(tc_core_sslmode)
{
	struct achat_channel    *c  = NULL;
	achat_rc                 rc = ACHAT_RC_ERROR;

	c = acc_create();
	fail_if(c == NULL, "couldn't create channel");
	mark_point();

	rc = acc_setsslmode(NULL, ACC_SSLMODE_NONE);
	fail_if(rc != ACHAT_RC_INVALPARAM,
	    "setsslmode expected to fail with rc=%d but returned rc=%d",
	    ACHAT_RC_INVALPARAM, rc);
	mark_point();

	rc = acc_setsslmode(c, 1024);
	fail_if(rc != ACHAT_RC_INVALPARAM,
	    "setsslmode expected to fail with rc=%d but returned rc=%d",
	    ACHAT_RC_INVALPARAM, rc);
	mark_point();

	rc = acc_setsslmode(c, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "setsslmode failed with rc=%d", rc);
	fail_if(c->sslmode != ACC_SSLMODE_CLEAR, "sslmode not set correctly");
	mark_point();

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "destroy failed with rc=%d", rc);
}
コード例 #4
0
ファイル: data-already-7.c プロジェクト: 0day-ci/gcc
int
main (int argc, char *argv[])
{
  int i;

#pragma acc enter data create (i)
  fprintf (stderr, "CheCKpOInT\n");
  acc_create (&i, sizeof i);

  return 0;
}
コード例 #5
0
void
tc_connect_lud_serverdup(const char *sockname)
{
	union {
		struct sockaddr_storage	ss;
		struct sockaddr_un	un;
	} sa;
	struct achat_channel    *s  = NULL;
	struct achat_channel    *s2 = NULL;
	achat_rc		 rc = ACHAT_RC_ERROR;

	s = acc_create();
	fail_if(s == NULL, "couldn't create server channel");
	fail_if(s->euid != (uid_t)-1, "euid expected -1 but is %i", s->euid);
	fail_if(s->egid != (gid_t)-1, "egid expected -1 but is %i", s->egid);

	rc = acc_settail(s, ACC_TAIL_SERVER);
	fail_if(rc != ACHAT_RC_OK, "server settail failed with rc=%d", rc);
	rc = acc_setsslmode(s, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "server setsslmode failed with rc=%d", rc);
	mark_point();

	bzero(&sa.ss, sizeof(sa.ss));
	sa.un.sun_family = AF_UNIX;
	strlcpy(sa.un.sun_path, sockname, sizeof(sa.un.sun_path));
	rc = acc_setaddr(s, &sa.ss, sizeof(struct sockaddr_un));
	if (rc != ACHAT_RC_OK)
		fail("server setaddr failed with rc=%d", rc);
	mark_point();

	rc = acc_prepare(s);
	fail_if(rc != ACHAT_RC_OK, "server prepare failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));

	s2 = acc_opendup(s);
	fail_if(s2 == NULL, "server opendup failed [%s]",
		anoubis_strerror(errno));
	fail_if(s2->euid != geteuid(), "server retrieved bogus uid %d, "
	    "expected %d", s2->euid, geteuid());
	fail_if(s2->egid != getegid(), "server retrieved bogus gid %d, "
	    "expected %d", s2->egid, getegid());

	rc = acc_destroy(s);
	fail_if(rc != ACHAT_RC_OK, "server org destroy failed with rc=%d",
	    rc);

	rc = acc_destroy(s2);
	fail_if(rc != ACHAT_RC_OK, "server dup destroy failed with rc=%d",
	    rc);
}
コード例 #6
0
void
tc_connect_lip_client(short port)
{
	union {
		struct sockaddr_storage	ss;
		struct sockaddr_in	in;
	} sa;
	struct achat_channel    *c  = NULL;
	achat_rc		 rc = ACHAT_RC_ERROR;

	c = acc_create();
	fail_if(c == NULL, "couldn't create client channel");
	fail_if(c->euid != (uid_t)-1, "euid expected -1 but is %i", c->euid);
	fail_if(c->egid != (gid_t)-1, "egid expected -1 but is %i", c->egid);

	rc = acc_settail(c, ACC_TAIL_CLIENT);
	fail_if(rc != ACHAT_RC_OK, "client settail failed with rc=%d", rc);
	rc = acc_setsslmode(c, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "client setsslmode failed with rc=%d", rc);
	mark_point();

	bzero(&sa.ss, sizeof(sa.ss));
	sa.in.sin_family = AF_INET;
	sa.in.sin_port = htons(port);
	inet_aton("127.0.0.1", &(sa.in.sin_addr));
	rc = acc_setaddr(c, &sa.ss, sizeof(struct sockaddr_in));
	if (rc != ACHAT_RC_OK)
		fail("client setaddr failed with rc=%d", rc);
	mark_point();

	rc = acc_prepare(c);
	fail_if(rc != ACHAT_RC_OK, "client prepare failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));

	sleep(4); /* give the server time to open his socket */
	rc = acc_open(c);
	fail_if(rc != ACHAT_RC_OK, "client open failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));
	fail_unless(c->euid == (uid_t)-1, "euid: -1 expected but is %i",
	    c->euid);
	fail_unless(c->egid == (gid_t)-1, "egid: -1 expected but is %i",
	    c->egid);

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "client destroy failed with rc=%d", rc);

	exit(0);
}
コード例 #7
0
void
tc_connect_lud_client(const char *sockname)
{
	union {
		struct sockaddr_storage	ss;
		struct sockaddr_un	un;
	} sa;
	struct achat_channel    *c  = NULL;
	achat_rc		 rc = ACHAT_RC_ERROR;

	c = acc_create();
	fail_if(c == NULL, "couldn't create client channel");
	fail_if(c->euid != (uid_t)-1, "euid expected -1 but is %i", c->euid);
	fail_if(c->egid != (gid_t)-1, "egid expected -1 but is %i", c->egid);
	mark_point();

	rc = acc_settail(c, ACC_TAIL_CLIENT);
	fail_if(rc != ACHAT_RC_OK, "client settail failed with rc=%d", rc);
	rc = acc_setsslmode(c, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "client setsslmode failed with rc=%d", rc);
	mark_point();

	bzero(&sa.ss, sizeof(sa.ss));
	sa.un.sun_family = AF_UNIX;
	strlcpy(sa.un.sun_path, sockname, sizeof(sa.un.sun_path));
	rc = acc_setaddr(c, &sa.ss, sizeof(struct sockaddr_un));
	if (rc != ACHAT_RC_OK)
		fail("client setaddr failed with rc=%d", rc);
	mark_point();

	rc = acc_prepare(c);
	fail_if(rc != ACHAT_RC_OK, "client prepare failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));

	sleep(4); /* give the server time to open his socket */
	rc = acc_open(c);
	fail_if(rc != ACHAT_RC_OK, "client open failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));

	fail_if(c->euid == (uid_t)-1, "euid != -1 expected, is %i", c->euid);
	fail_if(c->egid == (gid_t)-1, "egid != -1 expected, is %i", c->egid);

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "client destroy failed with rc=%d", rc);

	exit(0);
}
コード例 #8
0
ファイル: lib-29.c プロジェクト: earonesty/gcc
int
main (int argc, char **argv)
{
  const int N = 256;
  unsigned char *h;
  void *d;

  h = (unsigned char *) malloc (N);

  d = acc_create (h, N);
  if (!d)
    abort ();

  acc_delete (h, 0);

  free (h);

  return 0;
}
コード例 #9
0
END_TEST

START_TEST(tc_core_state_initialised)
{
	struct achat_channel    *c = NULL;
	union {
		struct sockaddr_storage	st;
		struct sockaddr_in	in;
	} sa;
	achat_rc                 rc = ACHAT_RC_ERROR;

	c = acc_create();
	fail_if(c == NULL, "couldn't create channel");
	mark_point();

	bzero(&sa.st, sizeof(sa.st));
	sa.in.sin_family = AF_INET;
	sa.in.sin_port = htons(ACHAT_SERVER_PORT);
	inet_aton("127.0.0.1", &(sa.in.sin_addr));
#ifdef OPENBSD
	sa.in.sin_len = sizeof(struct sockaddr_in);
#endif

	rc = acc_setaddr(c, &sa.st, sizeof(struct sockaddr_in));
	fail_if(rc != ACHAT_RC_OK, "setaddr failed with rc=%d", rc);
	if (memcmp(&c->addr, &sa.st, sizeof(sa.st)) != 0)
		fail("socket address not set correctly");
	fail_if(c->addrsize != sizeof(struct sockaddr_in),
		"socket address not set correctly");
	mark_point();

	rc = acc_settail(c, ACC_TAIL_SERVER);
	fail_if(rc != ACHAT_RC_OK, "settail failed with rc=%d", rc);
	fail_if(c->tail != ACC_TAIL_SERVER, "tail not set correctly");
	mark_point();

	rc = acc_setsslmode(c, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "setsslmode failed with rc=%d", rc);
	fail_if(c->sslmode != ACC_SSLMODE_CLEAR, "sslmode not set correctly");

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "destroy failed with rc=%d", rc);
}
コード例 #10
0
ファイル: lib-28.c プロジェクト: 0day-ci/gcc
int
main (int argc, char **argv)
{
  const int N = 256;
  unsigned char *h;
  void *d;

  h = (unsigned char *) malloc (N);

  d = acc_create (h, N);
  if (!d)
    abort ();

  fprintf (stderr, "CheCKpOInT\n");
  acc_delete (0, N);

  free (h);

  return 0;
}
コード例 #11
0
ファイル: test_wsconn.c プロジェクト: gaccob/gbase
int
test_ws_server() {
    con_table = idtable_create(1024);
    assert(con_table);

    r = reactor_create();
    assert(r);

    acc_t* acc = acc_create(r);
    assert(acc);
    acc_set_read_func(acc, _accept_read, NULL);

    struct sockaddr_in addr;
    int res = sock_addr_aton(WS_IP, WS_PORT, &addr);
    assert(res == 0);

    res = acc_start(acc, (struct sockaddr*)&addr);
    assert(res == 0);

    while (1) {
        res = reactor_dispatch(r, 1);
        if(res < 0) return -1;
        if(res == 0) usleep(100);
    }

    acc_stop(acc);
    acc_release(acc);
    for (int i = 0; i < 1024; i++) {
        WSCtx* ctx = idtable_get(con_table, i);
        if (ctx) {
            wsconn_release(ctx->con);
            FREE(ctx);
        }
    }
    idtable_release(con_table);
    reactor_release(r);
    return 0;
}
コード例 #12
0
END_TEST

START_TEST(tc_core_blocking)
{
	struct achat_channel    *c  = NULL;
	achat_rc                 rc = ACHAT_RC_ERROR;

	c = acc_create();
	fail_if(c == NULL, "couldn't create channel");
	mark_point();

	rc = acc_setblockingmode(c, ACC_BLOCKING);
	fail_if(rc != ACHAT_RC_OK, "acc_setblockingmode failed with rc=%d", rc);
	fail_if(c->blocking != ACC_BLOCKING, "blocking not set correctly");
	mark_point();

	rc = acc_setblockingmode(c, ACC_NON_BLOCKING);
	fail_if(rc != ACHAT_RC_OK, "acc_setblockingmode failed with rc=%d", rc);
	fail_if(c->blocking != ACC_NON_BLOCKING, "blocking not set correctly");
	mark_point();

	rc = acc_setblockingmode(c, -1);
	fail_if(rc != ACHAT_RC_INVALPARAM,
	    "blockingmode expected to fail with rc=%d but returned rc=%d",
	    ACHAT_RC_INVALPARAM, rc);
	mark_point();

	rc = acc_setblockingmode(c, 2);
	fail_if(rc != ACHAT_RC_INVALPARAM,
	    "blockingmode expected to fail with rc=%d but returned rc=%d",
	    ACHAT_RC_INVALPARAM, rc);
	mark_point();

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "destroy failed with rc=%d", rc);
}
コード例 #13
0
END_TEST


/*
 * This test prepares the client and server unix domain socket and run
 * a destroy on the client first. This should check/trigger bug #334 or
 * verify it's solution: the client may not unlink the server socket.
 */
START_TEST(tc_connect_localunixdomain_clientclose)
{
	char *sockname;
	union {
		struct sockaddr_storage	ss;
		struct sockaddr_un	un;
	} sa;
	struct achat_channel    *s  = NULL;
	struct achat_channel    *c  = NULL;
	achat_rc		 rc = ACHAT_RC_ERROR;

	sockname = tempnam(NULL, "ac");

	c = acc_create();
	fail_if(c == NULL, "couldn't create client channel");
	fail_if(c->euid != (uid_t)-1, "euid expected -1 but is %i", c->euid);
	fail_if(c->egid != (gid_t)-1, "egid expected -1 but is %i", c->egid);

	rc = acc_settail(c, ACC_TAIL_CLIENT);
	fail_if(rc != ACHAT_RC_OK, "client settail failed with rc=%d", rc);
	rc = acc_setsslmode(c, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "client setsslmode failed with rc=%d", rc);
	mark_point();

	bzero(&sa.ss, sizeof(sa.ss));
	sa.un.sun_family = AF_UNIX;
	strlcpy(sa.un.sun_path, sockname, sizeof(sa.un.sun_path));
	rc = acc_setaddr(c, &sa.ss, sizeof(struct sockaddr_un));
	if (rc != ACHAT_RC_OK)
		fail("client setaddr failed with rc=%d", rc);
	mark_point();

	rc = acc_prepare(c);
	fail_if(rc != ACHAT_RC_OK, "client prepare failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));
	mark_point();

	s = acc_create();
	fail_if(s == NULL, "couldn't create server channel");
	fail_if(c->euid != (uid_t)-1, "euid expected -1 but is %i", c->euid);
	fail_if(c->egid != (gid_t)-1, "egid expected -1 but is %i", c->egid);

	rc = acc_settail(s, ACC_TAIL_SERVER);
	fail_if(rc != ACHAT_RC_OK, "server settail failed with rc=%d", rc);
	rc = acc_setsslmode(s, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "server setsslmode failed with rc=%d", rc);
	mark_point();

	rc = acc_setaddr(s, &sa.ss, sizeof(struct sockaddr_un));
	if (rc != ACHAT_RC_OK)
		fail("server setaddr failed with rc=%d", rc);
	mark_point();

	rc = acc_prepare(s);
	fail_if(rc != ACHAT_RC_OK, "server prepare failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));
	mark_point();

	if (access(sockname, F_OK) != 0)
		fail("unix domain socket not created!");

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "client destroy failed with rc=%d", rc);

	if (access(sockname, F_OK) != 0)
		fail("unix domain socket (of server) removed by client!");

	rc = acc_destroy(s);
	fail_if(rc != ACHAT_RC_OK, "server destroy failed with rc=%d", rc);

	if (access(sockname, F_OK) == 0)
		fail("unix domain test: socket not removed!");
}
コード例 #14
0
ファイル: ComThread.cpp プロジェクト: genua/anoubis
ComThread::ConnectResult
ComThread::connect(void)
{
	struct sockaddr_storage	 ss;
	struct sockaddr_un	*ss_sun = (struct sockaddr_un *)&ss;
	achat_rc		 rc = ACHAT_RC_ERROR;
	int			 result;

	struct sigaction        act;

	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	act.sa_handler = SIG_IGN;
	sigaction(SIGPIPE, &act, NULL);

	/*
	 * *** channel ***
	 */

	channel_ = acc_create();
	if (channel_ == 0)
		return (Failure);

	rc = acc_settail(channel_, ACC_TAIL_CLIENT);
	if (rc != ACHAT_RC_OK) {
		disconnect();
		return (Failure);
	}

	rc = acc_setsslmode(channel_, ACC_SSLMODE_CLEAR);
	if (rc != ACHAT_RC_OK) {
		disconnect();
		return (Failure);
	}

	bzero(&ss, sizeof(ss));
	ss_sun->sun_family = AF_UNIX;
	strlcpy(ss_sun->sun_path, socketPath_.fn_str(),
	    sizeof(ss_sun->sun_path));
	rc = acc_setaddr(channel_, &ss, sizeof(struct sockaddr_un));
	if (rc != ACHAT_RC_OK) {
		disconnect();
		return (Failure);
	}

	rc = acc_prepare(channel_);
	if (rc != ACHAT_RC_OK) {
		disconnect();
		return (Failure);
	}

	rc = acc_open(channel_);
	if (rc != ACHAT_RC_OK) {
		disconnect();
		return (Failure);
	}

	/*
	 * *** client ***
	 */

	client_ = anoubis_client_create(channel_, ANOUBIS_AUTH_TRANSPORTANDKEY,
	    &x_auth_callback);
	if (client_ == 0) {
		disconnect();
		return (Failure);
	}

	result = anoubis_client_connect(client_, ANOUBIS_PROTO_BOTH);

	/* Pass protocol version back to the JobCtrl */
	JobCtrl::instance()->protocolVersion_ =
	    anoubis_client_serverversion(client_);

	/* Convert result to a enum */
	switch (-result) {
	/* In case everything is allright */
	case X_AUTH_SUCCESS:
		return Success;
		/* NOTREACHED */
	/* In case of missmatching Version */
	case EPROTONOSUPPORT:
		disconnect();
		return VersionMismatch;
		/* NOTREACHED */
	/* In case of error while authentication*/
	case X_AUTH_NOKEY:
		disconnect();
		return AuthNoKey;
		/* NOTREACHED */
	case ANOUBIS_AUTHERR_KEY_MISMATCH:
		disconnect();
		return AuthWrongKeyId;
		/* NOTREACHED */
	case ANOUBIS_AUTHERR_KEY:
		disconnect();
		return AuthInvalidKey;
		/* NOTREACHED */
	case ANOUBIS_AUTHERR_CERT:
		disconnect();
		return AuthInvalidCert;
		/* NOTREACHED */
	/* Internal System Error */
	case ANOUBIS_AUTHERR_PKG:
	case ANOUBIS_AUTHERR_INVAL:
	case ANOUBIS_AUTHERR_RAND:
	case ANOUBIS_AUTHERR_NOMEM:
	case ANOUBIS_AUTHERR_SIGN:
	default:
		disconnect();
		return AuthSysFail;
		/* NOTREACHED */
	}

	/* Should not happen since we handel everythin before */
	return (Failure);
}
コード例 #15
0
ファイル: pbgp_epoch.c プロジェクト: icsecurity/pbgp
int
claim_new_epoch(char *glb[2],char *epoch[2],char *facc,char *outf,setup_params_t *setup)
{
      int rv = 0, i = 0;
      epoch_item_t *ep = NULL;      
      id_list_t *act = NULL, *rvk = NULL;

      rv = newepoch_init(&ep,setup);
      if(rv < 0) {
            pbgp_error("claim_new_epoch :: Cannot complete initialization process\n");
            goto out1;
      }

      rv = ids_init(&ep->epls.act,&ep->epls.rvk);
      rv -= ids_init(&act,&rvk);
      if (rv < 0) { 
            pbgp_error("claim_new_epoch :: Cannot initialize ids lists\n");

            goto out2;
      }
     
      if (!file_exists(epoch[0]) || !file_exists(epoch[1])) {
            rv = -1;
            pbgp_error("Cannot find epoch files (%s,%s)\n",epoch[0],epoch[1]);
            goto out2;
      } 
 
      rv = ids_load(epoch[0],ep->epls.act);
	rv -= ids_load(epoch[1],ep->epls.rvk);
	rv -= ids_load(glb[0],act);
	rv -= ids_load(glb[1],rvk);
      if(rv < 0) { 
            pbgp_error("claim_new_epoch :: Cannot load ids\n");
            goto out3;
      }
     
      if(ep->epls.act->size == 0 && ep->epls.rvk->size == 0) {
            rv = -1;
            pbgp_error("claim_new_epoch :: There are no entities to join or revoke\n");
            goto out3;

      }
 
      //if first epoch
      if(!file_exists(facc)) {
            acc_create(ep->acc);
            ep->epoch = 0;
      } else {
            rv = acc_load(facc,ep->acc);
            if(rv < 0) {
                  pbgp_error("claim_new_epoch :: Cannot create accumulator\n");
                  goto out4;
            }
      }       
      ep->epoch = ep->acc->nep;
      //element_printf("ACC: %B\n",ep->acc);

      newepoch_gen(outf,ep,setup);
      //save accumulator
      //element_printf("ACC: %B\n",ep->acc);
      if(element_is0(ep->acc->elem)) {
            printf("ACC is 0\n");
            element_set1(ep->acc->elem);
      }
      acc_save(facc,ep->epoch,ep->acc);
      //update global joined entities
      for(i = 0; i < ep->epls.act->size; i++) {
            ids_add(act,&ep->epls.act->head[i]);
      }
      //update global revoked entities
      for(i = 0; i < ep->epls.rvk->size; i++) {
            ids_remove(act,&ep->epls.rvk->head[i]);
            ids_add(rvk,&ep->epls.rvk->head[i]);
      }
      ids_save(glb[0],act);
      ids_save(glb[1],rvk);
      
      //delete old epoch files (or write empty list)
      remove(epoch[0]);
      remove(epoch[1]);

out4:      
      acc_clear(ep->acc);
out3:
      ids_clear(ep->epls.act,ep->epls.rvk);
      ids_clear(act,rvk);
out2:
      newepoch_clear(ep);
out1:
      return rv; 
}
コード例 #16
0
END_TEST


START_TEST(tc_connect_localip)
{
	union {
		struct sockaddr_storage	ss;
		struct sockaddr_in	in;
	} sa;
	struct achat_channel    *s  = NULL;
	achat_rc		 rc = ACHAT_RC_ERROR;
	pid_t			 childpid;
	socklen_t		 sslen;

	s = acc_create();
	fail_if(s == NULL, "couldn't create server channel");
	fail_if(s->euid != (uid_t)-1, "euid expected -1 but is %i", s->euid);
	fail_if(s->egid != (gid_t)-1, "egid expected -1 but is %i", s->egid);

	rc = acc_settail(s, ACC_TAIL_SERVER);
	fail_if(rc != ACHAT_RC_OK, "server settail failed with rc=%d", rc);
	rc = acc_setsslmode(s, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "server setsslmode failed with rc=%d", rc);
	mark_point();

	bzero(&sa.ss, sizeof(sa.ss));
	sa.in.sin_family = AF_INET;
	sa.in.sin_port = 0;
	inet_aton("127.0.0.1", &(sa.in.sin_addr));
	rc = acc_setaddr(s, &sa.ss, sizeof(struct sockaddr_in));
	if (rc != ACHAT_RC_OK)
		fail("server setaddr failed with rc=%d", rc);
	mark_point();

	rc = acc_prepare(s);
	fail_if(rc != ACHAT_RC_OK, "server prepare failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));
	mark_point();

	bzero(&sa.ss, sizeof(sa.ss));
	sslen = sizeof(sa.ss);
	if (getsockname(s->fd, (struct sockaddr *)&sa.ss, &sslen) == -1)
		fail("error while asking about server socket name [%s]",
		    anoubis_strerror(errno));
	fail_if(sa.in.sin_port == 0,
	    "couldn't determine port of server socket");
	mark_point();

	switch (childpid = check_fork()) {
	case -1:
		fail("couldn't fork");
		break;
	case 0:
		/* child / client */
		tc_connect_lip_client(ntohs(sa.in.sin_port));
		check_waitpid_and_exit(0);
		break;
	default:
		/* parent / server */
		rc = acc_open(s);
		fail_if(rc != ACHAT_RC_OK, "server open failed with rc=%d [%s]",
		    rc, anoubis_strerror(errno));
		fail_unless(s->euid == (uid_t)-1, "euid: -1 expected but is %i",
			s->euid);
		fail_unless(s->egid == (gid_t)-1, "egid: -1 expected but is %i",
			s->egid);

		rc = acc_destroy(s);
		fail_if(rc != ACHAT_RC_OK, "server destroy failed with rc=%d",
		    rc);

		check_waitpid_and_exit(childpid);
		break;
	}
}
コード例 #17
0
ファイル: oacc-parallel.c プロジェクト: marxin/gcc
void
GOACC_enter_exit_data (int device, const void *offload_table, size_t mapnum,
		       void **hostaddrs, size_t *sizes, unsigned short *kinds,
		       int async, int num_waits, ...)
{
  struct goacc_thread *thr;
  struct gomp_device_descr *acc_dev;
  bool host_fallback = device == GOMP_DEVICE_HOST_FALLBACK;
  bool data_enter = false;
  size_t i;

  select_acc_device (device);

  thr = goacc_thread ();
  acc_dev = thr->dev;

  if ((acc_dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM)
      || host_fallback)
    return;

  if (num_waits > 0)
    {
      va_list ap;

      va_start (ap, num_waits);

      goacc_wait (async, num_waits, ap);

      va_end (ap);
    }

  acc_dev->openacc.async_set_async_func (async);

  /* Determine if this is an "acc enter data".  */
  for (i = 0; i < mapnum; ++i)
    {
      unsigned char kind = kinds[i] & 0xff;

      if (kind == GOMP_MAP_POINTER || kind == GOMP_MAP_TO_PSET)
	continue;

      if (kind == GOMP_MAP_FORCE_ALLOC
	  || kind == GOMP_MAP_FORCE_PRESENT
	  || kind == GOMP_MAP_FORCE_TO)
	{
	  data_enter = true;
	  break;
	}

      if (kind == GOMP_MAP_FORCE_DEALLOC
	  || kind == GOMP_MAP_FORCE_FROM)
	break;

      gomp_fatal (">>>> GOACC_enter_exit_data UNHANDLED kind 0x%.2x",
		      kind);
    }

  if (data_enter)
    {
      for (i = 0; i < mapnum; i++)
	{
	  unsigned char kind = kinds[i] & 0xff;

	  /* Scan for PSETs.  */
	  int psets = find_pset (i, mapnum, kinds);

	  if (!psets)
	    {
	      switch (kind)
		{
		case GOMP_MAP_POINTER:
		  gomp_acc_insert_pointer (1, &hostaddrs[i], &sizes[i],
					&kinds[i]);
		  break;
		case GOMP_MAP_FORCE_ALLOC:
		  acc_create (hostaddrs[i], sizes[i]);
		  break;
		case GOMP_MAP_FORCE_PRESENT:
		  acc_present_or_copyin (hostaddrs[i], sizes[i]);
		  break;
		case GOMP_MAP_FORCE_TO:
		  acc_present_or_copyin (hostaddrs[i], sizes[i]);
		  break;
		default:
		  gomp_fatal (">>>> GOACC_enter_exit_data UNHANDLED kind 0x%.2x",
			      kind);
		  break;
		}
	    }
	  else
	    {
	      gomp_acc_insert_pointer (3, &hostaddrs[i], &sizes[i], &kinds[i]);
	      /* Increment 'i' by two because OpenACC requires fortran
		 arrays to be contiguous, so each PSET is associated with
		 one of MAP_FORCE_ALLOC/MAP_FORCE_PRESET/MAP_FORCE_TO, and
		 one MAP_POINTER.  */
	      i += 2;
	    }
	}
    }
  else
    for (i = 0; i < mapnum; ++i)
      {
	unsigned char kind = kinds[i] & 0xff;

	int psets = find_pset (i, mapnum, kinds);

	if (!psets)
	  {
	    switch (kind)
	      {
	      case GOMP_MAP_POINTER:
		gomp_acc_remove_pointer (hostaddrs[i], (kinds[i] & 0xff)
					 == GOMP_MAP_FORCE_FROM,
					 async, 1);
		break;
	      case GOMP_MAP_FORCE_DEALLOC:
		acc_delete (hostaddrs[i], sizes[i]);
		break;
	      case GOMP_MAP_FORCE_FROM:
		acc_copyout (hostaddrs[i], sizes[i]);
		break;
	      default:
		gomp_fatal (">>>> GOACC_enter_exit_data UNHANDLED kind 0x%.2x",
			    kind);
		break;
	      }
	  }
	else
	  {
	    gomp_acc_remove_pointer (hostaddrs[i], (kinds[i] & 0xff)
				     == GOMP_MAP_FORCE_FROM, async, 3);
	    /* See the above comment.  */
	    i += 2;
	  }
      }

  acc_dev->openacc.async_set_async_func (acc_async_sync);
}
コード例 #18
0
END_TEST

START_TEST(tc_Sessions_three)
{
	union {
		struct sockaddr_storage	ss;
		struct sockaddr_un	un;
	} sa;
	struct achat_channel	*c  = NULL;
	achat_rc		 rc = ACHAT_RC_ERROR;
	struct anoubis_client   *client;
	struct anoubis_transaction * t;
	int count = 0;
	int ret;

	c = acc_create();
	fail_if(c == NULL, "couldn't create channel");
	rc = acc_settail(c, ACC_TAIL_CLIENT);
	fail_if(rc != ACHAT_RC_OK, "settail failed with rc=%d", rc);
	rc = acc_setsslmode(c, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "setsslmode failed with rc=%d", rc);
	mark_point();

	bzero(&sa.ss, sizeof(sa.ss));
	sa.un.sun_family = AF_UNIX;
	strlcpy(sa.un.sun_path, sockname, sizeof(sa.un.sun_path));
	rc = acc_setaddr(c, &sa.ss, sizeof(struct sockaddr_un));
	fail_if(rc != ACHAT_RC_OK, "setaddr failed with rc=%d", rc);
	mark_point();

	rc = acc_prepare(c);
	fail_if(rc != ACHAT_RC_OK, "prepare failed with rc=%d [%s]", rc,
	    anoubis_strerror(errno));
	rc = acc_open(c);
	fail_if(rc != ACHAT_RC_OK, "open failed with rc=%d [%s]", rc,
	    anoubis_strerror(errno));
	mark_point();

	client = anoubis_client_create(c, ANOUBIS_AUTH_TRANSPORT, NULL);
	fail_if(!client, "Failed to create client");
	mark_point();

	ret = anoubis_client_connect(client, ANOUBIS_PROTO_BOTH);
	fail_if(ret < 0, "client connect failed with code %d", ret);
	mark_point();

	t = anoubis_client_register_start(client, 0x123, 0, 0,
	    ANOUBIS_SOURCE_STAT);
	fail_if(!t, "Failed to register for stat events");
	while(count < 3) {
		struct anoubis_msg * m = anoubis_msg_new(4000);
		size_t length = 4000;
		fail_if(!m, "Cannot allocate message");
		rc = acc_receivemsg(c, m->u.buf, &length);
		fail_if(rc != ACHAT_RC_OK, "receive message returned %d", rc);
		anoubis_msg_resize(m, length);
		rc = anoubis_client_process(client, m);
		fail_if(rc != 1, "client process failed");
		m = anoubis_client_getnotify(client);
		if (m) {
			anoubis_dump(m, "NOTIFY");
			anoubis_msg_free(m);
			count++;
		}
	}
	anoubis_client_close(client);
	mark_point();

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "destroy failed with rc=%d", rc);
}
コード例 #19
0
END_TEST

START_TEST(tc_core_addr)
{
	struct achat_channel    *c = NULL;
	union {
		struct sockaddr_storage	 st;
		struct sockaddr_un	 un;
		struct sockaddr_in	 in;
	} sa;
	char			 testpath[] = "The road goes ever on and on";
	achat_rc                 rc = ACHAT_RC_ERROR;

	c = acc_create();
	fail_if(c == NULL, "couldn't create channel");
	mark_point();

	rc = acc_setaddr(NULL, NULL, 0);
	fail_if(rc != ACHAT_RC_INVALPARAM,
	    "setaddr expected to fail with rc=%d but returned rc=%d",
	    ACHAT_RC_INVALPARAM, rc);
	mark_point();

	rc = acc_setaddr(c, NULL, 0);
	fail_if(rc != ACHAT_RC_INVALPARAM,
	    "setaddr expected to fail with rc=%d but returned rc=%d",
	    ACHAT_RC_INVALPARAM, rc);
	mark_point();

	bzero(&sa.st, sizeof(sa.st));
	sa.un.sun_family = AF_UNIX;
	strlcpy(sa.un.sun_path, testpath, sizeof(sa.un.sun_path));
#ifdef OPENBSD
	sa.un.sun_len = SUN_LEN(&sa.un);
#endif
	rc = acc_setaddr(c, &sa.st, sizeof(struct sockaddr_un));
	fail_if(rc != ACHAT_RC_OK, "setaddr failed with rc=%d", rc);
	if (memcmp(&c->addr, &sa.st, sizeof(sa.st)) != 0)
		fail("socket address not set correctly");
	fail_if(c->addrsize != sizeof(struct sockaddr_un),
		"socket address not set correctly");
	mark_point();

	bzero(&sa.st, sizeof(sa.st));
	sa.in.sin_family = AF_INET;
	sa.in.sin_port = htons(ACHAT_SERVER_PORT);
	inet_aton("127.0.0.1", &(sa.in.sin_addr));
#ifdef OPENBSD
	sa.in.sin_len = sizeof(struct sockaddr_in);
#endif
	rc = acc_setaddr(c, &sa.st, sizeof(struct sockaddr_in));
	fail_if(rc != ACHAT_RC_OK, "setaddr failed with rc=%d", rc);
	if (memcmp(&c->addr, &sa.st, sizeof(sa.st)) != 0)
		fail("socket address not set correctly");
	fail_if(c->addrsize != sizeof(struct sockaddr_in),
		"socket address not set correctly");
	mark_point();

	/* XXX by ch: test of AF_INET6 is missing here */

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "destroy failed with rc=%d", rc);
}
コード例 #20
0
END_TEST

START_TEST(tc_Sessions_two)
{
	union {
		struct sockaddr_storage	ss;
		struct sockaddr_un	un;
	} sa;
	struct achat_channel	*c1  = NULL;
	struct achat_channel	*c2  = NULL;
	achat_rc		 rc = ACHAT_RC_ERROR;
	struct anoubis_client   *client1, *client2;
	int			 ret;

	c1 = acc_create();
	fail_if(c1 == NULL, "couldn't create first channel");
	rc = acc_settail(c1, ACC_TAIL_CLIENT);
	fail_if(rc != ACHAT_RC_OK, "1st channel settail failed with rc=%d", rc);
	rc = acc_setsslmode(c1, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "1st channel setsslmode failed with rc=%d",
	    rc);
	mark_point();

	c2 = acc_create();
	fail_if(c2 == NULL, "couldn't create second channel");
	rc = acc_settail(c2, ACC_TAIL_CLIENT);
	fail_if(rc != ACHAT_RC_OK, "2nd channel settail failed with rc=%d", rc);
	rc = acc_setsslmode(c2, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "2nd channel setsslmode failed with rc=%d",
	    rc);
	mark_point();

	bzero(&sa.ss, sizeof(sa.ss));
	sa.un.sun_family = AF_UNIX;
	strlcpy(sa.un.sun_path, sockname, sizeof(sa.un.sun_path));
	rc = acc_setaddr(c1, &sa.ss, sizeof(struct sockaddr_un));
	fail_if(rc != ACHAT_RC_OK, "1st channel setaddr failed with rc=%d", rc);
	rc = acc_setaddr(c2, &sa.ss, sizeof(struct sockaddr_un));
	fail_if(rc != ACHAT_RC_OK, "2nd channel setaddr failed with rc=%d", rc);
	mark_point();

	rc = acc_prepare(c1);
	fail_if(rc != ACHAT_RC_OK, "1st channel prepare failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));
	rc = acc_open(c1);
	fail_if(rc != ACHAT_RC_OK, "1st channel open failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));
	mark_point();

	client1 = anoubis_client_create(c1, ANOUBIS_AUTH_TRANSPORT, NULL);
	fail_if(!client1, "1st client create failed");
	mark_point();

	rc = acc_prepare(c2);
	fail_if(rc != ACHAT_RC_OK, "2nd channel prepare failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));
	rc = acc_open(c2);
	fail_if(rc != ACHAT_RC_OK, "2nd channel open failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));
	mark_point();
	client2 = anoubis_client_create(c2, ANOUBIS_AUTH_TRANSPORT, NULL);
	fail_if(!client1, "2nd client create failed");
	mark_point();

	ret = anoubis_client_connect(client1, ANOUBIS_PROTO_BOTH);
	fail_if(ret < 0, "1st client connect failed with %d", ret);
	mark_point();

	ret = anoubis_client_connect(client2, ANOUBIS_PROTO_BOTH);
	fail_if(ret < 0, "2nd client connect failed with %d", ret);
	mark_point();

	rc = acc_destroy(c1);
	fail_if(rc != ACHAT_RC_OK, "1st channel destroy failed with rc=%d", rc);

	rc = acc_destroy(c2);
	fail_if(rc != ACHAT_RC_OK, "2nd channel destroy failed with rc=%d", rc);
}