chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
use "Out of memory." consistantly (or with "\n")
[elogind.git]
/
src
/
readahead
/
readahead-analyze.c
diff --git
a/src/readahead/readahead-analyze.c
b/src/readahead/readahead-analyze.c
index 6ee355146a3708384893c4a9b7797ef53fcfabd6..53892b0cf862bf03a60d1e6348e3de3dfb6c8b53 100644
(file)
--- a/
src/readahead/readahead-analyze.c
+++ b/
src/readahead/readahead-analyze.c
@@
-32,52
+32,46
@@
#include "readahead-common.h"
#include "readahead-common.h"
-
-int main(int argc, char *argv[])
-{
- char line[1024];
- char path[PATH_MAX];
+int main_analyze(const char *pack_path) {
+ char line[LINE_MAX];
FILE *pack;
int a;
int missing = 0;
FILE *pack;
int a;
int missing = 0;
- off_t size;
- long tsize = 0;
- uint64_t inode;
- uint32_t b;
- uint32_t c;
- struct stat st;
- int pagesize = getpagesize();
-
- if (argc != 2)
- snprintf(path, PATH_MAX, "/.readahead");
- else
- snprintf(path, PATH_MAX, "%s", argv[1]);
-
- pack = fopen(path, "r");
+ off_t tsize = 0;
+
+ if (!pack_path)
+ pack_path = "/.readahead";
+
+ pack = fopen(pack_path, "re");
if (!pack) {
if (!pack) {
-
fprintf(stderr, "Pack file missing\n
");
-
exit(EXIT_FAILURE)
;
+
log_error("Pack file missing.
");
+
goto fail
;
}
}
- if (!
(fgets(line, sizeof(line), pack)
)) {
-
fprintf(stderr, "Pack file corrupt\n
");
-
exit(EXIT_FAILURE)
;
+ if (!
fgets(line, sizeof(line), pack
)) {
+
log_error("Pack file corrupt.
");
+
goto fail
;
}
}
- if (!strstr(line, READAHEAD_PACK_FILE_VERSION)) {
- fprintf(stderr, "Pack file version incompatible with this parser\n");
- exit(EXIT_FAILURE);
+ char_array_0(line);
+
+ if (!endswith(line, READAHEAD_PACK_FILE_VERSION)) {
+ log_error("Pack file version incompatible with this parser.");
+ goto fail;
}
if ((a = getc(pack)) == EOF) {
}
if ((a = getc(pack)) == EOF) {
-
fprintf(stderr, "Pack file corrupt\n
");
-
exit(EXIT_FAILURE)
;
+
log_error("Pack file corrupt.
");
+
goto fail
;
}
}
- fp
rintf(stdout, " pct sections size: path\n");
-
fprintf(stdout, " === ======== ====: ====\n"
);
+ fp
uts(" pct sections size: path\n"
+
" === ======== ====: ====\n", stdout
);
- while(true) {
+ for (;;) {
+ char path[PATH_MAX];
+ struct stat st;
+ uint64_t inode;
int pages = 0;
int sections = 0;
int pages = 0;
int sections = 0;
@@
-87,21
+81,23
@@
int main(int argc, char *argv[])
path[strlen(path)-1] = 0;
if (fread(&inode, sizeof(inode), 1, pack) != 1) {
path[strlen(path)-1] = 0;
if (fread(&inode, sizeof(inode), 1, pack) != 1) {
-
fprintf(stderr, "Pack file corrupt\n
");
-
exit(EXIT_FAILURE)
;
+
log_error("Pack file corrupt.
");
+
goto fail
;
}
}
- while (true) {
+ for (;;) {
+ uint32_t b, c;
+
if (fread(&b, sizeof(b), 1, pack) != 1 ||
fread(&c, sizeof(c), 1, pack) != 1) {
if (fread(&b, sizeof(b), 1, pack) != 1 ||
fread(&c, sizeof(c), 1, pack) != 1) {
-
fprintf(stderr, "Pack file corrupt\n
");
-
exit(EXIT_FAILURE)
;
+
log_error("Pack file corrupt.
");
+
goto fail
;
}
if ((b == 0) && (c == 0))
break;
/* Uncomment this to get all the chunks separately
}
if ((b == 0) && (c == 0))
break;
/* Uncomment this to get all the chunks separately
-
fprintf(stdout,
" %d: %d %d\n", sections, b, c);
+
printf(
" %d: %d %d\n", sections, b, c);
*/
pages += (c - b);
*/
pages += (c - b);
@@
-109,20
+105,22
@@
int main(int argc, char *argv[])
}
if (stat(path, &st) == 0) {
}
if (stat(path, &st) == 0) {
+ off_t size;
+
if (sections == 0)
size = st.st_size;
else
if (sections == 0)
size = st.st_size;
else
- size = pages * page
size
;
+ size = pages * page
_size()
;
tsize += size;
tsize += size;
-
fprintf(stdout,
" %4d%% (%2d) %12ld: %s\n",
- sections ? (int)
(size / st.st_size * 100.0
) : 100,
+
printf(
" %4d%% (%2d) %12ld: %s\n",
+ sections ? (int)
(size * 100 / st.st_size
) : 100,
sections ? sections : 1,
(unsigned long)size,
path);
} else {
sections ? sections : 1,
(unsigned long)size,
path);
} else {
-
fprintf(stdout,
" %4dp (%2d) %12s: %s (MISSING)\n",
+
printf(
" %4dp (%2d) %12s: %s (MISSING)\n",
sections ? pages : -1,
sections ? sections : 1,
"???",
sections ? pages : -1,
sections ? sections : 1,
"???",
@@
-132,10
+130,20
@@
int main(int argc, char *argv[])
}
}
- fprintf(stdout, "\nHOST: %s", line);
- fprintf(stdout, "TYPE: %c\n", a);
- fprintf(stdout, "MISSING: %d\n", missing);
- fprintf(stdout, "TOTAL: %ld\n", tsize);
+ fclose(pack);
+
+ printf("\nHOST: %s"
+ "TYPE: %c\n"
+ "MISSING: %d\n"
+ "TOTAL: %ld\n",
+ line,
+ a,
+ missing,
+ tsize);
+
+ return EXIT_SUCCESS;
- exit(EXIT_SUCCESS);
+fail:
+ fclose(pack);
+ return EXIT_FAILURE;
}
}