]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
jail: Give a random UUID and use it for the cgroup
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Aug 2022 14:02:29 +0000 (14:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Aug 2022 14:02:29 +0000 (14:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/jail.c

index 3591c354d8f0fcecd814d72eaa35f36046f16b87..97decaa92c6438a7305c4e494179d3de40889747 100644 (file)
@@ -39,6 +39,9 @@
 // libseccomp
 #include <seccomp.h>
 
+// libuuid
+#include <uuid.h>
+
 #include <pakfire/arch.h>
 #include <pakfire/cgroup.h>
 #include <pakfire/jail.h>
@@ -67,6 +70,10 @@ struct pakfire_jail {
        struct pakfire* pakfire;
        int nrefs;
 
+       // A unique ID for each jail
+       uuid_t uuid;
+       char __uuid[UUID_STR_LEN];
+
        // Flags
        int flags;
 
@@ -211,6 +218,9 @@ PAKFIRE_EXPORT int pakfire_jail_create(struct pakfire_jail** jail,
        // Store flags
        j->flags = flags;
 
+       // Generate a random UUID
+       uuid_generate_random(j->uuid);
+
        DEBUG(j->pakfire, "Allocated new jail at %p\n", j);
 
        // Set default log callback
@@ -260,6 +270,13 @@ static int pakfire_jail_has_flag(struct pakfire_jail* jail, int flag) {
        return jail->flags & flag;
 }
 
+static const char* pakfire_jail_uuid(struct pakfire_jail* jail) {
+       if (*jail->__uuid)
+               uuid_unparse_lower(jail->uuid, jail->__uuid);
+
+       return jail->__uuid;
+}
+
 // Resource Limits
 
 PAKFIRE_EXPORT int pakfire_jail_nice(struct pakfire_jail* jail, int nice) {
@@ -1302,10 +1319,11 @@ static int __pakfire_jail_exec(struct pakfire_jail* jail, const char* argv[]) {
        if (jail->cgroup) {
                args.flags |= CLONE_INTO_CGROUP;
 
-#warning TODO randomize the name
+               // Fetch our UUID
+               const char* uuid = pakfire_jail_uuid(jail);
 
                // Create a temporary cgroup
-               r = pakfire_cgroup_child(&ctx.cgroup, jail->cgroup, "jail", 0);
+               r = pakfire_cgroup_child(&ctx.cgroup, jail->cgroup, uuid, 0);
                if (r) {
                        ERROR(jail->pakfire, "Could not create cgroup for jail: %m\n");
                        goto ERROR;