From: Roy Marples Date: Sun, 28 Jul 2019 10:49:17 +0000 (+0100) Subject: script: ensure that tmp files are removed X-Git-Tag: v8.0.2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b57c47a12c77494cf55ad2212ee5511bc41c4ba;p=thirdparty%2Fdhcpcd.git script: ensure that tmp files are removed 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. --- diff --git a/src/script.c b/src/script.c index 1863a661..74aef1b1 100644 --- a/src/script.c +++ b/src/script.c @@ -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