summaryrefslogtreecommitdiff
path: root/src/readahead/readahead-analyze.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-06-21 23:53:20 +0200
committerLennart Poettering <lennart@poettering.net>2012-06-21 23:53:20 +0200
commit87ce22cc0d097d9cd0297d0141eadba6c573c299 (patch)
tree8b7831ad915705a9ee67aa2e6defdc58dc3e9a9d /src/readahead/readahead-analyze.c
parentb4bdfefac3fcf633aa0700a981d854cc49a9725b (diff)
readahead: merge three binaries into one
since the binaries share much of the same code and we better load only one binary instead of two from disk at early boot let's merge the three readahead binaries into one. This also allows us to drop a lot of duplicated code.
Diffstat (limited to 'src/readahead/readahead-analyze.c')
-rw-r--r--src/readahead/readahead-analyze.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/readahead/readahead-analyze.c b/src/readahead/readahead-analyze.c
index 6ee355146a..5a5b9176d0 100644
--- a/src/readahead/readahead-analyze.c
+++ b/src/readahead/readahead-analyze.c
@@ -32,8 +32,7 @@
#include "readahead-common.h"
-
-int main(int argc, char *argv[])
+int main_analyze(const char *pack_path)
{
char line[1024];
char path[PATH_MAX];
@@ -48,30 +47,28 @@ int main(int argc, char *argv[])
struct stat st;
int pagesize = getpagesize();
- if (argc != 2)
- snprintf(path, PATH_MAX, "/.readahead");
- else
- snprintf(path, PATH_MAX, "%s", argv[1]);
+ if (!pack_path)
+ pack_path = "/.readahead";
- pack = fopen(path, "r");
+ pack = fopen(pack_path, "r");
if (!pack) {
fprintf(stderr, "Pack file missing\n");
- exit(EXIT_FAILURE);
+ return EXIT_FAILURE;
}
if (!(fgets(line, sizeof(line), pack))) {
fprintf(stderr, "Pack file corrupt\n");
- exit(EXIT_FAILURE);
+ return EXIT_FAILURE;
}
if (!strstr(line, READAHEAD_PACK_FILE_VERSION)) {
fprintf(stderr, "Pack file version incompatible with this parser\n");
- exit(EXIT_FAILURE);
+ return EXIT_FAILURE;
}
if ((a = getc(pack)) == EOF) {
fprintf(stderr, "Pack file corrupt\n");
- exit(EXIT_FAILURE);
+ return EXIT_FAILURE;
}
fprintf(stdout, " pct sections size: path\n");
@@ -88,14 +85,14 @@ int main(int argc, char *argv[])
if (fread(&inode, sizeof(inode), 1, pack) != 1) {
fprintf(stderr, "Pack file corrupt\n");
- exit(EXIT_FAILURE);
+ return EXIT_FAILURE;
}
while (true) {
if (fread(&b, sizeof(b), 1, pack) != 1 ||
fread(&c, sizeof(c), 1, pack) != 1) {
fprintf(stderr, "Pack file corrupt\n");
- exit(EXIT_FAILURE);
+ return EXIT_FAILURE;
}
if ((b == 0) && (c == 0))
break;
@@ -137,5 +134,5 @@ int main(int argc, char *argv[])
fprintf(stdout, "MISSING: %d\n", missing);
fprintf(stdout, "TOTAL: %ld\n", tsize);
- exit(EXIT_SUCCESS);
+ return EXIT_SUCCESS;
}