summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2016-02-28 18:49:06 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2016-02-28 18:49:06 +0100
commit4e505a8eccafe3defaf0e491ec6c347ee0e87830 (patch)
treea4333e429e8c32645dfcaab3806064f753303465
parentf4b0df7bfe0f4016bb2d3ff90f36f00b76a02f57 (diff)
sfeed_frames: fix open file permission (write only).
check errno EEXIST (file exist? -> ignore), handle other errno codes as errors. ... also make sure to fflush write before modifying file access and modification timestamps or it will be overwritten again.
-rw-r--r--sfeed_frames.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/sfeed_frames.c b/sfeed_frames.c
index 673b6dc..3411187 100644
--- a/sfeed_frames.c
+++ b/sfeed_frames.c
@@ -155,11 +155,11 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f)
strtotime(fields[FieldUnixTimestamp], &parsedtime);
/* content file doesn't exist yet and has write access */
- if ((fd = open(filepath, O_CREAT | O_EXCL)) == -1) {
- if (errno == EACCES)
+ if ((fd = open(filepath, O_CREAT | O_EXCL | O_WRONLY)) == -1) {
+ if (errno != EEXIST)
err(1, "open: %s", filepath);
} else {
- if (!(fpcontent = fdopen(fd, "w+b")))
+ if (!(fpcontent = fdopen(fd, "wb")))
err(1, "fdopen: %s", filepath);
fputs("<html><head>"
"<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style.css\" />"
@@ -185,6 +185,11 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f)
/* set modified and access time of file to time of item. */
if (parsedtime) {
+ /* flush writes before setting atime and mtime
+ else the remaining (buffered) write can occur at
+ fclose() and overwrite our time again. */
+ fflush(fpcontent);
+
times[0].tv_sec = parsedtime;
times[1].tv_sec = parsedtime;