Re: [Crash-utility] [PATCH V2] extensions: add extend -s option to show all available shared object file
Thanks Wang -- queued for crash-7.2.9: https://github.com/crash-utility/crash/commit/5dfbc7aa27392a095b207d31654cec7db94dd810 Dave - Original Message - > When we load extensions, sometime we do not know the exact name of the shared > object file. > > This patch add -s option for extend cmd to show all available shared object > file. > > for example: > > crash> extend -s > ./trace.so > /usr/lib64/crash/extensions/dminfo.so > /usr/lib64/crash/extensions/echo.so > /usr/lib64/crash/extensions/eppic.so > /usr/lib64/crash/extensions/snap.so > /usr/lib64/crash/extensions/trace.so > ./extensions/dminfo.so > ./extensions/eppic.so > ./extensions/echo.so > ./extensions/snap.so > ./extensions/trace.so > crash> extend -s -l > extend: -l and -s are mutually exclusive > Usage: > extend [shared-object ...] | [-u [shared-object ...]] | -s > Enter "help extend" for details. > crash> extend -s -u > extend: -u and -s are mutually exclusive > Usage: > extend [shared-object ...] | [-u [shared-object ...]] | -s > Enter "help extend" for details. > crash> > > Also, this patch update the help for extend command: > add the search order "5. the ./extensions subdirectory of the current > directory" > > Changes since v1: > - -s option also check the current working directory > - fix warning > > Signed-off-by: Wang Long > --- > extensions.c | 75 > > help.c | 4 +++- > 2 files changed, 74 insertions(+), 5 deletions(-) > > diff --git a/extensions.c b/extensions.c > index 24b91de..d23b1e3 100644 > --- a/extensions.c > +++ b/extensions.c > @@ -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); > + > +
[Crash-utility] [PATCH V2] extensions: add extend -s option to show all available shared object file
When we load extensions, sometime we do not know the exact name of the shared object file. This patch add -s option for extend cmd to show all available shared object file. for example: crash> extend -s ./trace.so /usr/lib64/crash/extensions/dminfo.so /usr/lib64/crash/extensions/echo.so /usr/lib64/crash/extensions/eppic.so /usr/lib64/crash/extensions/snap.so /usr/lib64/crash/extensions/trace.so ./extensions/dminfo.so ./extensions/eppic.so ./extensions/echo.so ./extensions/snap.so ./extensions/trace.so crash> extend -s -l extend: -l and -s are mutually exclusive Usage: extend [shared-object ...] | [-u [shared-object ...]] | -s Enter "help extend" for details. crash> extend -s -u extend: -u and -s are mutually exclusive Usage: extend [shared-object ...] | [-u [shared-object ...]] | -s Enter "help extend" for details. crash> Also, this patch update the help for extend command: add the search order "5. the ./extensions subdirectory of the current directory" Changes since v1: - -s option also check the current working directory - fix warning Signed-off-by: Wang Long --- extensions.c | 75 help.c | 4 +++- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/extensions.c b/extensions.c index 24b91de..d23b1e3 100644 --- a/extensions.c +++ b/extensions.c @@ -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()) +