예제 #1
0
void
trig_incorporate(enum modstatdb_rw cstatus)
{
	enum trigdef_update_status ur;
	enum trigdef_updateflags tduf;

	free(triggersdir);
	triggersdir = dpkg_db_get_path(TRIGGERSDIR);

	free(triggersfilefile);
	triggersfilefile = trig_get_filename(triggersdir, "File");

	free(triggersnewfilefile);
	triggersnewfilefile = trig_get_filename(triggersdir, "File.new");

	trigdef_set_methods(&tdm_incorp);
	trig_file_interests_ensure();

	tduf = tduf_nolockok;
	if (cstatus >= msdbrw_write) {
		tduf |= tduf_write;
		if (trigh.transitional_activate)
			tduf |= tduf_writeifenoent;
	}

	ur = trigdef_update_start(tduf);
	if (ur == tdus_error_no_dir && cstatus >= msdbrw_write) {
		if (mkdir(triggersdir, 0755)) {
			if (errno != EEXIST)
				ohshite(_("unable to create triggers state"
				          " directory `%.250s'"), triggersdir);
		} else if (chown(triggersdir, 0, 0)) {
			ohshite(_("unable to set ownership of triggers state"
			          " directory `%.250s'"), triggersdir);
		}
		ur = trigdef_update_start(tduf);
	}
	switch (ur) {
	case tdus_error_empty_deferred:
		return;
	case tdus_error_no_dir:
	case tdus_error_no_deferred:
		if (!trigh.transitional_activate)
			return;
	/* Fall through. */
	case tdus_no_deferred:
		trigh.transitional_activate(cstatus);
		break;
	case tdus_ok:
		/* Read and incorporate triggers. */
		trigdef_parse();
		break;
	default:
		internerr("unknown trigdef_update_start return value '%d'", ur);
	}

	/* Right, that's it. New (empty) Unincorp can be installed. */
	trigdef_process_done();
}
예제 #2
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;
}
예제 #3
0
파일: triglib.c 프로젝트: guillemj/dpkg
void
trig_incorporate(enum modstatdb_rw cstatus)
{
	enum trigdef_update_status ur;
	enum trigdef_update_flags tduf;

	free(triggersdir);
	triggersdir = dpkg_db_get_path(TRIGGERSDIR);

	free(triggersfilefile);
	triggersfilefile = trig_get_filename(triggersdir, TRIGGERSFILEFILE);

	trigdef_set_methods(&tdm_incorp);
	trig_file_interests_ensure();

	tduf = TDUF_NO_LOCK_OK;
	if (cstatus >= msdbrw_write) {
		tduf |= TDUF_WRITE;
		if (trigh.transitional_activate)
			tduf |= TDUF_WRITE_IF_ENOENT;
	}

	ur = trigdef_update_start(tduf);
	if (ur == TDUS_ERROR_NO_DIR && cstatus >= msdbrw_write) {
		if (mkdir(triggersdir, 0755)) {
			if (errno != EEXIST)
				ohshite(_("unable to create triggers state"
				          " directory '%.250s'"), triggersdir);
		} else if (chown(triggersdir, 0, 0)) {
			ohshite(_("unable to set ownership of triggers state"
			          " directory '%.250s'"), triggersdir);
		}
		ur = trigdef_update_start(tduf);
	}
	switch (ur) {
	case TDUS_ERROR_EMPTY_DEFERRED:
		return;
	case TDUS_ERROR_NO_DIR:
	case TDUS_ERROR_NO_DEFERRED:
		if (!trigh.transitional_activate)
			return;
	/* Fall through. */
	case TDUS_NO_DEFERRED:
		trigh.transitional_activate(cstatus);
		break;
	case TDUS_OK:
		/* Read and incorporate triggers. */
		trigdef_parse();
		break;
	default:
		internerr("unknown trigdef_update_start return value '%d'", ur);
	}

	/* Right, that's it. New (empty) Unincorp can be installed. */
	trigdef_process_done();
}
예제 #4
0
파일: trigcmd.c 프로젝트: guillemj/dpkg
int
main(int argc, const char *const *argv)
{
	const char *badname;
	enum trigdef_update_flags tduf;
	enum trigdef_update_status tdus;

	dpkg_locales_init(PACKAGE);
	dpkg_program_init("dpkg-trigger");
	dpkg_options_parse(&argv, cmdinfos, printforhelp);

	admindir = dpkg_db_set_dir(admindir);

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

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

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

	fsys_hash_init();

	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_NO_LOCK_OK;
	if (!f_noact)
		tduf |= TDUF_WRITE | TDUF_WRITE_IF_EMPTY;
	tdus = trigdef_update_start(tduf);
	if (tdus >= 0) {
		trigdef_parse();
		if (!done_trig)
			trigdef_update_printf("%s %s\n", activate, bypackage);
		trigdef_process_done();
	}

	dpkg_program_done();

	return 0;
}
예제 #5
0
static int
test_trigdeferred_parser(const char *admindir)
{
	enum trigdef_update_flags tduf;
	enum trigdef_update_status tdus;

	dpkg_db_set_dir(admindir);

	trigdef_set_methods(&test_tdm);

	tduf = TDUF_NO_LOCK | TDUF_WRITE_IF_EMPTY | TDUF_WRITE_IF_ENOENT;
	tdus = trigdef_update_start(tduf);
	if (tdus < TDUS_OK)
		return -tdus + TDUS_OK;

	trigdef_parse();

	trigdef_process_done();

	return 0;
}