]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgroup: Define NO_UID_GID.
authorJan Safranek <jsafrane@redhat.com>
Wed, 30 Nov 2011 14:41:53 +0000 (15:41 +0100)
committerJan Safranek <jsafrane@redhat.com>
Tue, 6 Dec 2011 09:42:13 +0000 (10:42 +0100)
Group control or task file owner should have UID/GID set to NO_UID_GID to
distinguish permissions which were set in config file from undefined
values. In the end, NO_UID_GID is transtated to UID/GID 0, so users
won't see any difference.

This will allow subsequent patches to set default owners of files/directories if
the group definition itself did not contain perm {} section.

Signed-off-by: Jan Safranek <jsafrane@redhat.com>
include/libcgroup/groups.h
src/api.c
src/wrapper.c

index f375a824cea3e4f69cf0eff878b797d91a841f65..39596a122712c5cf465ee7f66eba2cd5a2d6f746 100644 (file)
@@ -121,6 +121,11 @@ struct cgroup_controller;
  */
 #define NO_PERMS (-1U)
 
+/**
+ * Uninitialized UID/GID used for task/control files.
+ */
+#define NO_UID_GID (-1U)
+
 /**
  * Allocate new cgroup structure. This function itself does not create new
  * control group in kernel, only new <tt>struct cgroup</tt> inside libcgroup!
index d3aaa45f42e7cebd1507ad982b19ba5e67f27840..0c55f1ab3a276e84cdf792d89764df681b8c4524 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -122,6 +122,14 @@ const char const *cgroup_strerror_codes[] = {
 
 static const char const *cgroup_ignored_tasks_files[] = { "tasks", NULL };
 
+static int cg_chown(const char *filename, uid_t owner, gid_t group)
+{
+       if (owner == NO_UID_GID)
+               owner = 0;
+       if (group == NO_UID_GID)
+               group = 0;
+       return chown(filename, owner, group);
+}
 static int cg_chown_file(FTS *fts, FTSENT *ent, uid_t owner, gid_t group)
 {
        int ret = 0;
@@ -139,7 +147,7 @@ static int cg_chown_file(FTS *fts, FTSENT *ent, uid_t owner, gid_t group)
        case FTS_DP:
        case FTS_F:
        case FTS_DEFAULT:
-               ret = chown(filename, owner, group);
+               ret = cg_chown(filename, owner, group);
                break;
        }
        if (ret < 0) {
@@ -1613,7 +1621,7 @@ int cgroup_create_cgroup(struct cgroup *cgroup, int ignore_ownership)
                                error = ECGOTHER;
                                goto err;
                        }
-                       error = chown(path, cgroup->tasks_uid,
+                       error = cg_chown(path, cgroup->tasks_uid,
                                                        cgroup->tasks_gid);
                        if (!error && cgroup->task_fperm != NO_PERMS)
                                error = cg_chmod_path(path, cgroup->task_fperm,
index 95be969678708df33f179134f25971c57e6a3c65..50b8013e5f1883aa63f17f20c04e4a8202ca4b75 100644 (file)
@@ -29,6 +29,8 @@
 static void init_cgroup(struct cgroup *cgroup)
 {
        cgroup->task_fperm = cgroup->control_fperm = cgroup->control_dperm = NO_PERMS;
+       cgroup->control_gid = cgroup->control_uid = cgroup->tasks_gid =
+                       cgroup->tasks_uid = NO_UID_GID;
 }
 
 void init_cgroup_table(struct cgroup *cgroups, size_t count)