On Sun, 30 Jun 2019 21:29:33 +0200
Matteo Croce <mcr...@redhat.com> wrote:

> @@ -737,6 +746,14 @@ static int netns_add(int argc, char **argv, bool create)
>       }
>       close(fd);
>  
> +     fd = open(tmp_path, O_RDONLY|O_CREAT|O_EXCL, 0);
> +     if (fd < 0) {
> +             fprintf(stderr, "Cannot create namespace file \"%s\": %s\n",
> +                     tmp_path, strerror(errno));
> +             goto out_delete;
> +     }
> +     close(fd);
> +
>       if (create) {
>               netns_save();
>               if (unshare(CLONE_NEWNET) < 0) {
> @@ -757,6 +774,7 @@ static int netns_add(int argc, char **argv, bool create)
>               goto out_delete;
>       }
>       netns_restore();
> +     unlink(tmp_path);

This looks like yet another source of potential errors and races.
What if the program is killed or other issues.

Maybe using abstract unix domain socket (which doesn't exist in filesystem
and auto-deletes on exit) would be better.

Reply via email to