示例#1
0
static int conf_files_list_strv_internal(char ***strv, const char *suffix, const char *root, char **dirs) {
        Hashmap *fh;
        char **files, **p;
        int r;

        assert(strv);
        assert(suffix);

        /* This alters the dirs string array */
        if (!path_strv_canonicalize_absolute_uniq(dirs, root))
                return -ENOMEM;

        fh = hashmap_new(string_hash_func, string_compare_func);
        if (!fh)
                return -ENOMEM;

        STRV_FOREACH(p, dirs) {
                r = files_add(fh, *p, suffix);
                if (r == -ENOMEM) {
                        hashmap_free_free(fh);
                        return r;
                } else if (r < 0)
                        log_debug("Failed to search for files in %s: %s",
                                  *p, strerror(-r));
        }
示例#2
0
static int conf_files_list_strv_internal(char ***strv, const char *suffix, const char *root, unsigned flags, char **dirs) {
        _cleanup_hashmap_free_ Hashmap *fh = NULL;
        _cleanup_set_free_free_ Set *masked = NULL;
        char **files, **p;
        int r;

        assert(strv);

        /* This alters the dirs string array */
        if (!path_strv_resolve_uniq(dirs, root))
                return -ENOMEM;

        fh = hashmap_new(&path_hash_ops);
        if (!fh)
                return -ENOMEM;

        if (flags & CONF_FILES_FILTER_MASKED) {
                masked = set_new(&path_hash_ops);
                if (!masked)
                        return -ENOMEM;
        }

        STRV_FOREACH(p, dirs) {
                r = files_add(fh, masked, suffix, root, flags, *p);
                if (r == -ENOMEM)
                        return r;
                if (r < 0)
                        log_debug_errno(r, "Failed to search for files in %s, ignoring: %m", *p);
        }
示例#3
0
static int conf_files_list_strv_internal(char ***strv, const char *suffix, const char *root, char **dirs) {
        _cleanup_hashmap_free_ Hashmap *fh = NULL;
        char **files, **p;
        int r;

        assert(strv);
        assert(suffix);

        /* This alters the dirs string array */
        if (!path_strv_resolve_uniq(dirs, root))
                return -ENOMEM;

        fh = hashmap_new(&string_hash_ops);
        if (!fh)
                return -ENOMEM;

        STRV_FOREACH(p, dirs) {
                r = files_add(fh, root, *p, suffix);
                if (r == -ENOMEM)
                        return r;
                if (r < 0)
                        log_debug_errno(r, "Failed to search for files in %s, ignoring: %m", *p);
        }
示例#4
0
int options_parse(int argc, const char** argv, options_t* options)
{
  uint64_t val;
  int i;

  /* Initialize options to default values. */
  options->nconnections = DEFAULT_CONNECTIONS;
  options->nthreads = DEFAULT_THREADS;
  options->receive = DEFAULT_RECEIVE;
  options->number_thread_loops = DEFAULT_LOOPS;
  options->number_connection_loops = DEFAULT_LOOPS;
  options->client_sends_first = CLIENT_SENDS_FIRST;
  options->set_read_write_event = SET_READ_WRITE_EVENT;
  options->nprocessors = 0;

  files_init(&options->files);

  /* Last parameter is not an option. */
  argc--;

  i = 1;
  while (i < argc) {
    if (strcasecmp(argv[i], "--connections") == 0) {
      /* Last parameter? */
      if (i + 1 == argc) {
        files_free(&options->files);
        return -1;
      }

      if (parse_uint64(argv[i + 1],
                       MIN_CONNECTIONS,
                       MAX_CONNECTIONS,
                       &val) < 0) {
        files_free(&options->files);
        return -1;
      }

      options->nconnections = (unsigned) val;

      i += 2;
    } else if (strcasecmp(argv[i], "--threads") == 0) {
      /* Last parameter? */
      if (i + 1 == argc) {
        files_free(&options->files);
        return -1;
      }

      if (parse_uint64(argv[i + 1], MIN_THREADS, MAX_THREADS, &val) < 0) {
        files_free(&options->files);
        return -1;
      }

      options->nthreads = (unsigned) val;

      i += 2;
    } else if (strcasecmp(argv[i], "--receive") == 0) {
      /* Last parameter? */
      if (i + 1 == argc) {
        files_free(&options->files);
        return -1;
      }

      if (parse_uint64(argv[i + 1], MIN_RECEIVE, MAX_RECEIVE, &val) < 0) {
        files_free(&options->files);
        return -1;
      }

      options->receive = (unsigned) val;

      i += 2;
    } else if (strcasecmp(argv[i], "--thread-loops") == 0) {
      /* Last parameter? */
      if (i + 1 == argc) {
        files_free(&options->files);
        return -1;
      }

      if (parse_uint64(argv[i + 1],
                       MIN_LOOPS,
                       MAX_LOOPS,
                       &options->number_thread_loops) < 0) {
        files_free(&options->files);
        return -1;
      }

      i += 2;
    } else if (strcasecmp(argv[i], "--connection-loops") == 0) {
      /* Last parameter? */
      if (i + 1 == argc) {
        files_free(&options->files);
        return -1;
      }

      if (parse_uint64(argv[i + 1],
                       MIN_LOOPS,
                       MAX_LOOPS,
                       &options->number_connection_loops) < 0) {
        files_free(&options->files);
        return -1;
      }

      i += 2;
    } else if (strcasecmp(argv[i], "--client-sends-first") == 0) {
      options->client_sends_first = 1;

      i++;
    } else if (strcasecmp(argv[i], "--server-sends-first") == 0) {
      options->client_sends_first = 0;

      i++;
    } else if (strcasecmp(argv[i], "--set-read-write-event") == 0) {
      options->set_read_write_event = 1;

      i++;
    } else if (strcasecmp(argv[i], "--do-not-set-read-write-event") == 0) {
      options->set_read_write_event = 0;

      i++;
    } else if (strcasecmp(argv[i], "--processors") == 0) {
      /* Last parameter? */
      if (i + 1 == argc) {
        files_free(&options->files);
        return -1;
      }

      if (parse_processors(argv[i + 1],
                           options->processors,
                           &options->nprocessors) < 0) {
        files_free(&options->files);
        return -1;
      }

      i += 2;
    } else if (strcasecmp(argv[i], "--file") == 0) {
      /* Last parameter? */
      if (i + 1 == argc) {
        files_free(&options->files);
        return -1;
      }

      if (files_add(&options->files, argv[i + 1]) < 0) {
        files_free(&options->files);
        return -1;
      }

      i += 2;
    } else {
      files_free(&options->files);
      return -1;
    }
  }

  /* If no files have been specified... */
  if (options->files.used == 0) {
    if (files_add_dummy(&options->files) < 0) {
      files_free(&options->files);
      return -1;
    }
  }

  options->nthreads = MIN(options->nthreads, options->nconnections);

  if (options->receive == 0) {
    options->client_sends_first = 1;
  }

  return 0;
}