<commit_before>/*
 * This file is part of Kotaka, a mud library for DGD
 * http://github.com/shentino/kotaka
 *
 * Copyright (C) 2018, 2019, 2020  <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <kernel/kernel.h>
#include <kernel/rsrc.h>
#include <kotaka/assert.h>
#include <kotaka/log.h>
#include <kotaka/paths/system.h>
#include <kotaka/privilege.h>
#include <status.h>
#include <type.h>

#define MODULE_BOOT_TICKS 1000000000

inherit SECOND_AUTO;
inherit UTILITY_COMPILE;
inherit LIB_SYSTEM;
inherit "~/lib/struct/list";

mapping modules;

private void scramble(mixed *arr)
{
	int sz;
	int i;

	sz = sizeof(arr);

	for (i = 0; i < sz; i++) {
		int j;
		mixed tmp;

		j = random(sz);

		tmp = arr[i];
		arr[i] = arr[j];
		arr[j] = tmp;
	}
}

private void freeze_module(string module)
{
	KERNELD->rsrc_set_limit(module, "objects", 0);
}

private void thaw_module(string module)
{
	int sz;
	string *resources;

	resources = KERNELD->query_resources();

	for (sz = sizeof(resources); --sz >= 0; ) {
		KERNELD->rsrc_set_limit(module, resources[sz], -1);
	}
}

private void send_module_boot_signal(string module)
{
	int sz;
	string *others;

	others = map_indices(modules);
	others -= ({ module });
	others |= ({ "System" });
	scramble(others);

	for (sz = sizeof(others) - 1; sz >= 0; --sz) {
		if (modules[others[sz]] != 1) {
			continue;
		}

		catch {
			object initd;

			if (initd = find_object(initd_of(others[sz]))) {
				initd->booted_module(module);
			} else {
				call_out("shutdown_module", 0, module);
			}
		}
	}
}

private void send_module_shutdown_signal(string module)
{
	int sz;
	string *others;

	others = map_indices(modules);
	others -= ({ module });
	others |= ({ "System" });
	scramble(others);

	for (sz = sizeof(others) - 1; sz >= 0; --sz) {
		if (modules[others[sz]] != 1) {
			continue;
		}

		catch {
			object initd;

			if (initd = find_object(initd_of(others[sz]))) {
				initd->shutdown_module(module);
			} else {
				call_out("shutdown_module", 0, module);
			}
		}
	}
}

static void purge_objects(string module)
{
	rlimits (0; -1) {
		mixed **list;

		list = OBJECTD->query_program_indices();

		while (!list_empty(list)) {
			int index;
			object pinfo;
			string path;

			index = list_front(list);
			list_pop_front(list);

			pinfo = OBJECTD->query_program_info(index);

			if (!pinfo) {
				continue;
			}

			if (pinfo->query_destructed()) {
				continue;
			}

			path = pinfo->query_path();

			if (DRIVER->creator(path) != module) {
				/* not theirs */<commit_msg>Make purge_objects private<commit_after>/*
 * This file is part of Kotaka, a mud library for DGD
 * http://github.com/shentino/kotaka
 *
 * Copyright (C) 2018, 2019, 2020  <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <kernel/kernel.h>
#include <kernel/rsrc.h>
#include <kotaka/assert.h>
#include <kotaka/log.h>
#include <kotaka/paths/system.h>
#include <kotaka/privilege.h>
#include <status.h>
#include <type.h>

#define MODULE_BOOT_TICKS 1000000000

inherit SECOND_AUTO;
inherit UTILITY_COMPILE;
inherit LIB_SYSTEM;
inherit "~/lib/struct/list";

mapping modules;

private void scramble(mixed *arr)
{
	int sz;
	int i;

	sz = sizeof(arr);

	for (i = 0; i < sz; i++) {
		int j;
		mixed tmp;

		j = random(sz);

		tmp = arr[i];
		arr[i] = arr[j];
		arr[j] = tmp;
	}
}

private void freeze_module(string module)
{
	KERNELD->rsrc_set_limit(module, "objects", 0);
}

private void thaw_module(string module)
{
	int sz;
	string *resources;

	resources = KERNELD->query_resources();

	for (sz = sizeof(resources); --sz >= 0; ) {
		KERNELD->rsrc_set_limit(module, resources[sz], -1);
	}
}

private void send_module_boot_signal(string module)
{
	int sz;
	string *others;

	others = map_indices(modules);
	others -= ({ module });
	others |= ({ "System" });
	scramble(others);

	for (sz = sizeof(others) - 1; sz >= 0; --sz) {
		if (modules[others[sz]] != 1) {
			continue;
		}

		catch {
			object initd;

			if (initd = find_object(initd_of(others[sz]))) {
				initd->booted_module(module);
			} else {
				call_out("shutdown_module", 0, module);
			}
		}
	}
}

private void send_module_shutdown_signal(string module)
{
	int sz;
	string *others;

	others = map_indices(modules);
	others -= ({ module });
	others |= ({ "System" });
	scramble(others);

	for (sz = sizeof(others) - 1; sz >= 0; --sz) {
		if (modules[others[sz]] != 1) {
			continue;
		}

		catch {
			object initd;

			if (initd = find_object(initd_of(others[sz]))) {
				initd->shutdown_module(module);
			} else {
				call_out("shutdown_module", 0, module);
			}
		}
	}
}

private void purge_objects(string module)
{
	rlimits (0; -1) {
		mixed **list;

		list = OBJECTD->query_program_indices();

		while (!list_empty(list)) {
			int index;
			object pinfo;
			string path;

			index = list_front(list);
			list_pop_front(list);

			pinfo = OBJECTD->query_program_info(index);

			if (!pinfo) {
				continue;
			}

			if (pinfo->query_destructed()) {
				continue;
			}

			path = pinfo->query_path();

			if (DRIVER->creator(path) != module) {
				/* not theirs */
{'fraction_non_alphanumeric': 0.1394169835234474, 'fraction_numerical': 0.011723700887198986, 'mean_word_length': 3.5912727272727274, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '493823', 'n_tokens_mistral': 2508, 'n_tokens_neox': 2202, 'n_words': 630}