]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: Show warning when tasks file can not be opened
authorNikola Forró <nforro@redhat.com>
Thu, 16 Jan 2020 17:43:52 +0000 (18:43 +0100)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 31 Jan 2020 20:59:47 +0000 (20:59 +0000)
Signed-off-by: Nikola Forró <nforro@redhat.com>
Reviewed-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index e7a07cfc5fe7968446f63e857a8a9f2f46fef51d..96e082fc312741ba6b0f29a15d7c3662e837aa7b 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -1382,12 +1382,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) {
@@ -1406,7 +1409,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;
 }