]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
coverity: #1427191
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 8 Jan 2018 17:24:41 +0000 (18:24 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 6 Feb 2018 09:26:59 +0000 (10:26 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c

index 1c2faef28b35ea0b6191e746a07edc3a5749dd51..dab112b1587b7c82c57e331932cbbd547f5ed057 100644 (file)
@@ -2411,15 +2411,17 @@ int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf,
                        return -1;
                }
 
-               buflen = sizeof("deny\n") - 1;
-               errno = 0;
-               ret = lxc_write_nointr(fd, "deny\n", buflen);
-               if (ret != buflen) {
-                       SYSERROR("Failed to write \"deny\" to \"/proc/%d/setgroups\"", pid);
+               if (fd >= 0) {
+                       buflen = sizeof("deny\n") - 1;
+                       errno = 0;
+                       ret = lxc_write_nointr(fd, "deny\n", buflen);
+                       if (ret != buflen) {
+                               SYSERROR("Failed to write \"deny\" to \"/proc/%d/setgroups\"", pid);
+                               close(fd);
+                               return -1;
+                       }
                        close(fd);
-                       return -1;
                }
-               close(fd);
        }
 
        ret = snprintf(path, MAXPATHLEN, "/proc/%d/%cid_map", pid,