summaryrefslogtreecommitdiffstats
path: root/vmcore-dmesg
diff options
context:
space:
mode:
authorLianbo Jiang <lijiang@redhat.com>2019-08-23 20:05:38 +0800
committerSimon Horman <horms@verge.net.au>2019-09-08 13:26:07 +0100
commita7c4cb8e998571cb3dd62e907935a1e052b15d6c (patch)
treee2f2ec782d6939a686e9cb9f8cdd798e15e06bdd /vmcore-dmesg
parent14ad054e7baa788a6629385ffe5e0f1996b7de02 (diff)
downloadkexec-tools-a7c4cb8e998571cb3dd62e907935a1e052b15d6c.tar.gz
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 <lijiang@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
Diffstat (limited to 'vmcore-dmesg')
-rw-r--r--vmcore-dmesg/vmcore-dmesg.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/vmcore-dmesg/vmcore-dmesg.c b/vmcore-dmesg/vmcore-dmesg.c
index bebc348a..fe7df8ec 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);