Introduction of a new "extend -s" option, which shows all available

shared object extension modules that are located in the directories
that are part of the normal search path that is used when a shared
object is loaded without a fully-qualified pathname.
(w@laoqinren.net)
This commit is contained in:
Dave Anderson 2020-03-03 09:47:51 -05:00
parent 49ed67d2c7
commit 5dfbc7aa27
2 changed files with 74 additions and 5 deletions

View File

@ -20,10 +20,13 @@
static int in_extensions_library(char *, char *);
static char *get_extensions_directory(char *);
static void show_all_extensions(void);
static void show_extensions(char *);
#define DUMP_EXTENSIONS (0)
#define LOAD_EXTENSION (1)
#define UNLOAD_EXTENSION (2)
#define DUMP_EXTENSIONS (0)
#define LOAD_EXTENSION (1)
#define UNLOAD_EXTENSION (2)
#define SHOW_ALL_EXTENSIONS (4)
/*
* Load, unload, or list the extension libaries.
@ -36,14 +39,30 @@ cmd_extend(void)
flag = DUMP_EXTENSIONS;
while ((c = getopt(argcnt, args, "lu")) != EOF) {
while ((c = getopt(argcnt, args, "lus")) != EOF) {
switch(c)
{
case 's':
if (flag & UNLOAD_EXTENSION) {
error(INFO,
"-s and -u are mutually exclusive\n");
argerrs++;
}else if (flag & LOAD_EXTENSION) {
error(INFO,
"-s and -l are mutually exclusive\n");
argerrs++;
} else
flag |= SHOW_ALL_EXTENSIONS;
break;
case 'l':
if (flag & UNLOAD_EXTENSION) {
error(INFO,
"-l and -u are mutually exclusive\n");
argerrs++;
} else if (flag & SHOW_ALL_EXTENSIONS) {
error(INFO,
"-l and -s are mutually exclusive\n");
argerrs++;
} else
flag |= LOAD_EXTENSION;
break;
@ -53,6 +72,10 @@ cmd_extend(void)
error(INFO,
"-u and -l are mutually exclusive\n");
argerrs++;
} else if (flag & SHOW_ALL_EXTENSIONS) {
error(INFO,
"-u and -s are mutually exclusive\n");
argerrs++;
} else
flag |= UNLOAD_EXTENSION;
break;
@ -100,6 +123,11 @@ cmd_extend(void)
optind++;
}
break;
case SHOW_ALL_EXTENSIONS:
show_all_extensions();
break;
}
}
@ -182,6 +210,45 @@ dump_extension_table(int verbose)
} while ((ext = ext->prev));
}
static void
show_extensions(char *dir) {
DIR *dirp;
struct dirent *dp;
char filename[BUFSIZE*2];
dirp = opendir(dir);
if (!dirp)
return;
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
sprintf(filename, "%s%s%s", dir,
LASTCHAR(dir) == '/' ? "" : "/",
dp->d_name);
if (!is_shared_object(filename))
continue;
fprintf(fp, "%s\n", filename);
}
closedir(dirp);
}
static void
show_all_extensions(void)
{
char *dir;
show_extensions("./");
if ((dir = getenv("CRASH_EXTENSIONS")))
show_extensions(dir);
if (BITS64())
show_extensions("/usr/lib64/crash/extensions/");
show_extensions("/usr/lib/crash/extensions/");
show_extensions("./extensions/");
}
/*
* Load an extension library.

4
help.c
View File

@ -2164,13 +2164,14 @@ NULL
char *help_extend[] = {
"extend",
"extend the %s command set",
"[shared-object ...] | [-u [shared-object ...]]",
"[shared-object ...] | [-u [shared-object ...]] | -s",
" This command dynamically loads or unloads %s extension shared object",
" libraries:\n",
" shared-object load the specified shared object file; more than one",
" one object file may be entered.",
" -u shared-object unload the specified shared object file; if no file",
" arguments are specified, unload all objects.",
" -s show all available shared object files.",
"\n If the shared-object filename is not expressed with a fully-qualified",
" pathname, the following directories will be searched in the order shown,",
" and the first instance of the file that is found will be selected:\n",
@ -2178,6 +2179,7 @@ char *help_extend[] = {
" 2. the directory specified in the CRASH_EXTENSIONS environment variable",
" 3. /usr/lib64/crash/extensions (64-bit architectures)",
" 4. /usr/lib/crash/extensions",
" 5. the ./extensions subdirectory of the current directory",
"\n If no arguments are entered, the current set of shared object files and ",
" a list of their commands will be displayed. The registered commands",
" contained in each shared object file will appear automatically in the ",