예제 #1
0
파일: cgmanager.c 프로젝트: hallyn/pam-cgm
void cgm_clear_cgroup(const char *cg)
{
	int32_t recursive = 1;
	int32_t existed;

	if ( cgmanager_remove_sync(NULL, cgroup_manager, ctrl_list, cg, recursive, &existed) != 0) {
		NihError *nerr;
		nerr = nih_error_get();
		fprintf(stderr, "warning: call to remove(%s) failed: %s\n", cg, nerr->message);
		nih_free(nerr);
	}
}
예제 #2
0
/* Internal helper.  Must be called with the cgmanager dbus socket open */
static void cgm_remove_cgroup(const char *controller, const char *path)
{
	int existed;
	if ( cgmanager_remove_sync(NULL, cgroup_manager, controller,
				   path, CG_REMOVE_RECURSIVE, &existed) != 0) {
		NihError *nerr;
		nerr = nih_error_get();
		ERROR("call to cgmanager_remove_sync failed: %s", nerr->message);
		nih_free(nerr);
		ERROR("Error removing %s:%s", controller, path);
	}
	if (existed == -1)
		INFO("cgroup removal attempt: %s:%s did not exist", controller, path);
}
예제 #3
0
static void do_function(void *arguments)
{
	char path[100];
	int existed;
	char *value;
	bool err = false;

	if (!cgm_dbus_connect()) {
		fprintf(stderr, "Error connecting to dbus\n");
		return;
	}

	sprintf(path, "cgmtest-%d", gettid());

	if (connect_only) {
		if (cgmanager_create_sync(NULL, cgroup_manager, "freezer", path, &existed) != 0) {
			NihError *nerr = nih_error_get();
			fprintf(stderr, "Error creating freezer cgroup: %s\n", nerr->message);
			nih_free(nerr);
			err = true;
		}
		if (cgmanager_get_value_sync(NULL, cgroup_manager, "freezer", path, "freezer.state", &value) != 0) {
			NihError *nerr = nih_error_get();
			fprintf(stderr, "Error querying freezer cgroup: %s\n", nerr->message);
			nih_free(nerr);
			err = true;
		}
		if (cgmanager_remove_sync(NULL, cgroup_manager, "freezer", path, 1, &existed) != 0) {
			NihError *nerr = nih_error_get();
			fprintf(stderr, "Error removing freezer cgroup: %s\n", nerr->message);
			nih_free(nerr);
			err = true;
		}
	}
	cgm_dbus_disconnect();
	if (err) {
		fflush(stderr);
		exit(1);
	}
}
예제 #4
0
bool cgm_remove(const char *controller, const char *cg)
{
	/*
	 * tempting to make remove be recursive, but this is a filesystem,
	 * so best to opt for least surprise
	 */
	int32_t r = 0, e;

	if (!cgm_dbus_connect()) {
		return false;
	}

	if ( cgmanager_remove_sync(NULL, cgroup_manager, controller, cg, r, &e) != 0) {
		NihError *nerr;
		nerr = nih_error_get();
		fprintf(stderr, "call to remove (%s:%s) failed: %s\n", controller, cg, nerr->message);
		nih_free(nerr);
		cgm_dbus_disconnect();
		return false;
	}

	cgm_dbus_disconnect();
	return true;
}