summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2016-01-11 13:27:26 +0100
committerFelix Fietkau <nbd@openwrt.org>2016-01-11 13:27:53 +0100
commit950437eecd6048dd29eb3e11f4343372b2ddce60 (patch)
tree0080edef7b8a234a0975d55e4e8c0edbecd5f292
parenta536e300370cc3ad7b14b052b9ee943e6149ba4d (diff)
downloaduci-950437eecd6048dd29eb3e11f4343372b2ddce60.tar.gz
file: defer checking the tmpfile until it is actually needed.
Avoids creating useless entries in the kernel dentry cache Signed-off-by: Felix Fietkau <nbd@openwrt.org>
-rw-r--r--file.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/file.c b/file.c
index 341a706..8e6052c 100644
--- a/file.c
+++ b/file.c
@@ -735,17 +735,6 @@ static void uci_file_commit(struct uci_context *ctx, struct uci_package **packag
if ((asprintf(&filename, "%s/.%s.uci-XXXXXX", ctx->confdir, p->e.name) < 0) || !filename)
UCI_THROW(ctx, UCI_ERR_MEM);
- if (!mktemp(filename))
- *filename = 0;
-
- if (!*filename) {
- free(filename);
- UCI_THROW(ctx, UCI_ERR_IO);
- }
-
- if ((stat(filename, &statbuf) == 0) && ((statbuf.st_mode & S_IFMT) != S_IFREG))
- UCI_THROW(ctx, UCI_ERR_IO);
-
/* open the config file for writing now, so that it is locked */
f1 = uci_open_stream(ctx, p->path, NULL, SEEK_SET, true, true);
@@ -780,6 +769,17 @@ static void uci_file_commit(struct uci_context *ctx, struct uci_package **packag
goto done;
}
+ if (!mktemp(filename))
+ *filename = 0;
+
+ if (!*filename) {
+ free(filename);
+ UCI_THROW(ctx, UCI_ERR_IO);
+ }
+
+ if ((stat(filename, &statbuf) == 0) && ((statbuf.st_mode & S_IFMT) != S_IFREG))
+ UCI_THROW(ctx, UCI_ERR_IO);
+
f2 = uci_open_stream(ctx, filename, p->path, SEEK_SET, true, true);
uci_export(ctx, f2, p, false);