summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2018-08-23 13:58:17 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2018-08-23 13:58:17 +0200
commitc460ba9cb9d79d9007327c8ace7a7ac2c17e6277 (patch)
treec4a3c321ca2f2cd27db8296a2c7080bede3d4af9
parentb7f7a502a074741d72d324b39b8f6b2036e8ff50 (diff)
sfeed_tail: file need to exist the first run, but not after
+ dont memcpy the struct stat(2) when nothing changed.
-rw-r--r--sfeed_tail.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/sfeed_tail.c b/sfeed_tail.c
index 6e1da91..d401b4e 100644
--- a/sfeed_tail.c
+++ b/sfeed_tail.c
@@ -14,7 +14,7 @@
static char *line;
static size_t linesize;
-static int changed;
+static int changed, firsttime = 1;
static time_t comparetime;
struct line {
@@ -144,10 +144,19 @@ main(int argc, char *argv[])
comparetime -= 86400;
for (i = 1; i < argc; i++) {
- if (!(fp = fopen(argv[i], "r")))
- err(1, "fopen: %s", argv[i]);
- if (fstat(fileno(fp), &st) == -1)
- err(1, "fstat: %s", argv[i]);
+ if (!(fp = fopen(argv[i], "r"))) {
+ if (firsttime)
+ err(1, "fopen: %s", argv[i]);
+ /* NOTE: don't report when the file is missing */
+ continue;
+ }
+ if (fstat(fileno(fp), &st) == -1) {
+ if (firsttime)
+ err(1, "fstat: %s", argv[i]);
+ warn("fstat: %s", argv[i]);
+ fclose(fp);
+ continue;
+ }
/* did the file change? by size, modification */
if (stfiles[i - 1].st_size != st.st_size ||
@@ -155,9 +164,10 @@ main(int argc, char *argv[])
name = ((name = strrchr(argv[i], '/'))) ? name + 1 : argv[i];
printfeed(fp, name);
if (ferror(fp))
- err(1, "ferror: %s", argv[i]);
+ warn("ferror: %s", argv[i]);
+ memcpy(&stfiles[i - 1], &st, sizeof(st));
}
- memcpy(&stfiles[i - 1], &st, sizeof(st));
+
fclose(fp);
}
@@ -169,6 +179,7 @@ main(int argc, char *argv[])
}
sleep(1);
slept++;
+ firsttime = 0;
}
return 0;
}