]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc_init: add missing O_CLOEXEC
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 25 Mar 2020 11:53:13 +0000 (12:53 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 25 Mar 2020 11:53:13 +0000 (12:53 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cmd/lxc_init.c

index 24f67f08132fb96189dd01735fc694803dc00029..a52793343a1fc4b023ab1149757912c730911b68 100644 (file)
@@ -87,7 +87,8 @@ static void prevent_forking(void)
                return;
 
        while (getline(&line, &len, f) != -1) {
-               int fd, ret;
+               __do_close int fd = -EBADF;
+               int ret;
                char *p, *p2;
 
                p = strchr(line, ':');
@@ -118,7 +119,7 @@ static void prevent_forking(void)
                        return;
                }
 
-               fd = open(path, O_WRONLY);
+               fd = open(path, O_WRONLY | O_CLOEXEC);
                if (fd < 0) {
                        if (my_args.quiet)
                                fprintf(stderr, "Failed to open \"%s\"\n", path);
@@ -129,7 +130,6 @@ static void prevent_forking(void)
                if (ret != 1 && !my_args.quiet)
                        fprintf(stderr, "Failed to write to \"%s\"\n", path);
 
-               close(fd);
                return;
        }
 }