Ejemplo n.º 1
0
Archivo: main.c Proyecto: jtniehof/dpkg
int main(int argc, const char *const *argv) {
  jmp_buf ejbuf;
  void (*actionfunction)(const char *const *argv);

  setlocale(LC_ALL, "");
  bindtextdomain(PACKAGE, LOCALEDIR);
  textdomain(PACKAGE);

  standard_startup(&ejbuf);
  loadcfgfile(DPKG, cmdinfos);
  myopt(&argv, cmdinfos);

  if (!cipaction) badusage(_("need an action option"));

  if (!f_triggers)
    f_triggers = (cipaction->arg == act_triggers && *argv) ? -1 : 1;

  setvbuf(stdout, NULL, _IONBF, 0);

  if (is_invoke_action(cipaction->arg))
    run_invoke_hooks(cipaction->olong, pre_invoke_hooks);

  filesdbinit();

  actionfunction= (void (*)(const char* const*))cipaction->farg;

  actionfunction(argv);

  if (is_invoke_action(cipaction->arg))
    run_invoke_hooks(cipaction->olong, post_invoke_hooks);

  standard_shutdown();

  return reportbroken_retexitstatus();
}
Ejemplo n.º 2
0
int main(int argc, const char *const *argv) {
  struct dpkg_error err;
  int ret;

  setlocale(LC_NUMERIC, "POSIX");
  setlocale(LC_ALL, "");
  bindtextdomain(PACKAGE, LOCALEDIR);
  textdomain(PACKAGE);

  dpkg_set_progname(BACKEND);
  standard_startup();
  myopt(&argv, cmdinfos, printforhelp);

  if (!cipaction) badusage(_("need an action option"));

  if (!compressor_check_params(&compress_params, &err))
    badusage(_("invalid compressor parameters: %s"), err.str);

  unsetenv("GZIP");

  ret = cipaction->action(argv);

  standard_shutdown();

  return ret;
}
Ejemplo n.º 3
0
int
main(int argc, const char *const *argv)
{
	int uf;
	const char *badname;
	enum trigdef_updateflags tduf;

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	dpkg_set_progname("dpkg-trigger");
	standard_startup();
	myopt(&argv, cmdinfos, printforhelp);

	admindir = dpkg_db_set_dir(admindir);

	setvbuf(stdout, NULL, _IONBF, 0);

	if (f_check) {
		if (*argv)
			badusage(_("--%s takes no arguments"),
			         "check-supported");
		do_check();
	}

	if (!*argv || argv[1])
		badusage(_("takes one argument, the trigger name"));

	badname = parse_awaiter_package();
	if (badname)
		ohshit(_("illegal awaited package name '%.250s': %.250s"),
		       bypackage, badname);

	activate = argv[0];
	badname = trig_name_is_illegal(activate);
	if (badname)
		badusage(_("invalid trigger name `%.250s': %.250s"),
		         activate, badname);

	trigdef_set_methods(&tdm_add);

	tduf = tduf_nolockok;
	if (!f_noact)
		tduf |= tduf_write | tduf_writeifempty;
	uf = trigdef_update_start(tduf);
	if (uf >= 0) {
		trigdef_parse();
		if (!done_trig)
			trigdef_update_printf("%s %s\n", activate, bypackage);
		trigdef_process_done();
	}

	standard_shutdown();

	return 0;
}
Ejemplo n.º 4
0
int main(int argc, const char *const *argv) {
  jmp_buf ejbuf;

  setlocale(LC_NUMERIC, "POSIX");
  standard_startup(&ejbuf, argc, &argv, NULL, NULL, cmdinfos);
  if (!cipaction) badusage(_("need an action option"));

  unsetenv("GZIP");
  action(argv);
  standard_shutdown(NULL);
  exit(0);
}
Ejemplo n.º 5
0
int
main(int argc, char *const *argv)
{
	jmp_buf ejbuf;

	standard_startup(&ejbuf);

	const char *mode = NULL;
	admindir = ADMINDIR;

	int opt;
	while ((opt = getopt_long(argc, argv, ":", long_options, NULL)) != -1) {
		switch (opt) {
		case OPT_HELP:
			usage();
			return 0;
		case OPT_VERSION:
			version();
			return 0;
		case OPT_TEST:
			testmode = 1;
			break;
		case OPT_RENAME:
			dorename_ = 1;
			break;
		case OPT_QUIET:
			quiet = 1;
			break;
		case OPT_LOCAL:
			package = ":";
			break;
		case OPT_ADD:
			checkmanymodes(mode, "add");
			mode = "add";
			break;
		case OPT_REMOVE:
			checkmanymodes(mode, "remove");
			mode = "remove";
			break;
		case OPT_LIST:
			checkmanymodes(mode, "list");
			mode = "list";
			break;
		case OPT_LISTPACKAGE:
			checkmanymodes(mode, "listpackage");
			mode = "listpackage";
			break;
		case OPT_TRUENAME:
			checkmanymodes(mode, "truename");
			mode = "truename";
			break;
		case OPT_DIVERT:
			if(strchr(optarg, '\n'))
				badusage(_("divert-to may not contain newlines"));
			divertto = optarg;
			break;
		case OPT_PACKAGE:
			if(strchr(optarg, '\n'))
				badusage(_("package may not contain newlines"));
			package = optarg;
			break;
		case OPT_ADMINDIR:
			admindir = optarg;
			break;
		case ':':
			if(optopt == OPT_DIVERT)
				badusage(_("--divert needs a divert-to argument"));
			if(optopt == OPT_PACKAGE)
				badusage(_("--package needs a package argument"));
			if(optopt == OPT_ADMINDIR)
				badusage(_("--admindir needs an admindir argument"));
			ohshit(_("internal error: unknown option %d"), optopt);
		default:
			badusage(_("unknown option '%s'"), argv[optind]);
		}
	}

	diversion* diversions = read_diversions();

	if (!mode || !strcmp(mode, "add")) {
		if (optind != argc - 1)
			badusage(_("--%s needs a single argument"), "add");
		op_add(diversions, argv[optind]);
	}
	if (!strcmp(mode, "remove")) {
		if (optind != argc - 1)
			badusage(_("--%s needs a single argument"), "remove");
		op_remove(diversions, argv[optind]);
	}
	if (!strcmp(mode, "list")) {
		if (optind >= argc) {
			char *const null_pattern[] = { "*", NULL };
			op_list(diversions, null_pattern);
		} else {
			op_list(diversions, argv + optind);
		}
	}

	if (!strcmp(mode, "truename")) {
		if (optind != argc - 1)
			badusage(_("--%s needs a single argument"), mode);
		op_truename(diversions, argv[optind]);
	}

	if (!strcmp(mode, "listpackage")) {
		if (optind != argc - 1)
			badusage(_("--%s needs a single argument"), mode);
		op_listpackage(diversions, argv[optind]);
	}

	ohshit(_("internal error - bad mode '%s'"), mode);
}