]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
script: ensure that tmp files are removed
authorRoy Marples <roy@marples.name>
Sun, 28 Jul 2019 10:49:17 +0000 (11:49 +0100)
committerRoy Marples <roy@marples.name>
Sun, 28 Jul 2019 10:49:17 +0000 (11:49 +0100)
fopen creates a new stream which will use a new fd.
Why using fdopen, the new stream will use the same fd, so when
it's closed the tmp file will really unlink.

src/script.c

index 1863a66166eaf57dcfd27e943c8e8b993b95376d..74aef1b1b0615ae10c9f9581b69f8757e14714eb 100644 (file)
@@ -213,10 +213,11 @@ make_env(const struct interface *ifp, const char *reason)
        if (tmpfd == -1)
                goto eexit;
        unlink(tmpfile);
-       fp = fopen(tmpfile, "w+");
-       close(tmpfd);
-       if (fp == NULL)
+       fp = fdopen(tmpfd, "w+");
+       if (fp == NULL) {
+               close(tmpfd);
                goto eexit;
+       }
 #endif
 
 #ifdef INET