2010-08-17 03:33:07 +02:00
|
|
|
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
2010-06-21 23:27:18 +02:00
|
|
|
|
2012-07-18 19:07:51 +02:00
|
|
|
#pragma once
|
2010-06-21 23:27:18 +02:00
|
|
|
|
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2010 Lennart Poettering
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
2012-04-12 00:20:58 +02:00
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2010-06-21 23:27:18 +02:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd 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
|
2012-04-12 00:20:58 +02:00
|
|
|
Lesser General Public License for more details.
|
2010-06-21 23:27:18 +02:00
|
|
|
|
2012-04-12 00:20:58 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2010-06-21 23:27:18 +02:00
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2010-07-11 00:50:49 +02:00
|
|
|
#include <stdio.h>
|
2010-07-12 18:16:44 +02:00
|
|
|
#include <dirent.h>
|
2010-07-11 00:50:49 +02:00
|
|
|
|
|
|
|
#include "set.h"
|
2011-03-17 04:02:35 +01:00
|
|
|
#include "def.h"
|
2010-06-21 23:27:18 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
/* A bit mask of well known cgroup controllers */
|
|
|
|
typedef enum CGroupControllerMask {
|
|
|
|
CGROUP_CPU = 1,
|
|
|
|
CGROUP_CPUACCT = 2,
|
|
|
|
CGROUP_BLKIO = 4,
|
|
|
|
CGROUP_MEMORY = 8,
|
|
|
|
CGROUP_DEVICE = 16
|
|
|
|
} CGroupControllerMask;
|
|
|
|
|
2013-04-30 00:15:30 +02:00
|
|
|
/*
|
|
|
|
* General rules:
|
|
|
|
*
|
|
|
|
* We accept named hierarchies in the syntax "foo" and "name=foo".
|
|
|
|
*
|
|
|
|
* We expect that named hierarchies do not conflict in name with a
|
|
|
|
* kernel hierarchy, modulo the "name=" prefix.
|
|
|
|
*
|
|
|
|
* We always generate "normalized" controller names, i.e. without the
|
|
|
|
* "name=" prefix.
|
|
|
|
*
|
|
|
|
* We require absolute cgroup paths. When returning, we will always
|
|
|
|
* generate paths with multiple adjacent / removed.
|
|
|
|
*/
|
|
|
|
|
2010-07-11 00:50:49 +02:00
|
|
|
int cg_enumerate_processes(const char *controller, const char *path, FILE **_f);
|
|
|
|
int cg_read_pid(FILE *f, pid_t *_pid);
|
|
|
|
|
2010-07-12 18:16:44 +02:00
|
|
|
int cg_enumerate_subgroups(const char *controller, const char *path, DIR **_d);
|
|
|
|
int cg_read_subgroup(DIR *d, char **fn);
|
|
|
|
|
2011-03-03 23:55:30 +01:00
|
|
|
int cg_kill(const char *controller, const char *path, int sig, bool sigcont, bool ignore_self, Set *s);
|
|
|
|
int cg_kill_recursive(const char *controller, const char *path, int sig, bool sigcont, bool ignore_self, bool remove, Set *s);
|
2010-07-12 18:16:44 +02:00
|
|
|
int cg_kill_recursive_and_wait(const char *controller, const char *path, bool remove);
|
2010-06-21 23:27:18 +02:00
|
|
|
|
2013-01-12 04:24:12 +01:00
|
|
|
int cg_migrate(const char *cfrom, const char *pfrom, const char *cto, const char *pto, bool ignore_self);
|
|
|
|
int cg_migrate_recursive(const char *cfrom, const char *pfrom, const char *cto, const char *pto, bool ignore_self, bool remove);
|
2010-07-12 18:16:44 +02:00
|
|
|
|
|
|
|
int cg_split_spec(const char *spec, char **controller, char **path);
|
|
|
|
int cg_join_spec(const char *controller, const char *path, char **spec);
|
2013-04-16 04:36:06 +02:00
|
|
|
int cg_mangle_path(const char *path, char **result);
|
2010-06-21 23:27:18 +02:00
|
|
|
|
|
|
|
int cg_get_path(const char *controller, const char *path, const char *suffix, char **fs);
|
2012-04-14 02:15:13 +02:00
|
|
|
int cg_get_path_and_check(const char *controller, const char *path, const char *suffix, char **fs);
|
2013-04-16 04:36:06 +02:00
|
|
|
|
|
|
|
int cg_pid_get_path(const char *controller, pid_t pid, char **path);
|
2010-06-21 23:27:18 +02:00
|
|
|
|
|
|
|
int cg_trim(const char *controller, const char *path, bool delete_root);
|
2010-07-12 18:16:44 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
int cg_rmdir(const char *controller, const char *path);
|
2010-06-21 23:27:18 +02:00
|
|
|
int cg_delete(const char *controller, const char *path);
|
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
int cg_create(const char *controller, const char *path);
|
2010-06-21 23:27:18 +02:00
|
|
|
int cg_attach(const char *controller, const char *path, pid_t pid);
|
|
|
|
int cg_create_and_attach(const char *controller, const char *path, pid_t pid);
|
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
int cg_set_attribute(const char *controller, const char *path, const char *attribute, const char *value);
|
|
|
|
|
2010-06-21 23:27:18 +02:00
|
|
|
int cg_set_group_access(const char *controller, const char *path, mode_t mode, uid_t uid, gid_t gid);
|
2013-06-27 04:14:27 +02:00
|
|
|
int cg_set_task_access(const char *controller, const char *path, mode_t mode, uid_t uid, gid_t gid);
|
2010-06-21 23:27:18 +02:00
|
|
|
|
|
|
|
int cg_install_release_agent(const char *controller, const char *agent);
|
|
|
|
|
|
|
|
int cg_is_empty(const char *controller, const char *path, bool ignore_self);
|
2012-12-23 11:56:13 +01:00
|
|
|
int cg_is_empty_by_spec(const char *spec, bool ignore_self);
|
2010-06-21 23:27:18 +02:00
|
|
|
int cg_is_empty_recursive(const char *controller, const char *path, bool ignore_self);
|
|
|
|
|
2013-04-16 04:36:06 +02:00
|
|
|
int cg_get_root_path(char **path);
|
2013-04-15 14:05:00 +02:00
|
|
|
|
2013-04-16 04:36:06 +02:00
|
|
|
int cg_path_get_session(const char *path, char **session);
|
2013-04-23 04:10:13 +02:00
|
|
|
int cg_path_get_owner_uid(const char *path, uid_t *uid);
|
2013-04-15 14:05:00 +02:00
|
|
|
int cg_path_get_unit(const char *path, char **unit);
|
|
|
|
int cg_path_get_user_unit(const char *path, char **unit);
|
2013-04-16 04:36:06 +02:00
|
|
|
int cg_path_get_machine_name(const char *path, char **machine);
|
2013-06-21 01:46:27 +02:00
|
|
|
int cg_path_get_slice(const char *path, char **slice);
|
2013-04-16 04:36:06 +02:00
|
|
|
|
|
|
|
int cg_pid_get_path_shifted(pid_t pid, char **root, char **cgroup);
|
2013-04-15 14:05:00 +02:00
|
|
|
|
2013-04-16 04:36:06 +02:00
|
|
|
int cg_pid_get_session(pid_t pid, char **session);
|
2013-04-23 04:10:13 +02:00
|
|
|
int cg_pid_get_owner_uid(pid_t pid, uid_t *uid);
|
2012-05-30 22:25:01 +02:00
|
|
|
int cg_pid_get_unit(pid_t pid, char **unit);
|
2013-01-17 18:55:05 +01:00
|
|
|
int cg_pid_get_user_unit(pid_t pid, char **unit);
|
2013-04-16 04:36:06 +02:00
|
|
|
int cg_pid_get_machine_name(pid_t pid, char **machine);
|
2013-06-21 01:46:27 +02:00
|
|
|
int cg_pid_get_slice(pid_t pid, char **slice);
|
2011-03-14 23:13:57 +01:00
|
|
|
|
2013-04-16 04:36:06 +02:00
|
|
|
int cg_path_decode_unit(const char *cgroup, char **unit);
|
2013-01-18 07:13:27 +01:00
|
|
|
|
2012-04-16 19:14:11 +02:00
|
|
|
char **cg_shorten_controllers(char **controllers);
|
2013-01-19 00:59:19 +01:00
|
|
|
|
|
|
|
int cg_controller_from_attr(const char *attr, char **controller);
|
2013-04-23 04:10:13 +02:00
|
|
|
|
|
|
|
char *cg_escape(const char *p);
|
2013-05-03 04:51:50 +02:00
|
|
|
char *cg_unescape(const char *p) _pure_;
|
2013-04-25 00:01:29 +02:00
|
|
|
|
|
|
|
bool cg_controller_is_valid(const char *p, bool allow_named);
|
2013-06-17 21:33:26 +02:00
|
|
|
|
|
|
|
int cg_slice_to_path(const char *unit, char **ret);
|
2013-06-27 04:14:27 +02:00
|
|
|
|
|
|
|
int cg_create_with_mask(CGroupControllerMask mask, const char *path);
|
|
|
|
int cg_attach_with_mask(CGroupControllerMask mask, const char *path, pid_t pid);
|
2013-07-01 00:03:57 +02:00
|
|
|
int cg_attach_many_with_mask(CGroupControllerMask mask, const char *path, Set* pids);
|
2013-06-27 04:14:27 +02:00
|
|
|
int cg_migrate_with_mask(CGroupControllerMask mask, const char *from, const char *to);
|
|
|
|
int cg_trim_with_mask(CGroupControllerMask mask, const char *path, bool delete_root);
|
|
|
|
|
|
|
|
CGroupControllerMask cg_mask_supported(void);
|