I went through cgroup_dbg messages and increased they log level where I
found it appropriate. I am pretty sure I missed other important ones, this
is just a first attempt. Feel free to suggest additional messages.

Changelog:
  - fixed capital letters in few log messages

Signed-off-by: Peter Schiffer <pschi...@redhat.com>
---
 src/api.c    |   94 +++++++++++++++++++++++++++++++---------------------------
 src/config.c |    4 +-
 2 files changed, 52 insertions(+), 46 deletions(-)

diff --git a/src/api.c b/src/api.c
index 62ae6c2..f94aa86 100644
--- a/src/api.c
+++ b/src/api.c
@@ -173,7 +173,7 @@ static int cg_chown_recursive(char **path, uid_t owner, 
gid_t group)
                FTSENT *ent;
                ent = fts_read(fts);
                if (!ent) {
-                       cgroup_dbg("fts_read failed\n");
+                       cgroup_warn("Warning: fts_read failed\n");
                        break;
                }
                ret = cg_chown_file(fts, ent, owner, group);
@@ -388,7 +388,7 @@ static void cgroup_free_rule(struct cgroup_rule *r)
 
        /* Make sure our rule is not NULL, first. */
        if (!r) {
-               cgroup_dbg("Warning: Attempted to free NULL rule.\n");
+               cgroup_warn("Warning: attempted to free NULL rule\n");
                return;
        }
        if (r->procname) {
@@ -416,7 +416,7 @@ static void cgroup_free_rule_list(struct cgroup_rule_list 
*cg_rl)
 
        /* Make sure we're not freeing NULL memory! */
        if (!(cg_rl->head)) {
-               cgroup_dbg("Warning: Attempted to free NULL list.\n");
+               cgroup_warn("Warning: attempted to free NULL list\n");
                return;
        }
 
@@ -535,9 +535,8 @@ static int cgroup_parse_rules(bool cache, uid_t muid,
        pthread_rwlock_wrlock(&rl_lock);
        fp = fopen(CGRULES_CONF_FILE, "re");
        if (!fp) {
-               cgroup_dbg("Failed to open configuration file %s with"
-                               " error: %s\n", CGRULES_CONF_FILE,
-                               strerror(errno));
+               cgroup_err("Error: failed to open configuration file %s: %s\n",
+                               CGRULES_CONF_FILE, strerror(errno));
                last_errno = errno;
                ret = ECGOTHER;
                goto unlock;
@@ -567,7 +566,7 @@ static int cgroup_parse_rules(bool cache, uid_t muid,
                 * of it (begins with %), then we should skip this rule too.
                 */
                if (skipped && *itr == '%') {
-                       cgroup_dbg("Warning: Skipped child of invalid rule,"
+                       cgroup_warn("Warning: skipped child of invalid rule,"
                                        " line %d.\n", linenum);
                        continue;
                }
@@ -579,8 +578,8 @@ static int cgroup_parse_rules(bool cache, uid_t muid,
                skipped = false;
                i = sscanf(itr, "%s%s%s", key, controllers, destination);
                if (i != 3) {
-                       cgroup_dbg("Failed to parse configuration file on"
-                                       " line %d.\n", linenum);
+                       cgroup_err("Error: failed to parse configuration file"
+                                       " on line %d\n", linenum);
                        goto parsefail;
                }
                procname = strchr(key, ':');
@@ -590,8 +589,9 @@ static int cgroup_parse_rules(bool cache, uid_t muid,
                        len_username = procname - key - 1;
                        len_procname = strlen(procname);
                        if (len_procname < 0) {
-                               cgroup_dbg("Failed to parse configuration file"
-                                               " on line %d.\n", linenum);
+                               cgroup_err("Error: failed to parse"
+                                               " configuration file on line"
+                                               " %d\n", linenum);
                                goto parsefail;
                        }
                } else {
@@ -709,7 +709,7 @@ static int cgroup_parse_rules(bool cache, uid_t muid,
                 */
                newrule = calloc(1, sizeof(struct cgroup_rule));
                if (!newrule) {
-                       cgroup_dbg("Out of memory?  Error: %s\n",
+                       cgroup_err("Error: out of memory? Error was: %s\n",
                                strerror(errno));
                        last_errno = errno;
                        ret = ECGOTHER;
@@ -739,24 +739,25 @@ static int cgroup_parse_rules(bool cache, uid_t muid,
                /* Parse the controller list, and add that to newrule too. */
                stok_buff = strtok(controllers, ",");
                if (!stok_buff) {
-                       cgroup_dbg("Failed to parse controllers on line"
-                                       " %d\n", linenum);
+                       cgroup_err("Error: failed to parse controllers on"
+                                       " line %d\n", linenum);
                        goto destroyrule;
                }
 
                i = 0;
                do {
                        if (i >= MAX_MNT_ELEMENTS) {
-                               cgroup_dbg("Too many controllers listed"
-                                       " on line %d\n", linenum);
+                               cgroup_err("Error: too many controllers"
+                                       " listed on line %d\n", linenum);
                                goto destroyrule;
                        }
 
                        newrule->controllers[i] = strndup(stok_buff,
                                                        strlen(stok_buff) + 1);
                        if (!(newrule->controllers[i])) {
-                               cgroup_dbg("Out of memory?  Error was: %s\n",
-                                       strerror(errno));
+                               cgroup_err("Error: out of memory? "
+                                               "Error was: %s\n",
+                                               strerror(errno));
                                goto destroyrule;
                        }
                        i++;
@@ -1188,7 +1189,7 @@ static int __cgroup_attach_task_pid(char *path, pid_t tid)
        fclose(tasks);
        return 0;
 err:
-       cgroup_dbg("Error writing tid %d to %s:%s\n",
+       cgroup_warn("Warning: cannot write tid %d to %s:%s\n",
                        tid, path, strerror(errno));
        fclose(tasks);
        return ret;
@@ -1208,7 +1209,7 @@ int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t 
tid)
        int i, ret = 0;
 
        if (!cgroup_initialized) {
-               cgroup_dbg("libcgroup is not initialized\n");
+               cgroup_warn("Warning: libcgroup is not initialized\n");
                return ECGROUPNOTINITIALIZED;
        }
        if (!cgroup) {
@@ -1229,8 +1230,9 @@ int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t 
tid)
        } else {
                for (i = 0; i < cgroup->index; i++) {
                        if 
(!cgroup_test_subsys_mounted(cgroup->controller[i]->name)) {
-                               cgroup_dbg("subsystem %s is not mounted\n",
-                                       cgroup->controller[i]->name);
+                               cgroup_warn("Warning: subsystem %s is not "
+                                               "mounted\n",
+                                               cgroup->controller[i]->name);
                                return ECGROUPSUBSYSNOTMOUNTED;
                        }
                }
@@ -1420,7 +1422,7 @@ int cgroup_modify_cgroup(struct cgroup *cgroup)
 
        for (i = 0; i < cgroup->index; i++) {
                if (!cgroup_test_subsys_mounted(cgroup->controller[i]->name)) {
-                       cgroup_dbg("subsystem %s is not mounted\n",
+                       cgroup_warn("Warning: subsystem %s is not mounted\n",
                                cgroup->controller[i]->name);
                        return ECGROUPSUBSYSNOTMOUNTED;
                }
@@ -1634,8 +1636,8 @@ int cgroup_create_cgroup(struct cgroup *cgroup, int 
ignore_ownership)
                         * ignore it specifically if they wish.
                         */
                        if (error) {
-                               cgroup_dbg("failed to set %s: %s (%d)\n",
-                                       path,
+                               cgroup_warn("Warning: failed to set %s: "
+                                               "%s (%d)\n", path,
                                        cgroup_strerror(error), error);
                                retval = ECGCANTSETVALUE;
                                continue;
@@ -2500,8 +2502,8 @@ static int cg_prepare_cgroup(struct cgroup *cgroup, pid_t 
pid,
                                cptr = cgroup_add_controller(cgroup,
                                                cg_mount_table[j].name);
                                if (!cptr) {
-                                       cgroup_dbg("Adding controller '%s'"
-                                               " failed\n",
+                                       cgroup_warn("Warning: adding "
+                                               "controller '%s' failed\n",
                                                cg_mount_table[j].name);
                                        
pthread_rwlock_unlock(&cg_mount_table_lock);
                                        cgroup_free_controllers(cgroup);
@@ -2516,7 +2518,7 @@ static int cg_prepare_cgroup(struct cgroup *cgroup, pid_t 
pid,
                cgroup_dbg("Adding controller %s\n", controller);
                cptr = cgroup_add_controller(cgroup, controller);
                if (!cptr) {
-                       cgroup_dbg("Adding controller '%s' failed\n",
+                       cgroup_warn("Warning: adding controller '%s' failed\n",
                                controller);
                        cgroup_free_controllers(cgroup);
                        return ECGROUPNOTALLOWED;
@@ -2847,7 +2849,7 @@ int cgroup_change_cgroup_flags(uid_t uid, gid_t gid,
 
        /* We need to check this before doing anything else! */
        if (!cgroup_initialized) {
-               cgroup_dbg("libcgroup is not initialized\n");
+               cgroup_warn("Warning: libcgroup is not initialized\n");
                ret = ECGROUPNOTINITIALIZED;
                goto finished;
        }
@@ -2863,8 +2865,8 @@ int cgroup_change_cgroup_flags(uid_t uid, gid_t gid,
 
                /* The configuration file has an error!  We must exit now. */
                if (ret != -1 && ret != 0) {
-                       cgroup_dbg("Failed to parse the configuration"
-                               " rules.\n");
+                       cgroup_err("Error: failed to parse the configuration"
+                               " rules\n");
                        goto finished;
                }
 
@@ -2989,7 +2991,8 @@ int cgroup_change_cgroup_flags(uid_t uid, gid_t gid,
                ret = cgroup_change_cgroup_path(newdest,
                                pid, (const char * const *)tmp->controllers);
                if (ret) {
-                       cgroup_dbg("FAILED! (Error Code: %d)\n", ret);
+                       cgroup_warn("Warning: failed to apply the rule. "
+                                       "Error was: %d\n", ret);
                        goto finished;
                }
                cgroup_dbg("OK!\n");
@@ -3041,7 +3044,7 @@ int cgroup_change_cgroup_path(const char *dest, pid_t pid,
        struct cgroup cgroup;
 
        if (!cgroup_initialized) {
-               cgroup_dbg("libcgroup is not initialized\n");
+               cgroup_warn("Warning: libcgroup is not initialized\n");
                return ECGROUPNOTINITIALIZED;
        }
        memset(&cgroup, 0, sizeof(struct cgroup));
@@ -3052,7 +3055,8 @@ int cgroup_change_cgroup_path(const char *dest, pid_t pid,
        /* Add task to cgroup */
        ret = cgroup_attach_task_pid(&cgroup, pid);
        if (ret)
-               cgroup_dbg("cgroup_attach_task_pid failed:%d\n", ret);
+               cgroup_warn("Warning: cgroup_attach_task_pid failed: "
+                               "%d\n", ret);
        cgroup_free_controllers(&cgroup);
        return ret;
 }
@@ -3126,7 +3130,8 @@ int cgroup_reload_cached_rules(void)
        cgroup_dbg("Reloading cached rules from %s.\n", CGRULES_CONF_FILE);
        ret = cgroup_parse_rules(true, CGRULE_INVALID, CGRULE_INVALID, NULL);
        if (ret) {
-               cgroup_dbg("Error parsing configuration file \"%s\": %d.\n",
+               cgroup_warn("Warning: error parsing configuration "
+                               "file '%s': %d\n",
                        CGRULES_CONF_FILE, ret);
                ret = ECGRULESPARSEFAIL;
                goto finished;
@@ -3180,14 +3185,14 @@ int cgroup_get_current_controller_path(pid_t pid, const 
char *controller,
                return ECGOTHER;
 
        if (!cgroup_initialized) {
-               cgroup_dbg("libcgroup is not initialized\n");
+               cgroup_warn("Warning: libcgroup is not initialized\n");
                return ECGROUPNOTINITIALIZED;
        }
 
        ret = asprintf(&path, "/proc/%d/cgroup", pid);
        if (ret <= 0) {
-               cgroup_dbg("cannot allocate memory (/proc/pid/cgroup) ret %d\n",
-                       ret);
+               cgroup_warn("Warning: cannot allocate memory "
+                               "(/proc/pid/cgroup) ret %d\n", ret);
                return ret;
        }
 
@@ -3220,8 +3225,8 @@ int cgroup_get_current_controller_path(pid_t pid, const 
char *controller,
                 * disappear :)
                 */
                if (ret != 3) {
-                       cgroup_dbg("read failed for pid_cgroup_fd ret %d\n",
-                               ret);
+                       cgroup_warn("Warning: read failed for "
+                                       "pid_cgroup_fd ret %d\n", ret);
                        last_errno = errno;
                        ret = ECGOTHER;
                        goto done;
@@ -3406,7 +3411,7 @@ int cgroup_walk_tree_begin(const char *controller, const 
char *base_path,
        }
        ent = fts_read(entry->fts);
        if (!ent) {
-               cgroup_dbg("fts_read failed\n");
+               cgroup_warn("Warning: fts_read failed\n");
                fts_close(entry->fts);
                free(entry);
                *handle = NULL;
@@ -3544,7 +3549,7 @@ int cgroup_read_value_begin(const char *controller, const 
char *path,
                name);
        fp = fopen(stat_file, "re");
        if (!fp) {
-               cgroup_dbg("fopen failed\n");
+               cgroup_warn("Warning: fopen failed\n");
                last_errno = errno;
                *handle = NULL;
                return ECGOTHER;
@@ -3620,7 +3625,7 @@ int cgroup_read_stats_begin(const char *controller, const 
char *path,
 
        fp = fopen(stat_file, "re");
        if (!fp) {
-               cgroup_dbg("fopen failed\n");
+               cgroup_warn("Warning: fopen failed\n");
                return ECGINVAL;
        }
 
@@ -3819,7 +3824,8 @@ int cgroup_get_uid_gid_from_procfs(pid_t pid, uid_t 
*euid, gid_t *egid)
                 * /proc/<pid>/status. The format has been changed
                 * and we should catch up the change.
                 */
-               cgroup_dbg("The invlid file format of /proc/%d/status.\n", pid);
+               cgroup_warn("Warning: invalid file format of"
+                               " /proc/%d/status\n", pid);
                return ECGFAIL;
        }
        return 0;
diff --git a/src/config.c b/src/config.c
index db29838..bc92112 100644
--- a/src/config.c
+++ b/src/config.c
@@ -990,7 +990,7 @@ static int cgroup_parse_config(const char *pathname)
        yyin = fopen(pathname, "re");
 
        if (!yyin) {
-               cgroup_dbg("Failed to open file %s\n", pathname);
+               cgroup_err("Error: failed to open file %s\n", pathname);
                last_errno = errno;
                return ECGOTHER;
        }
@@ -1032,7 +1032,7 @@ static int cgroup_parse_config(const char *pathname)
                /*
                 * Either yyparse failed or longjmp() was called.
                 */
-               cgroup_dbg("Failed to parse file %s\n", pathname);
+               cgroup_err("Error: failed to parse file %s\n", pathname);
                ret = ECGCONFIGPARSEFAIL;
                goto err;
        }


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to