A patch below, functionally identical to my previous. But this seems
neater, showing the intent more clearly: clearer that this is a "true"
bug in systemd.

Cheers, Paul
--
Paul Szabo   [email protected]   http://www.maths.usyd.edu.au/u/psz/
School of Mathematics and Statistics   University of Sydney    Australia
diff -r -U23 a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
--- a/src/basic/cgroup-util.c	2017-07-20 09:32:36.000000000 +1000
+++ b/src/basic/cgroup-util.c	2017-07-23 13:51:28.000000000 +1000
@@ -363,46 +363,60 @@
                         return r;
         }
 
         return ret;
 }
 
 int cg_migrate(
                 const char *cfrom,
                 const char *pfrom,
                 const char *cto,
                 const char *pto,
                 CGroupFlags flags) {
 
         bool done = false;
         _cleanup_set_free_ Set *s = NULL;
         int r, ret = 0;
         pid_t my_pid;
 
         assert(cfrom);
         assert(pfrom);
         assert(cto);
         assert(pto);
 
+        /*
+         * PSz 25 Oct 2015
+         * An empty "to" path is surely wrong
+         * (do not annoy cgroups that are not ours).
+         * PSz 23 Jul 2017
+         * Cannot happen anymore(?), see cg_migrate_recursive_fallback()
+         * below... log if it does!
+         */
+        if (!strlen(pto)) {
+                log_warning("PSz debug: cg_migrate skip from (%s)%s to (%s)%s", cfrom, pfrom, cto, pto);
+                return ret;
+        }
+        /* log_warning("PSz debug: cg_migrate do from (%s)%s to (%s)%s", cfrom, pfrom, cto, pto); */
+
         s = set_new(NULL);
         if (!s)
                 return -ENOMEM;
 
         my_pid = getpid();
 
         do {
                 _cleanup_fclose_ FILE *f = NULL;
                 pid_t pid = 0;
                 done = true;
 
                 r = cg_enumerate_processes(cfrom, pfrom, &f);
                 if (r < 0) {
                         if (ret >= 0 && r != -ENOENT)
                                 return r;
 
                         return ret;
                 }
 
                 while ((r = cg_read_pid(f, &pid)) > 0) {
 
                         /* This might do weird stuff if we aren't a
                          * single-threaded program. However, we
@@ -504,46 +518,62 @@
 int cg_migrate_recursive_fallback(
                 const char *cfrom,
                 const char *pfrom,
                 const char *cto,
                 const char *pto,
                 CGroupFlags flags) {
 
         int r;
 
         assert(cfrom);
         assert(pfrom);
         assert(cto);
         assert(pto);
 
         r = cg_migrate_recursive(cfrom, pfrom, cto, pto, flags);
         if (r < 0) {
                 char prefix[strlen(pto) + 1];
 
                 /* This didn't work? Then let's try all prefixes of the destination */
 
                 PATH_FOREACH_PREFIX(prefix, pto) {
                         int q;
 
+                        /*
+                         * PSz 23 Jul 2017
+                         * Skip an empty ("") prefix path: surely wrong,
+                         * do not annoy cgroups that are not ours.
+                         * Other comments:
+                         * - Why this "did not work so try something else"?
+                         * - Maybe should have used PATH_FOREACH_PREFIX_MORE
+                         *   for cleaner, more compact code.
+                         * - Should check cg_attach_fallback() also, and maybe
+                         *   review all other uses of PATH_FOREACH_PREFIX.
+                         */
+                        if (!strlen(prefix)) {
+                                /* log_warning("PSz debug: cg_migrate_recursive_fallback skip from (%s)%s to (%s) (empty prefix of %s)", cfrom, pfrom, cto, pto); */
+                                continue;
+                        }
+
                         q = cg_migrate_recursive(cfrom, pfrom, cto, prefix, flags);
                         if (q >= 0)
                                 return q;
                 }
         }
 
         return r;
 }
 
 static const char *controller_to_dirname(const char *controller) {
         const char *e;
 
         assert(controller);
 
         /* Converts a controller name to the directory name below
          * /sys/fs/cgroup/ we want to mount it to. Effectively, this
          * just cuts off the name= prefixed used for named
          * hierarchies, if it is specified. */
 
         e = startswith(controller, "name=");
         if (e)
                 return e;
 
_______________________________________________
Pkg-systemd-maintainers mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-systemd-maintainers

Reply via email to