> I would prefer a flag for your behaviour.
This is the patch with option for my behavior. Not sure about option name
though. Any comments?

---
Kernel may be configured with different options (like swap) and may or
may not have some group variables. This commit adds possibility to use
common cgconfig.conf between these machines with different compiled options.
Add new option (-T, --tolerate) which lets cgconfigparser skip failed
group variables.

Signed-off-by: Stanislav Fomichev <stfomic...@yandex-team.ru>
---
 include/libcgroup/config.h |  3 ++-
 src/api.c                  |  2 +-
 src/config.c               | 14 +++++++++++---
 src/tools/cgconfig.c       | 10 ++++++++--
 4 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/include/libcgroup/config.h b/include/libcgroup/config.h
index 43568e1cf8d0..a77c11e083ac 100644
--- a/include/libcgroup/config.h
+++ b/include/libcgroup/config.h
@@ -30,8 +30,9 @@ __BEGIN_DECLS
  * Load configuration file and mount and create control groups described there.
  * See cgconfig.conf man page for format of the file.
  * @param pathname Name of the configuration file to load.
+ * @param tolerate Tolerate non-fatal errors.
  */
-int cgroup_config_load_config(const char *pathname);
+int cgroup_config_load_config(const char *pathname, int tolerate);
 
 /**
  * Delete all control groups and unmount all hierarchies.
diff --git a/src/api.c b/src/api.c
index cd4e5b096b41..a252d0f99d67 100644
--- a/src/api.c
+++ b/src/api.c
@@ -1660,7 +1660,7 @@ int cgroup_create_cgroup(struct cgroup *cgroup, int 
ignore_ownership)
                         * ignore it specifically if they wish.
                         */
                        if (error) {
-                               cgroup_warn("Warning: failed to set %s: %s 
(%d)\n",
+                               cgroup_err("Error: failed to set %s: %s (%d)\n",
                                        path, cgroup_strerror(error), error);
                                retval = ECGCANTSETVALUE;
                                continue;
diff --git a/src/config.c b/src/config.c
index ac844a7ae30c..5c4161992434 100644
--- a/src/config.c
+++ b/src/config.c
@@ -723,7 +723,7 @@ out_err:
 /*
  * Actually create the groups once the parsing has been finished.
  */
-static int cgroup_config_create_groups(void)
+static int cgroup_config_create_groups(int tolerate)
 {
        int error = 0;
        int i;
@@ -733,6 +733,14 @@ static int cgroup_config_create_groups(void)
                error = cgroup_create_cgroup(cgroup, 0);
                cgroup_dbg("creating group %s, error %d\n", cgroup->name,
                        error);
+
+               /* if for some reason we couldn't set group value, just
+                * skip it with a warning */
+               if (tolerate && error == ECGCANTSETVALUE) {
+                       error = 0;
+                       continue;
+               }
+
                if (error)
                        return error;
        }
@@ -1083,7 +1091,7 @@ static void cgroup_config_sort_groups()
  * The main function which does all the setup of the data structures
  * and finally creates the cgroups
  */
-int cgroup_config_load_config(const char *pathname)
+int cgroup_config_load_config(const char *pathname, int tolerate)
 {
        int error;
        int namespace_enabled = 0;
@@ -1135,7 +1143,7 @@ int cgroup_config_load_config(const char *pathname)
                goto err_mnt;
 
        cgroup_config_apply_default();
-       error = cgroup_config_create_groups();
+       error = cgroup_config_create_groups(tolerate);
        cgroup_dbg("creating all cgroups now, error=%d\n", error);
        if (error)
                goto err_grp;
diff --git a/src/tools/cgconfig.c b/src/tools/cgconfig.c
index e8bb5a2e553b..eaa494865cb9 100644
--- a/src/tools/cgconfig.c
+++ b/src/tools/cgconfig.c
@@ -61,6 +61,7 @@ static void usage(int status, char *progname)
                "permissions\n");
        printf("  -t <tuid>:<tgid>              Default owner of the tasks "\
                "file\n");
+       printf("  -T, --tolerate                Tolerate non-fatal errors\n");
 }
 
 int main(int argc, char *argv[])
@@ -72,6 +73,7 @@ int main(int argc, char *argv[])
                {"load", 1, 0, 'l'},
                {"load-directory", 1, 0, 'L'},
                {"task", required_argument, NULL, 't'},
+               {"tolerate", 0, NULL, 'T' },
                {"admin", required_argument, NULL, 'a'},
                {"dperm", required_argument, NULL, 'd'},
                {"fperm", required_argument, NULL, 'f' },
@@ -85,6 +87,7 @@ int main(int argc, char *argv[])
        mode_t tasks_mode = NO_PERMS;
        int dirm_change = 0;
        int filem_change = 0;
+       int tolerate = 0;
        struct cgroup *default_group = NULL;
 
        cgroup_set_default_logger(-1);
@@ -98,7 +101,7 @@ int main(int argc, char *argv[])
        if (error)
                goto err;
 
-       while ((c = getopt_long(argc, argv, "hl:L:t:a:d:f:s:", options,
+       while ((c = getopt_long(argc, argv, "hl:L:t:Ta:d:f:s:", options,
                        NULL)) > 0) {
                switch (c) {
                case 'h':
@@ -141,6 +144,9 @@ int main(int argc, char *argv[])
                        if (error)
                                goto err;
                        break;
+               case 'T':
+                       tolerate = 1;
+                       break;
                case 's':
                        filem_change = 1;
                        error = parse_mode(optarg, &tasks_mode, argv[0]);
@@ -188,7 +194,7 @@ int main(int argc, char *argv[])
        }
 
        for (i = 0; i < cfg_files.count; i++) {
-               ret = cgroup_config_load_config(cfg_files.items[i]);
+               ret = cgroup_config_load_config(cfg_files.items[i], tolerate);
                if (ret) {
                        fprintf(stderr, "%s; error loading %s: %s\n", argv[0],
                                        cfg_files.items[i],
-- 
1.8.3.2

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to