chiark / gitweb /
Detect running cgroup controller.
authorSven Eden <yamakuzure@gmx.net>
Thu, 16 Feb 2017 05:16:10 +0000 (06:16 +0100)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 09:23:13 +0000 (10:23 +0100)
elogind has to run on any system, no matter which init system is in
control of the cgroups. So instead of hardcoding "name=foo",
configure now greps 1: in /proc/self/cgroup - which is hopefully
the right choice. (Well, to be honest, if it isn't, something is
really wrong with the running system...)

Makefile.am
configure.ac
src/basic/cgroup-util.c
src/basic/def.h

index fe421287a2c4163bf90f1115cfb5ac6fbe298efd..0d2f986575dbad649e9bb3f86c59d40ab9a1f908 100644 (file)
@@ -55,6 +55,7 @@ zshcompletiondir=@zshcompletiondir@
 systemsleepdir=$(pkglibexecdir)/sleep.d
 systemshutdowndir=$(pkglibexecdir)/shutdown.d
 
+CGROUP_CONTROLLER=@cgroup_controller@
 PKTTYAGENT=$(bindir)/pkttyagent
 
 # Our own, non-special dirs
@@ -68,9 +69,11 @@ factory_pamdir = $(datadir)/factory/etc/pam.d
 
 # And these are the special ones for /
 rootprefix=@rootprefix@
+rootlibdir=@rootlibdir@
 rootbindir=$(rootprefix)/bin
 rootlibexecdir=$(rootprefix)/lib/elogind
 
+
 EXTRA_DIST =
 BUILT_SOURCES =
 INSTALL_EXEC_HOOKS =
@@ -119,6 +122,7 @@ CLEANFILES = $(BUILT_SOURCES) \
 AM_CPPFLAGS = \
        -include $(top_builddir)/config.h \
        -DPKGSYSCONFDIR=\"$(pkgsysconfdir)\" \
+       -DELOGIND_CGROUP_CONTROLLER=\"$(CGROUP_CONTROLLER)\" \
        -DELOGIND_CGROUP_AGENT_PATH=\"$(rootlibexecdir)/elogind-cgroups-agent\" \
        -DROOTPREFIX=\"$(rootprefix)\" \
        -DUDEVLIBEXECDIR=\"$(udevlibexecdir)\" \
index 351dda27e46d7073494cce51beabf69e358d27dc..5da0e12cab7f56729fd694d75c9a9706bfc48468 100644 (file)
@@ -109,6 +109,16 @@ if test -z "$GPERF" ; then
         AC_MSG_ERROR([*** gperf not found])
 fi
 
+
+# ------------------------------------------------------------------------------
+# Find running cgroup controller
+with_cgroupctrl=
+AS_IF(  [test -f /proc/self/cgroup],
+        [with_cgroupctrl=`grep "^1:" /proc/self/cgroup | cut -d ':' -f 2`])
+AS_IF(  [test -z "$with_cgroupctrl"],
+        AC_MSG_ERROR([No running cgroup controller found]))
+
+
 # ------------------------------------------------------------------------------
 address_sanitizer_cflags=
 address_sanitizer_cppflags=
@@ -691,6 +701,7 @@ AC_SUBST([pamlibdir], [$with_pamlibdir])
 AC_SUBST([pamconfdir], [$with_pamconfdir])
 AC_SUBST([rootprefix], [$with_rootprefix])
 AC_SUBST([rootlibdir], [$with_rootlibdir])
+AC_SUBST([cgroup_controller], [$with_cgroupctrl])
 
 AC_CONFIG_FILES([
         Makefile
@@ -712,6 +723,7 @@ AC_MSG_RESULT([
         test coverage:           ${have_coverage}
         Split /usr:              ${enable_split_usr}
         extra debugging:         ${enable_debug}
+        cgroup controller:       ${with_cgroupctrl}
 
         prefix:                  ${prefix}
         rootprefix:              ${with_rootprefix}
index cd5db6f69c1ab46ed94efdb01bc43a12217a6766..92d09f0b5cf8248dbeae92d4dc3b0d681e396519 100644 (file)
@@ -570,7 +570,7 @@ static int controller_is_accessible(const char *controller) {
                  * the unified hierarchy. */
 
                 if (streq(controller, ELOGIND_CGROUP_CONTROLLER))
-                return 0;
+                        return 0;
 
                 if (startswith(controller, "name="))
                         return -EOPNOTSUPP;
@@ -581,8 +581,8 @@ static int controller_is_accessible(const char *controller) {
                 dn = controller_to_dirname(controller);
                 cc = strjoina("/sys/fs/cgroup/", dn);
 
-        if (laccess(cc, F_OK) < 0)
-                return -errno;
+                if (laccess(cc, F_OK) < 0)
+                        return -errno;
         }
 
         return 0;
@@ -811,11 +811,11 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
         if (unified < 0)
                 return unified;
         if (unified == 0) {
-        if (controller) {
-                if (!cg_controller_is_valid(controller))
-                        return -EINVAL;
-        } else
-                controller = ELOGIND_CGROUP_CONTROLLER;
+                if (controller) {
+                        if (!cg_controller_is_valid(controller))
+                                return -EINVAL;
+                } else
+                        controller = ELOGIND_CGROUP_CONTROLLER;
 
                 cs = strlen(controller);
         }
@@ -840,29 +840,29 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
                                 continue;
                 } else {
                         char *l;
-                size_t k;
-                const char *word, *state;
-                bool found = false;
+                        size_t k;
+                        const char *word, *state;
+                        bool found = false;
 
-                l = strchr(line, ':');
-                if (!l)
-                        continue;
+                        l = strchr(line, ':');
+                        if (!l)
+                                continue;
 
-                l++;
-                e = strchr(l, ':');
-                if (!e)
-                        continue;
+                        l++;
+                        e = strchr(l, ':');
+                        if (!e)
+                                continue;
 
-                *e = 0;
-                FOREACH_WORD_SEPARATOR(word, k, l, ",", state) {
-                        if (k == cs && memcmp(word, controller, cs) == 0) {
-                                found = true;
-                                break;
+                        *e = 0;
+                        FOREACH_WORD_SEPARATOR(word, k, l, ",", state) {
+                                if (k == cs && memcmp(word, controller, cs) == 0) {
+                                        found = true;
+                                        break;
+                                }
                         }
-                }
 
-                if (!found)
-                        continue;
+                        if (!found)
+                                continue;
                 }
 
                 p = strdup(e + 1);
index 00f9f2f9478ae5ee44ec1158bcc61d7be189b136..f4ca626d22b490b36dbd657d8950d83270aea86c 100644 (file)
@@ -35,7 +35,9 @@
  * the watchdog pings will keep the loop busy. */
 #define DEFAULT_EXIT_USEC (30*USEC_PER_SEC)
 
-#define ELOGIND_CGROUP_CONTROLLER "name=elogind"
+#ifndef ELOGIND_CGROUP_CONTROLLER
+#  define ELOGIND_CGROUP_CONTROLLER "name=elogind"
+#endif
 
 #define SIGNALS_CRASH_HANDLER SIGSEGV,SIGILL,SIGFPE,SIGBUS,SIGQUIT,SIGABRT
 #define SIGNALS_IGNORE SIGPIPE