File crash-search-also-in-lib-crash of Package crash
From: Bernhard Walle <bwalle@suse.de>
Subject: [PATCH] Add /usr/lib{,64}/crash to the search path for extensions
Patch-mainline: never
This patch just adds /usr/lib{,64}/crash to the search path for extensions.
This allows extensions to be installed in that directories to confirm
to the shared library packaging policy of SUSE.
Signed-off-by: Bernhard Walle <bwalle@suse.de>
---
defs.h | 1 +
extensions.c | 12 ++++++++++++
symbols.c | 22 ++++++++++++++++++++++
3 files changed, 35 insertions(+)
--- a/defs.h
+++ b/defs.h
@@ -3295,6 +3295,7 @@ void dump_symbol_table(void);
void dump_struct_table(ulong);
void dump_offset_table(char *, ulong);
int is_elf_file(char *);
+int is_elf_file_in_dir(const char *file, const char *dir);
int is_kernel(char *);
int file_elf_version(char *);
int is_system_map(char *);
--- a/extensions.c
+++ b/extensions.c
@@ -210,8 +210,20 @@ load_extension(char *lib)
* If the library is not specified by an absolute pathname, dlopen()
* does not look in the current directory.
*/
+
+ /* add .so if necessary */
+ if (strlen(lib) <= 3 || strcmp(lib + strlen(lib) - 3, ".so") != 0) {
+ char *lib2 = strdup(lib);
+ sprintf(lib, "%s.so", lib2);
+ free(lib2);
+ }
+
if ((*lib != '.') && (*lib != '/') && is_elf_file(lib))
sprintf(ext->filename, "./%s", lib);
+ else if (is_elf_file_in_dir("/usr/lib/crash", lib))
+ sprintf(ext->filename, "%s/%s", "/usr/lib/crash", lib);
+ else if (is_elf_file_in_dir("/usr/lib64/crash", lib))
+ sprintf(ext->filename, "%s/%s", "/usr/lib64/crash", lib);
else
strcpy(ext->filename, lib);
--- a/symbols.c
+++ b/symbols.c
@@ -2604,6 +2604,28 @@ bailout:
return(is_bfd_format(file));
}
+
+/*
+ * Checks if file <file> in dir <dir> is a valid ELF file.
+ */
+int
+is_elf_file_in_dir(const char *dir, const char *file)
+{
+ char *buffer;
+ int ret;
+
+ buffer = malloc(strlen(dir) + strlen(file) + 2);
+ if (!buffer)
+ return FALSE;
+
+ sprintf(buffer, "%s/%s", dir, file);
+
+ ret = is_elf_file(buffer);
+ free(buffer);
+
+ return ret;
+}
+
/*
* Given a choice between two namelists, pick the one for gdb to use.
* For now, just check get their stats and check their sizes; the larger