cgconfig service fails when something else mounts cgroup hierarchies during
boot (e.g. systemd). Therefore we should allow cgconfig.conf to have no
'mount' section -> it's up to admin to ensure that controllers are mounted as
needed.

Because 'group' section is already optional, with this patch cgconfigparser
will accept empty configuration file. This is probably the best default
config for distros with systemd.

Changelog:
  - fixed case with empty config file and no mounted controllers
  - reworked the if conditions to be more clear

Signed-off-by: Jan Safranek <jsafr...@redhat.com>
---

 doc/man/cgconfig.conf.5 |   13 +++++++++++--
 src/config.c            |   17 +++++++++--------
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/doc/man/cgconfig.conf.5 b/doc/man/cgconfig.conf.5
index d57fb44..4a82b95 100644
--- a/doc/man/cgconfig.conf.5
+++ b/doc/man/cgconfig.conf.5
@@ -12,8 +12,8 @@ The file consists of
 .I mount
 and
 .I group
-sections. These sections can be in arbitrary order. Any line starting
-with '#' is considered a comment line and is ignored.
+sections. These sections can be in arbitrary order and both are optional.
+Any line starting with '#' is considered a comment line and is ignored.
 .LP
 .I mount
 section has this form:
@@ -53,6 +53,11 @@ controller shall be mounted. The directory is created
 automatically on cgconfig service startup if it does not exist and
 is deleted on service shutdown.
 .LP
+
+If no
+.I mount
+section is specified, no controllers are mounted.
+
 .I group
 section has this form:
 .RS
@@ -174,6 +179,10 @@ created. If it is enclosed in double quotes `"', it can 
contain spaces
 and other special characters.
 .RE
 
+If no
+.I group
+section is specified, no groups are created.
+
 .\"********************************************"
 .SH EXAMPLES
 .LP
diff --git a/src/config.c b/src/config.c
index f1873ea..0dd70d8 100644
--- a/src/config.c
+++ b/src/config.c
@@ -723,24 +723,25 @@ int cgroup_config_load_config(const char *pathname)
        mount_enabled = (config_mount_table[0].name[0] != '\0');
 
        /*
-        * The configuration should have either namespace or mount.
-        * Not both and not none.
+        * The configuration should have namespace or mount, not both.
         */
-       if (namespace_enabled == mount_enabled) {
+       if (namespace_enabled && mount_enabled) {
                free(config_cgroup_table);
                return ECGMOUNTNAMESPACE;
        }
 
-       /*
-        * We do not allow both mount and namespace sections in the
-        * same configuration file. So test for that
-        */
-
        error = cgroup_config_mount_fs();
        if (error)
                goto err_mnt;
 
        error = cgroup_init();
+       if (error == ECGROUPNOTMOUNTED && cgroup_table_index == 0) {
+               /*
+                * The config file seems to be empty.
+                */
+               error = 0;
+               goto err_mnt;
+       }
        if (error)
                goto err_mnt;
 


------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its 
next-generation tools to help Windows* and Linux* C/C++ and Fortran 
developers boost performance applications - including clusters. 
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to