1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-27 18:55:40 +03:00

readahead: make sure to close pack file before exiting, to be valgrind clean

This commit is contained in:
Lennart Poettering 2012-06-22 00:03:25 +02:00
parent 97fa0e708f
commit ebfb7506fe
2 changed files with 20 additions and 10 deletions

View File

@ -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;
}

View File

@ -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 {