summaryrefslogtreecommitdiffstats
path: root/include/libcgroup/tasks.h
diff options
context:
space:
mode:
authorJan Safranek <jsafrane@redhat.com>2010-03-12 16:50:20 +0100
committerDhaval Giani <dhaval.giani@gmail.com>2010-03-21 22:02:01 +0100
commited0881d91408000d6ea5e4f73b49acf2615df9f9 (patch)
tree86148053ea4208f9299877444283ef89de4a18de /include/libcgroup/tasks.h
parent4f6e409bad2dfa94a4245f7ea612b91a9baed2b7 (diff)
downloadlibcg-ed0881d91408000d6ea5e4f73b49acf2615df9f9.tar.gz
libcg-ed0881d91408000d6ea5e4f73b49acf2615df9f9.tar.xz
libcg-ed0881d91408000d6ea5e4f73b49acf2615df9f9.zip
Split header file III
Changelog: - since there are no global macros, base.h is gone - since there is no base.h, all headers need to include <features.h> to get __BEGIN_DECLS - new init.h with cgroup_init() and cgroup_get_subsys_mount_point() - new error.h with error handling enum and related stuff - use #ifndef _LIBCGROUP_*_H instead _LIBCG_*_H in header guards - fix few checkpatch complaints (long lines, whitespaces, ...) The patch includes Makefile and .spec changes. I tested it compiles, make dist produces tarball with all headers, so does also the rpm. 'make' should automatically catch all changes in new headers and recompile dependent (=all) sources when any header changes. libcgroup.h - does not declare anything, it just includes all the other files. In future, it might contain base of doxygen documentation (some introduction etc.) libcgroup/error.h - the big enum with errors + error related functions libcgroup/init.h - libcgroup_init() and cgroup_get_subsys_mount_point() libcgroup/config.h - configuration reading/unloading libcgroup/groups.h - group manipulation stuff (create/modify/delete/free, incl. controllers and get/set values) + definition of struct cgroup (=must be included by libcgroup/tasks.h, which needs it) libcgroup/iterators.h - various walks, *_begin/next/end libcgroup/tasks.h - task classification, incl. rules cache manipulation In addition, I probably removed some #includes, which are not needed now when looking for the minimal #include set to build the project. I also hope I did not miss any function declaration or macro... Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
Diffstat (limited to 'include/libcgroup/tasks.h')
-rw-r--r--include/libcgroup/tasks.h126
1 files changed, 126 insertions, 0 deletions
diff --git a/include/libcgroup/tasks.h b/include/libcgroup/tasks.h
new file mode 100644
index 0000000..0bd4fb1
--- /dev/null
+++ b/include/libcgroup/tasks.h
@@ -0,0 +1,126 @@
+#ifndef _LIBCGROUP_TASKS_H
+#define _LIBCGROUP_TASKS_H
+
+#include <libcgroup/groups.h>
+
+#include <features.h>
+#include <stdbool.h>
+
+__BEGIN_DECLS
+
+/* Flags for cgroup_change_cgroup_uid_gid() */
+enum cgflags {
+ CGFLAG_USECACHE = 0x01,
+};
+
+enum cgroup_daemon_type {
+ CGROUP_DAEMON_UNCHANGE_CHILDREN = 0x1,
+};
+
+int cgroup_attach_task(struct cgroup *cgroup);
+int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid);
+
+/**
+ * Changes the cgroup of a program based on the rules in the config file.
+ * If a rule exists for the given UID, GID or PROCESS NAME, then the given
+ * PID is placed into the correct group. By default, this function parses
+ * the configuration file each time it is called.
+ *
+ * The flags can alter the behavior of this function:
+ * CGFLAG_USECACHE: Use cached rules instead of parsing the config file
+ *
+ * This function may NOT be thread safe.
+ * @param uid The UID to match
+ * @param gid The GID to match
+ * @param procname The PROCESS NAME to match
+ * @param pid The PID of the process to move
+ * @param flags Bit flags to change the behavior, as defined above
+ * @return 0 on success, > 0 on error
+ * TODO: Determine thread-safeness and fix of not safe.
+ */
+int cgroup_change_cgroup_flags(const uid_t uid, const gid_t gid,
+ char *procname, const pid_t pid, const int flags);
+
+/**
+ * Changes the cgroup of a program based on the rules in the config file. If a
+ * rule exists for the given UID or GID, then the given PID is placed into the
+ * correct group. By default, this function parses the configuration file each
+ * time it is called.
+ *
+ * The flags can alter the behavior of this function:
+ * CGFLAG_USECACHE: Use cached rules instead of parsing the config file
+ *
+ * This function may NOT be thread safe.
+ * @param uid The UID to match
+ * @param gid The GID to match
+ * @param pid The PID of the process to move
+ * @param flags Bit flags to change the behavior, as defined above
+ * @return 0 on success, > 0 on error
+ * TODO: Determine thread-safeness and fix if not safe.
+ */
+int cgroup_change_cgroup_uid_gid_flags(const uid_t uid, const gid_t gid,
+ const pid_t pid, const int flags);
+
+/**
+ * Provides backwards-compatibility with older versions of the API. This
+ * function is deprecated, and cgroup_change_cgroup_uid_gid_flags() should be
+ * used instead. In fact, this function simply calls the newer one with flags
+ * set to 0 (none).
+ * @param uid The UID to match
+ * @param gid The GID to match
+ * @param pid The PID of the process to move
+ * @return 0 on success, > 0 on error
+ */
+int cgroup_change_cgroup_uid_gid(uid_t uid, gid_t gid, pid_t pid);
+
+/**
+ * Changes the cgroup of a program based on the path provided. In this case,
+ * the user must already know into which cgroup the task should be placed and
+ * no rules will be parsed.
+ *
+ * returns 0 on success.
+ */
+int cgroup_change_cgroup_path(char *path, pid_t pid, char *controllers[]);
+
+/**
+ * Print the cached rules table. This function should be called only after
+ * first calling cgroup_parse_config(), but it will work with an empty rule
+ * list.
+ * @param fp The file stream to print to
+ */
+void cgroup_print_rules_config(FILE *fp);
+
+/**
+ * Reloads the rules list, using the given configuration file. This function
+ * is probably NOT thread safe (calls cgroup_parse_rules_config()).
+ * @return 0 on success, > 0 on failure
+ */
+int cgroup_reload_cached_rules(void);
+
+/**
+ * Initializes the rules cache.
+ * @return 0 on success, > 0 on failure
+ */
+int cgroup_init_rules_cache(void);
+
+/**
+ * Get the current cgroup path where the task specified by pid_t pid
+ * has been classified
+ */
+int cgroup_get_current_controller_path(pid_t pid, const char *controller,
+ char **current_path);
+
+/**
+ * Register the unchanged process to a cgrulesengd daemon.
+ * If the daemon does not work, this function returns 0 as success.
+ * @param pid: The process id
+ * @param flags Bit flags to change the behavior, as defined above
+ * @return 0 on success, > 0 on error.
+ */
+int cgroup_register_unchanged_process(pid_t pid, int flags);
+
+__END_DECLS
+
+#endif /* _LIBCGROUP_TASKS_H */
+
+