Preparation. This way "ramdump" array is ready for use right after
is_ramdump(), and this also simplifies the code a little bit.

Signed-off-by: Oleg Nesterov <[email protected]>
---
 ramdump.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/ramdump.c b/ramdump.c
index ab93767..c6a8a85 100644
--- a/ramdump.c
+++ b/ramdump.c
@@ -59,29 +59,19 @@ static void alloc_elf_header(Elf64_Ehdr *ehdr, ushort 
e_machine)
        ehdr->e_shstrndx = 0;
 }
 
-static int alloc_program_headers(Elf64_Phdr *phdr)
+static void alloc_program_headers(Elf64_Phdr *phdr)
 {
        unsigned int i;
-       struct stat64 st;
 
        for (i = 0; i < nodes; i++) {
                phdr[i].p_type = PT_LOAD;
-
-               if (0 > stat64(ramdump[i].path, &st)) {
-                       error(INFO, "ramdump stat failed\n");
-                       return -1;
-               }
-
-               phdr[i].p_filesz = st.st_size;
+               phdr[i].p_filesz = ramdump[i].end_paddr + 1 - 
ramdump[i].start_paddr;
                phdr[i].p_memsz = phdr[i].p_filesz;
                phdr[i].p_vaddr = 0;
                phdr[i].p_paddr = ramdump[i].start_paddr;
-               ramdump[i].end_paddr = ramdump[i].start_paddr + st.st_size - 1;
                phdr[i].p_flags = PF_R | PF_W | PF_X;
                phdr[i].p_align = 0;
        }
-
-       return 0;
 }
 
 static char *write_elf(Elf64_Phdr *load, Elf64_Ehdr *e_head, size_t 
data_offset)
@@ -219,8 +209,7 @@ char *ramdump_to_elf(void)
 
        load = (Elf64_Phdr *)ptr;
 
-       if (alloc_program_headers(load))
-               goto end;
+       alloc_program_headers(load);
 
        offset += sizeof(Elf64_Phdr) * nodes;
        ptr += sizeof(Elf64_Phdr) * nodes;
@@ -248,6 +237,7 @@ int is_ramdump(char *p)
        char *x = NULL, *y = NULL, *pat;
        size_t len;
        char *pattern;
+       struct stat64 st;
        int err = 0;
 
        if (nodes || !strchr(p, '@'))
@@ -277,6 +267,10 @@ int is_ramdump(char *p)
                                                "ramdump %s open failed:%s\n",
                                                ramdump[nodes - 1].path,
                                                strerror(errno));
+                       if (fstat64(ramdump[nodes - 1].rfd, &st) < 0)
+                               error(FATAL, "ramdump stat failed\n");
+                       ramdump[nodes - 1].end_paddr =
+                               ramdump[nodes - 1].start_paddr + st.st_size - 1;
                }
 
                pat = NULL;
-- 
2.5.0

--
Crash-utility mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/crash-utility

Reply via email to