I've put few errors and warnings where I find them appropriate - usually
when a function returns error and the user might be interested exactly what
file/directory is bad.

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

 src/api.c    |   26 +++++++++++++++++++++++++-
 src/config.c |   20 ++++++++++++++++++--
 2 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/src/api.c b/src/api.c
index a1808df..40dc413 100644
--- a/src/api.c
+++ b/src/api.c
@@ -142,6 +142,8 @@ static int cg_chown_file(FTS *fts, FTSENT *ent, uid_t 
owner, gid_t group)
        }
        if (ret < 0) {
                last_errno = errno;
+               cgroup_warn("Warning: cannot change owner of file %s: %s\n",
+                               filename, strerror(errno));
                ret = ECGOTHER;
        }
        return ret;
@@ -159,6 +161,8 @@ static int cg_chown_recursive(char **path, uid_t owner, 
gid_t group)
        fts = fts_open(path, FTS_PHYSICAL | FTS_NOCHDIR |
                                FTS_NOSTAT, NULL);
        if (fts == NULL) {
+               cgroup_warn("Warning: cannot open directory %s: %s\n",
+                               path, strerror(errno));
                last_errno = errno;
                return ECGOTHER;
        }
@@ -201,6 +205,8 @@ int cg_chmod_file(FTS *fts, FTSENT *ent, mode_t dir_mode,
                break;
        }
        if (ret < 0) {
+               cgroup_warn("Warning: cannot change permissions of file %s:"
+                               " %s\n", filename, strerror(errno));
                last_errno = errno;
                ret = ECGOTHER;
        }
@@ -239,6 +245,8 @@ int cg_chmod_recursive(struct cgroup *cgroup, mode_t 
dir_mode,
                        FTS_NOSTAT, NULL);
        if (fts == NULL) {
                last_errno = errno;
+               cgroup_warn("Warning: cannot open directory %s: %s\n",
+                               fts_path, strerror(errno));
                final_ret = ECGOTHER;
                goto err;
        }
@@ -778,6 +786,8 @@ int cgroup_init(void)
        if (!proc_cgroup) {
                last_errno = errno;
                ret = ECGOTHER;
+               cgroup_err("Error: cannot open /proc/cgroups: %s\n",
+                               strerror(errno));
                goto unlock_exit;
        }
 
@@ -797,6 +807,8 @@ int cgroup_init(void)
                free(buf);
                last_errno = errno;
                ret = ECGOTHER;
+               cgroup_err("Error: cannot read /proc/cgroups: %s\n",
+                               strerror(errno));
                goto unlock_exit;
        }
        free(buf);
@@ -813,7 +825,10 @@ int cgroup_init(void)
 
        proc_mount = fopen("/proc/mounts", "re");
        if (proc_mount == NULL) {
-               ret = ECGFAIL;
+               last_errno = errno;
+               cgroup_err("Error: cannot open /proc/mounts: %s\n",
+                               strerror(errno));
+               ret = ECGOTHER;
                goto unlock_exit;
        }
 
@@ -1774,6 +1789,9 @@ static int cg_delete_cgroup_controller(char *cgroup_name, 
char *controller,
        delete_tasks = fopen(path, "re");
        if (delete_tasks) {
                ret = cg_move_task_files(delete_tasks, target_tasks);
+               if (ret != 0)
+                       cgroup_warn("Warning: removing tasks from %s failed:"
+                                       " %s\n", path, cgroup_strerror(ret));
                fclose(delete_tasks);
        } else {
                /*
@@ -1783,6 +1801,8 @@ static int cg_delete_cgroup_controller(char *cgroup_name, 
char *controller,
                if (errno != ENOENT) {
                        last_errno = errno;
                        ret = ECGOTHER;
+                       cgroup_warn("Warning: cannot open %s: %s\n",
+                                       path, strerror(errno));
                }
        }
 
@@ -1798,6 +1818,8 @@ static int cg_delete_cgroup_controller(char *cgroup_name, 
char *controller,
        ret = rmdir(path);
        if (ret != 0 && errno != ENOENT) {
                last_errno = errno;
+               cgroup_warn("Warning: cannot remove directory %s: %s\n",
+                               path, strerror(errno));
                return ECGOTHER;
        }
 
@@ -1947,6 +1969,8 @@ int cgroup_delete_cgroup_ext(struct cgroup *cgroup, int 
flags)
                parent_tasks = fopen(parent_path, "we");
                if (!parent_tasks) {
                        last_errno = errno;
+                       cgroup_warn("Warning: cannot open tasks file %s: %s\n",
+                                       parent_path, strerror(errno));
                        ret = ECGOTHER;
                } else {
                        if (flags & CGFLAG_DELETE_RECURSIVE) {
diff --git a/src/config.c b/src/config.c
index 566ea60..aff3be5 100644
--- a/src/config.c
+++ b/src/config.c
@@ -439,16 +439,23 @@ static int cgroup_config_mount_fs(void)
 
                if (ret < 0 && errno != ENOENT) {
                        last_errno = errno;
+                       cgroup_err("Error: cannot access %s: %s\n",
+                                       curr->mount.path, strerror(errno));
                        return ECGOTHER;
                }
 
                if (errno == ENOENT) {
                        ret = cg_mkdir_p(curr->mount.path);
-                       if (ret)
+                       if (ret) {
+                               cgroup_err("Error: cannot create directory"
+                                               " %s\n", curr->mount.path);
                                return ret;
+                       }
                } else if (!S_ISDIR(buff.st_mode)) {
                        errno = ENOTDIR;
                        last_errno = errno;
+                       cgroup_err("Error: %s already exists but it is not a"
+                                       " directory\n",  curr->mount.path);
                        return ECGOTHER;
                }
 
@@ -459,8 +466,12 @@ static int cgroup_config_mount_fs(void)
                ret = mount(CGROUP_FILESYSTEM, curr->mount.path,
                                CGROUP_FILESYSTEM, 0, curr->name);
 
-               if (ret < 0)
+               if (ret < 0) {
+                       cgroup_err("Error: cannot mount %s to %s: %s\n",
+                                       curr->name, curr->mount.path,
+                                       strerror(errno));
                        return ECGMOUNTFAIL;
+               }
        }
        return 0;
 }
@@ -803,6 +814,9 @@ static int cgroup_config_unload_controller(const struct 
cgroup_mount_point *moun
                if (error) {
                        last_errno = errno;
                        ret = ECGOTHER;
+                       cgroup_warn("Warning: cannot unmount controller %s on"
+                                       " %s: %s\n", mount_info->name,
+                                       mount_info->path, strerror(errno));
                        goto out_error;
                }
                ret = cgroup_get_subsys_mount_point_next(&handle, path);
@@ -850,6 +864,8 @@ int cgroup_unload_cgroups(void)
                        if (error) {
                                /* remember the error and continue unloading
                                 * the rest */
+                               cgroup_warn("Warning: cannot clear controller"
+                                               " %s\n", info.name);
                                ret = error;
                                error = 0;
                        }


------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding 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