__cgroup_attach_task_pid() function outputs a warning message when
writing into "tasks" file fails, but it doesn't do that when the file
can not be opened.

Change that, as such warnings can be useful when debugging an issue.

Signed-off-by: Nikola Forró <nfo...@redhat.com>
---
 src/api.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/api.c b/src/api.c
index 06cf0b9..a72b21a 100644
--- a/src/api.c
+++ b/src/api.c
@@ -1318,12 +1318,15 @@ static int __cgroup_attach_task_pid(char *path, pid_t 
tid)
        if (!tasks) {
                switch (errno) {
                case EPERM:
-                       return ECGROUPNOTOWNER;
+                       ret = ECGROUPNOTOWNER;
+                       break;
                case ENOENT:
-                       return ECGROUPNOTEXIST;
+                       ret = ECGROUPNOTEXIST;
+                       break;
                default:
-                       return ECGROUPNOTALLOWED;
+                       ret = ECGROUPNOTALLOWED;
                }
+               goto err;
        }
        ret = fprintf(tasks, "%d", tid);
        if (ret < 0) {
@@ -1342,7 +1345,8 @@ static int __cgroup_attach_task_pid(char *path, pid_t tid)
 err:
        cgroup_warn("Warning: cannot write tid %d to %s:%s\n",
                        tid, path, strerror(errno));
-       fclose(tasks);
+       if (tasks)
+               fclose(tasks);
        return ret;
 }
 
-- 
2.17.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to