Exemple #1
0
int run_wrapped(struct opts *opts) {
    int arg;

    char torun[PATH_MAX + 1];
    xfind_real_executable(opts, torun);

    struct timeval start;
    xgettimeofday(&start);

    char quoted_arg[1024*4];
    log_vcs(opts, "start: %s %d.%06d\n", VERSION, start.tv_sec, start.tv_usec);
    log_vcs(opts, "cmd: %s", xquotestr(opts->o_execname, quoted_arg,
                                       sizeof(quoted_arg)));
    for (arg = 0; arg < opts->o_argc; arg += 1)
        log_vcs(opts, " %s", xquotestr(opts->o_argv[arg], quoted_arg,
                                       sizeof(quoted_arg)));
    log_vcs(opts, "\n");

    char **new_argv;
    new_argv = xmalloc(sizeof(char *) * (opts->o_argc + 2));
    new_argv[0] = torun;
    for (arg = 0; arg < opts->o_argc; arg += 1)
        new_argv[arg+1] = opts->o_argv[arg];
    new_argv[arg+1] = NULL;

    int pid;
    if ((pid = fork()) == 0) {
        if (execv(torun, new_argv) < 0) {
            perror("vcslog-wrapper: execv");
            exit(1);
        }
        // we should never get here
    }

    struct rusage rusage;
    int status;
    wait3(&status, 0, &rusage);

    struct timeval end;
    xgettimeofday(&end);
    int exitcode = WEXITSTATUS(status);
    log_vcs(opts, "end: %d.%06d s:%d ut:%d.%06d st:%d.%06d\n",
            end.tv_sec, end.tv_usec,
            exitcode,
            rusage.ru_utime.tv_sec, rusage.ru_utime.tv_usec,
            rusage.ru_stime.tv_sec, rusage.ru_stime.tv_usec);
    return exitcode;
}
/*
** Mallocs a new client and initializes it to the default values
*/
t_client	*malloc_client()
{
  t_client	*c;
  static int	id = 0;
  int		i;

  c = xmalloc(sizeof(*c));
  c->socket = -1;
  c->team_name = NULL;
  c->requests = NULL;
  c->orientation = 1;
  c->level = 1;
  c->id = id++;
  c->out = c->request;
  c->in = c->request;
  c->request[0] = 0;
  c->to_send = NULL;
  c->to_send_len = 0;
  c->already_sent = 0;
  i = -1;
  while (++i < NB_ROCKS)
    c->rocks[i] = 0;
  c->life = DEFAULT_LIFE;
  xgettimeofday(&(c->next_meal), 0);
  set_next_meal(&(c->next_meal));
  return (c);
}
Exemple #3
0
static void
do_init(void)
{
    uint8_t sha1[SHA1_DIGEST_SIZE];
    struct sha1_ctx sha1_ctx;
    uint8_t random_seed[16];
    struct timeval now;

    /* Get seed data. */
    get_entropy_or_die(random_seed, sizeof random_seed);
    xgettimeofday(&now);

    /* Convert seed into key. */
    sha1_init(&sha1_ctx);
    sha1_update(&sha1_ctx, random_seed, sizeof random_seed);
    sha1_update(&sha1_ctx, &now, sizeof now);
    sha1_update_int(&sha1_ctx, getpid());
#ifndef _WIN32
    sha1_update_int(&sha1_ctx, getppid());
    sha1_update_int(&sha1_ctx, getuid());
    sha1_update_int(&sha1_ctx, getgid());
#endif
    sha1_final(&sha1_ctx, sha1);

    /* Generate key. */
    BUILD_ASSERT(sizeof sha1 >= 16);
    aes128_schedule(&key, sha1);

    /* Generate initial counter. */
    get_entropy_or_die(counter, sizeof counter);
}
Exemple #4
0
static void
benchmark_ccmap(void)
{
    struct ccmap ccmap;
    struct timeval start;
    pthread_t *threads;
    struct ccmap_aux aux;
    size_t i;

    /* Insertions. */
    xgettimeofday(&start);
    ccmap_init(&ccmap);
    for (i = 0; i < n_elems; i++) {
        ccmap_inc(&ccmap, hash_int(i, 0));
    }
    printf("ccmap insert:  %5d ms\n", elapsed(&start));

    /* Search and mutation. */
    xgettimeofday(&start);
    aux.ccmap = &ccmap;
    ovs_mutex_init(&aux.mutex);
    threads = xmalloc(n_threads * sizeof *threads);
    for (i = 0; i < n_threads; i++) {
        threads[i] = ovs_thread_create("search", search_ccmap, &aux);
    }
    for (i = 0; i < n_threads; i++) {
        xpthread_join(threads[i], NULL);
    }
    free(threads);
    printf("ccmap search:  %5d ms\n", elapsed(&start));

    /* Destruction. */
    xgettimeofday(&start);
    for (i = 0; i < n_elems; i++) {
        uint32_t hash = hash_int(i, 0);

        if (ccmap_find(&ccmap, hash)) {
            /* Also remove any colliding hashes. */
            while (ccmap_dec(&ccmap, hash)) {
                ;
            }
        }
    }
    ccmap_destroy(&ccmap);
    printf("ccmap destroy: %5d ms\n", elapsed(&start));
}
Exemple #5
0
static int
elapsed(const struct timeval *start)
{
    struct timeval end;

    xgettimeofday(&end);
    return timeval_to_msec(&end) - timeval_to_msec(start);
}
Exemple #6
0
static long long int
time_in_msec(void)
{
    struct timeval tv;

    xgettimeofday(&tv);

    return tv.tv_sec * 1000LL + tv.tv_usec / 1000;
}
Exemple #7
0
void
random_init(void)
{
    uint32_t *seedp = seed_get();
    while (!*seedp) {
        struct timeval tv;
        uint32_t entropy;
        pthread_t self;

        xgettimeofday(&tv);
        get_entropy_or_die(&entropy, 4);
        self = pthread_self();

        *seedp = (tv.tv_sec ^ tv.tv_usec ^ entropy
                  ^ hash_bytes(&self, sizeof self, 0));
    }
}
size_t time_to_string
  (const char *name, const char *uri, const char *query, char *buf, size_t bs)
{
    struct xtimeval tv;
    struct xtm tm;
    struct xtm *(*method)(const xtime_t *, struct xtm *) = xgmtime_r;
    if (0 == strcmp (name, "localtime")) {
        method = xlocaltime_r;
    }
    xgettimeofday (&tv, NULL);
    method (&tv.tv_sec, &tm);
    return snprintf
      ( buf
      , bs
      , "%lu-%02u-%02u %02u:%02u:%02u %s"
      , 1900 + tm.tm_year
      , tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec
      , tm.tm_zone
      );
}
int		do_connection(t_serv *serveur, t_client *client, int cs, int i)
{
  if (serveur->team[i].nb_clients - 1 >= 0)
    {
      client[cs].team = i;
      connect_to_drone(serveur, client, cs, i);
      client[cs].timelife = 1000000 *
	(client[cs].drone->nourriture * 126 / serveur->speed);
      client[cs].timelaps = 0;
      client[cs].flag = 0;
      xgettimeofday(&client[cs].life);
      delete_command(client, cs);
      memset(client[cs].buffer, 0, BUFF_SIZE);
      sprintf(client[cs].buffer, "%d\n%d %d\n",
	      --serveur->team[client[cs].team].nb_clients,
	      serveur->world_x, serveur->world_y);
      xsend(cs, client[cs].buffer, strlen(client[cs].buffer), 0);
      if (serveur->graphic_flag)
	send_pnw(serveur, client, cs);
      return (1);
    }
  xsend(cs, KO, strlen(KO), 0);
  return (-1);
}