From a7c4cb8e998571cb3dd62e907935a1e052b15d6c Mon Sep 17 00:00:00 2001 From: Lianbo Jiang Date: Fri, 23 Aug 2019 20:05:38 +0800 Subject: Cleanup: move it back from util_lib/elf_info.c Some code related to vmcore-dmesg.c is put into the util_lib, which is not very reasonable, so lets move it back and tidy up those code. In addition, that will also help to limit the size of vmcore-dmesg.txt in vmcore-dmesg.c instead of elf_info.c. Signed-off-by: Lianbo Jiang Signed-off-by: Simon Horman --- vmcore-dmesg/vmcore-dmesg.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'vmcore-dmesg/vmcore-dmesg.c') diff --git a/vmcore-dmesg/vmcore-dmesg.c b/vmcore-dmesg/vmcore-dmesg.c index bebc348..fe7df8e 100644 --- a/vmcore-dmesg/vmcore-dmesg.c +++ b/vmcore-dmesg/vmcore-dmesg.c @@ -5,6 +5,34 @@ typedef Elf32_Nhdr Elf_Nhdr; extern const char *fname; +static void write_to_stdout(char *buf, unsigned int nr) +{ + ssize_t ret; + + ret = write(STDOUT_FILENO, buf, nr); + if (ret != nr) { + fprintf(stderr, "Failed to write out the dmesg log buffer!:" + " %s\n", strerror(errno)); + exit(54); + } +} + +static int read_vmcore_dmesg(int fd, void (*handler)(char*, unsigned int)) +{ + int ret; + + ret = read_elf(fd); + if (ret > 0) { + fprintf(stderr, "Unable to read ELF information" + " from vmcore\n"); + return ret; + } + + dump_dmesg(fd, handler); + + return 0; +} + int main(int argc, char **argv) { ssize_t ret; @@ -23,7 +51,7 @@ int main(int argc, char **argv) return 2; } - ret = read_elf_vmcore(fd); + ret = read_vmcore_dmesg(fd, write_to_stdout); close(fd); -- cgit