Exemple #1
0
int fio_crctest(const char *type)
{
	unsigned int test_mask = 0;
	uint64_t mb = CHUNK * NR_CHUNKS;
	int i;

	crc32c_intel_probe();

	if (!type)
		test_mask = ~0U;
	else if (!strcmp(type, "help") || !strcmp(type, "list"))
		return list_types();
	else
		test_mask = get_test_mask(type);

	for (i = 0; t[i].name; i++) {
		double mb_sec;
		uint64_t usec;

		if (!(t[i].mask & test_mask))
			continue;

		usec = t[i].fn();
		mb_sec = (double) mb / (double) usec;
		mb_sec /= (1.024 * 1.024);
		printf("%s:\t%8.2f MB/sec\n", t[i].name, mb_sec);
	}

	return 0;
}
Exemple #2
0
Fichier : nm_64.c Projet : rioru/42
static t_type	*fill_types(struct segment_command_64 *segment,
	struct load_command *lc, t_type *type, int nb)
{
	unsigned int		i;
	struct section_64	*section;

	i = 0;
	while (i < segment->nsects)
	{
		section = (void*)lc + sizeof(struct segment_command_64)
		+ sizeof(struct section_64) * i;
		type = list_types(section, type, nb);
		++i;
	}
	return (type);
}
Exemple #3
0
int main(int argc, char** argv)
{
  AppArgs::Init();

  if (!(  AppArgs::AddOption("about",   '?', AAT_NO_VALUE, false)
      &&  AppArgs::AddOption("help",    'h', AAT_NO_VALUE, false)
      &&  AppArgs::AddOption("list",    'l', AAT_NO_VALUE, false)
      &&  AppArgs::AddOption("remove",  'r', AAT_NO_VALUE, false)
      &&  AppArgs::AddOption("edit",    'e', AAT_NO_VALUE, false)
      &&  AppArgs::AddOption("types",   't', AAT_NO_VALUE, false)
      &&  AppArgs::AddOption("reload",  'd', AAT_NO_VALUE, false)
      &&  AppArgs::AddOption("user",    'u', AAT_MANDATORY_VALUE, false)
      &&  AppArgs::AddOption("config",  'f', AAT_MANDATORY_VALUE, false)
      &&  AppArgs::AddOption("version", 'V', AAT_NO_VALUE, false)))
  {
    fprintf(stderr, "error while initializing application");
    return 1;
  }

  AppArgs::Parse(argc, argv);

  if (AppArgs::ExistsOption("help")) {
    fprintf(stderr, "%s\n", INCRONTAB_HELP);
    return 0;
  }

  if (AppArgs::ExistsOption("about")) {
    fprintf(stderr, "%s\n", INCRONTAB_DESCRIPTION);
    return 0;
  }

  if (AppArgs::ExistsOption("version")) {
    fprintf(stderr, "%s\n", INCRONTAB_VERSION);
    return 0;
  }

  bool oper = AppArgs::ExistsOption("list")
          ||  AppArgs::ExistsOption("remove")
          ||  AppArgs::ExistsOption("edit")
          ||  AppArgs::ExistsOption("types")
          ||  AppArgs::ExistsOption("reload");

  size_t vals = AppArgs::GetValueCount();

  if (!oper && vals == 0) {
    fprintf(stderr, "invalid arguments - specify operation or source file\n");
    return 1;
  }

  if (oper && vals > 0) {
    fprintf(stderr, "invalid arguments - operation and source file cannot be combined\n");
    return 1;
  }

  uid_t uid = getuid();

  std::string user;
  bool chuser = AppArgs::GetOption("user", user);

  if (uid != 0 && chuser) {
    fprintf(stderr, "cannot override user to '%s': insufficient privileges\n", user.c_str());
    return 1;
  }

  struct passwd* ppwd = NULL;

  if (chuser) {
	if ((ppwd = getpwnam(user.c_str())) != NULL) {
      if (    setenv("LOGNAME",   ppwd->pw_name,   1) != 0
		  ||  setenv("USER",      ppwd->pw_name,   1) != 0
		  ||  setenv("USERNAME",  ppwd->pw_name,   1) != 0
		  ||  setenv("HOME",      ppwd->pw_dir,    1) != 0
		  ||  setenv("SHELL",     ppwd->pw_shell,  1) != 0)
      {
		perror("cannot set environment variables");
		return 1;
	  }
	} else {
	  fprintf(stderr, "user '%s' not found\n", user.c_str());
	  return 1;
	}
  } else {
    ppwd = getpwuid(uid);
    if (ppwd == NULL) {
      fprintf(stderr, "cannot determine current user\n");
      return 1;
    }
    user = ppwd->pw_name;
  }

  try {

    IncronCfg::Init();

    std::string cfg(INCRON_CONFIG);
    if (AppArgs::GetOption("config", cfg)) {
      if (uid != 0) {
        fprintf(stderr, "insufficient privileges to use custom configuration (will use default)\n");
      }
      else if (euidaccess(cfg.c_str(), R_OK) != 0) {
        perror("cannot read configuration file (will use default)");
      }
    }

    IncronCfg::Load(cfg);

    if (!IncronTab::CheckUser(user)) {
      fprintf(stderr, "user '%s' is not allowed to use incron\n", user.c_str());
      return 1;
    }

    if (!oper) {
      std::string file;
      if (!AppArgs::GetValue(0, file)
          || !copy_from_file(file, user))
      {
        return 1;
      }
    }
    else {
      if (AppArgs::ExistsOption("list")) {
        if (!list_table(user))
          return 1;
      }
      else if (AppArgs::ExistsOption("remove")) {
        if (!remove_table(user))
          return 1;
      }
      else if (AppArgs::ExistsOption("edit")) {
        if (!edit_table(user))
          return 1;
      }
      else if (AppArgs::ExistsOption("types")) {
        list_types();
      }
      else if (AppArgs::ExistsOption("reload")) {
        if (!reload_table(user))
          return 1;
      }
      else {
        fprintf(stderr, "invalid usage\n");
        return 1;
      }
    }

    return 0;

  } catch (InotifyException e) {
    fprintf(stderr, "*** unhandled exception occurred ***\n");
    fprintf(stderr, "%s\n", e.GetMessage().c_str());
    fprintf(stderr, "error: (%i) %s\n", e.GetErrorNumber(), strerror(e.GetErrorNumber()));

    return 1;
  }
}
static void
xbsd_list_types(void)
{
    list_types(xbsd_fstypes);
}