X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbasic%2Ffileio.c;h=4ad2acf3bd7d9f5a404c1b04f89fe378f4a0d6f5;hb=6414babd8b4554e19f9ac7826cb7e82ef6b3435c;hp=16a6d02872eb7986994bb673fccce468a9de5dc5;hpb=d1dcbfbabb3ce13ceb0d5dd48a2478bce8d8ed21;p=elogind.git diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 16a6d0287..4ad2acf3b 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -271,7 +271,7 @@ int read_full_stream(FILE *f, char **contents, size_t *size) { if (n >= READ_FULL_BYTES_MAX) return -E2BIG; - n = MAX(n * 2, READ_FULL_BYTES_MAX); + n = MIN(n * 2, READ_FULL_BYTES_MAX); } buf[l] = 0; @@ -1046,7 +1046,7 @@ int fopen_temporary(const char *path, FILE **_f, char **_temp_path) { if (r < 0) return r; - fd = mkostemp_safe(t, O_WRONLY|O_CLOEXEC); + fd = mkostemp_safe(t); if (fd < 0) { free(t); return -errno; @@ -1079,7 +1079,7 @@ int fflush_and_check(FILE *f) { } /* This is much like mkostemp() but is subject to umask(). */ -int mkostemp_safe(char *pattern, int flags) { +int mkostemp_safe(char *pattern) { _cleanup_umask_ mode_t u = 0; int fd; @@ -1087,7 +1087,7 @@ int mkostemp_safe(char *pattern, int flags) { u = umask(077); - fd = mkostemp(pattern, flags); + fd = mkostemp(pattern, O_CLOEXEC); if (fd < 0) return -errno; @@ -1285,17 +1285,15 @@ int open_tmpfile_unlinkable(const char *directory, int flags) { /* Returns an unlinked temporary file that cannot be linked into the file system anymore */ -#ifdef O_TMPFILE /* Try O_TMPFILE first, if it is supported */ fd = open(directory, flags|O_TMPFILE|O_EXCL, S_IRUSR|S_IWUSR); if (fd >= 0) return fd; -#endif /* Fall back to unguessable name + unlinking */ p = strjoina(directory, "/systemd-tmp-XXXXXX"); - fd = mkostemp_safe(p, flags); + fd = mkostemp_safe(p); if (fd < 0) return fd; @@ -1318,7 +1316,6 @@ int open_tmpfile_linkable(const char *target, int flags, char **ret_path) { * which case "ret_path" will be returned as NULL. If not possible a the tempoary path name used is returned in * "ret_path". Use link_tmpfile() below to rename the result after writing the file in full. */ -#ifdef O_TMPFILE { _cleanup_free_ char *dn = NULL; @@ -1334,7 +1331,6 @@ int open_tmpfile_linkable(const char *target, int flags, char **ret_path) { log_debug_errno(errno, "Failed to use O_TMPFILE on %s: %m", dn); } -#endif r = tempfn_random(target, NULL, &tmp); if (r < 0)