chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
mount: when learning about the root mount from mountinfo, don't add conflicting dep...
[elogind.git]
/
src
/
readahead
/
readahead-analyze.c
diff --git
a/src/readahead/readahead-analyze.c
b/src/readahead/readahead-analyze.c
index 42bf9dbac97673d21c6703dec804ce4ad810cf4c..76db3cb7e4b8dc0be437e291d9bf8e3d0c0797cb 100644
(file)
--- a/
src/readahead/readahead-analyze.c
+++ b/
src/readahead/readahead-analyze.c
@@
-32,19
+32,12
@@
#include "readahead-common.h"
#include "readahead-common.h"
-int main_analyze(const char *pack_path)
-{
- char line[1024];
- char path[PATH_MAX];
- FILE *pack;
+int main_analyze(const char *pack_path) {
+ char line[LINE_MAX];
+ _cleanup_fclose_ FILE *pack = NULL;
int a;
int missing = 0;
int a;
int missing = 0;
- off_t size;
- long tsize = 0;
- uint64_t inode;
- uint32_t b;
- uint32_t c;
- struct stat st;
+ size_t tsize = 0;
if (!pack_path)
pack_path = "/.readahead";
if (!pack_path)
pack_path = "/.readahead";
@@
-52,28
+45,33
@@
int main_analyze(const char *pack_path)
pack = fopen(pack_path, "re");
if (!pack) {
log_error("Pack file missing.");
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.");
}
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.");
log_error("Pack file version incompatible with this parser.");
-
return EXIT_FAILURE
;
+
goto fail
;
}
if ((a = getc(pack)) == EOF) {
log_error("Pack file corrupt.");
}
if ((a = getc(pack)) == EOF) {
log_error("Pack file corrupt.");
-
return EXIT_FAILURE
;
+
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;
@@
-84,20
+82,22
@@
int main_analyze(const char *pack_path)
if (fread(&inode, sizeof(inode), 1, pack) != 1) {
log_error("Pack file corrupt.");
if (fread(&inode, sizeof(inode), 1, pack) != 1) {
log_error("Pack file corrupt.");
-
return EXIT_FAILURE
;
+
goto fail
;
}
}
- while (true) {
+ for (;;) {
+ uint32_t b, c;
+
if (fread(&b, sizeof(b), 1, pack) != 1 ||
fread(&c, sizeof(c), 1, pack) != 1) {
log_error("Pack file corrupt.");
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;
/* 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);
@@
-105,6
+105,8
@@
int main_analyze(const char *pack_path)
}
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
@@
-112,13
+114,13
@@
int main_analyze(const char *pack_path)
tsize += size;
tsize += size;
-
fprintf(stdout, " %4d%% (%2d) %12l
d: %s\n",
-
sections ? (int)(size / st.st_size * 100.0) : 100
,
-
sections ? sections : 1,
-
(unsigned long)
size,
-
path);
+
printf(" %4jd%% (%2d) %12j
d: %s\n",
+
(intmax_t) (sections && st.st_size ? size * 100 / st.st_size : 100)
,
+ sections ? sections : 1,
+
(intmax_t)
size,
+ path);
} else {
} 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,
"???",
@@
-128,10
+130,17
@@
int main_analyze(const char *pack_path)
}
}
- fprintf(stdout, "\nHOST: %s", line);
- fprintf(stdout, "TYPE: %c\n", a);
- fprintf(stdout, "MISSING: %d\n", missing);
- fprintf(stdout, "TOTAL: %ld\n", tsize);
+ printf("\nHOST: %s"
+ "TYPE: %c\n"
+ "MISSING: %d\n"
+ "TOTAL: %zu\n",
+ line,
+ a,
+ missing,
+ tsize);
return EXIT_SUCCESS;
return EXIT_SUCCESS;
+
+fail:
+ return EXIT_FAILURE;
}
}