summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/readahead/readahead-analyze.c27
-rw-r--r--src/readahead/readahead-replay.c3
2 files changed, 20 insertions, 10 deletions
diff --git a/src/readahead/readahead-analyze.c b/src/readahead/readahead-analyze.c
index 42bf9dbac9..75f85b46e0 100644
--- a/src/readahead/readahead-analyze.c
+++ b/src/readahead/readahead-analyze.c
@@ -34,13 +34,13 @@
int main_analyze(const char *pack_path)
{
- char line[1024];
+ char line[LINE_MAX];
char path[PATH_MAX];
FILE *pack;
int a;
int missing = 0;
off_t size;
- long tsize = 0;
+ off_t tsize = 0;
uint64_t inode;
uint32_t b;
uint32_t c;
@@ -52,22 +52,24 @@ int main_analyze(const char *pack_path)
pack = fopen(pack_path, "re");
if (!pack) {
log_error("Pack file missing.");
- return EXIT_FAILURE;
+ goto fail;
}
if (!fgets(line, sizeof(line), pack)) {
log_error("Pack file corrupt.");
- return EXIT_FAILURE;
+ goto fail;
}
- if (!strstr(line, READAHEAD_PACK_FILE_VERSION)) {
+ char_array_0(line);
+
+ if (!endswith(line, READAHEAD_PACK_FILE_VERSION)) {
log_error("Pack file version incompatible with this parser.");
- return EXIT_FAILURE;
+ goto fail;
}
if ((a = getc(pack)) == EOF) {
log_error("Pack file corrupt.");
- return EXIT_FAILURE;
+ goto fail;
}
fprintf(stdout, " pct sections size: path\n");
@@ -84,14 +86,14 @@ int main_analyze(const char *pack_path)
if (fread(&inode, sizeof(inode), 1, pack) != 1) {
log_error("Pack file corrupt.");
- return EXIT_FAILURE;
+ goto fail;
}
while (true) {
if (fread(&b, sizeof(b), 1, pack) != 1 ||
fread(&c, sizeof(c), 1, pack) != 1) {
log_error("Pack file corrupt.");
- return EXIT_FAILURE;
+ goto fail;
}
if ((b == 0) && (c == 0))
break;
@@ -128,10 +130,17 @@ int main_analyze(const char *pack_path)
}
+ fclose(pack);
+
fprintf(stdout, "\nHOST: %s", line);
fprintf(stdout, "TYPE: %c\n", a);
fprintf(stdout, "MISSING: %d\n", missing);
fprintf(stdout, "TOTAL: %ld\n", tsize);
return EXIT_SUCCESS;
+
+
+fail:
+ fclose(pack);
+ return EXIT_FAILURE;
}
diff --git a/src/readahead/readahead-replay.c b/src/readahead/readahead-replay.c
index 6e6db601d4..7bd079aae5 100644
--- a/src/readahead/readahead-replay.c
+++ b/src/readahead/readahead-replay.c
@@ -155,7 +155,8 @@ static int replay(const char *root) {
goto finish;
}
- if ((!(pack = fopen(pack_fn, "re")))) {
+ pack = fopen(pack_fn, "re");
+ if (!pack) {
if (errno == ENOENT)
log_debug("No pack file found.");
else {