Re: [PATCH]: minimal mode extensions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi again,

On Wed, Jan 23, 2013 at 3:28 PM, Dave Anderson <anderson@xxxxxxxxxx> wrote:
>
>
> ----- Original Message -----
>> Hi all,
>>
>> How do you feel about allowing minimal mode in extensions? See
>> attached patch.
>>
>> Regards,
>> Per
>
> Seems reasonable enough -- and I'm sure you've got good reasons for
> having minimal-mode extension modules.
>
> But since you're opening the door to all extension modules, I have
> a few additional suggestions.  Modify the register_extension() and
> load_extension() functions such that:
>
>  (1) if in minimal mode, and an extension module doesn't have any
>      MINIMAL commands, reject the module outright, failing
>      in a similar manner to the DUPLICATE_COMMAND_NAME error.
>
>  (2) if in minimal mode, and an extension module has multiple commands
>      where some are MINIMAL but others are not, maybe print a warning
>      message for the commands that are not MINIMAL?
>
> And then document the MINIMAL flag in this part of the "extend" help page:
>
>   crash> help extend
>   ...
>     command, and during command failures.  The flags field currently has one
>     available bit setting, REFRESH_TASK_TABLE, which should be set if it is
>     preferable to reload the current set of running processes just prior to
>     executing the command (on a live system).  Terminate the array of
>     command_table_entry structures with an entry with a NULL command name.
>   ...
>
> Make sense?

Does to me. New patch attached.

/Per

>
> Dave
>
> --
> Crash-utility mailing list
> Crash-utility@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/crash-utility
diff --git a/cmdline.c b/cmdline.c
index 0459e72..204886f 100755
--- a/cmdline.c
+++ b/cmdline.c
@@ -2199,15 +2199,6 @@ shell_command(char *cmd)
 	return REDIRECT_SHELL_COMMAND;
 }
 
-int minimal_functions(char *name)
-{
-	return  STREQ("log", name) || STREQ("help",name)  || \
-		STREQ("dis", name) || STREQ("q", name)    || \
-		STREQ("sym", name) || STREQ("exit", name) || \
-		STREQ("rd", name)  || STREQ("eval", name) || \
-		STREQ("set", name); 
-}
-
 static int 
 verify_args_input_file(char *fileptr)
 {
diff --git a/defs.h b/defs.h
index d84d4d5..7b422eb 100755
--- a/defs.h
+++ b/defs.h
@@ -534,6 +534,7 @@ struct args_input_file {
 #define REFRESH_TASK_TABLE (0x1)           /* command_table_entry flags */
 #define HIDDEN_COMMAND     (0x2)
 #define CLEANUP            (0x4)           /* for extensions only */
+#define MINIMAL            (0x8)
 
 /*
  *  A linked list of extension table structures keeps track of the current
@@ -549,6 +550,7 @@ struct extension_table {
 
 #define REGISTERED              (0x1)      /* extension_table flags */
 #define DUPLICATE_COMMAND_NAME  (0x2)
+#define NO_MINIMAL_COMMANDS     (0x4)
 
 struct new_utsname {
         char sysname[65];
diff --git a/extensions.c b/extensions.c
index 71cd25d..4da5091 100755
--- a/extensions.c
+++ b/extensions.c
@@ -266,7 +266,7 @@ load_extension(char *lib)
 
 	if (!(ext->flags & REGISTERED)) {
 		dlclose(ext->handle);
-		if (ext->flags & DUPLICATE_COMMAND_NAME)
+		if (ext->flags & (DUPLICATE_COMMAND_NAME | NO_MINIMAL_COMMANDS))
 			error(INFO, 
 		         "%s: shared object unloaded\n", ext->filename);
 		else
@@ -493,6 +493,7 @@ register_extension(struct command_table_entry *command_table)
 {
 	struct command_table_entry *cp;
 
+	pc->curext->flags |= NO_MINIMAL_COMMANDS;
         for (cp = command_table; cp->name; cp++) {
 		if (get_command_table_entry(cp->name)) {
 			error(INFO, 
@@ -501,6 +502,26 @@ register_extension(struct command_table_entry *command_table)
 			pc->curext->flags |= DUPLICATE_COMMAND_NAME;
 			return;
 		}
+		if (cp->flags & MINIMAL) {
+			pc->curext->flags &= ~NO_MINIMAL_COMMANDS;
+		}
+	}
+
+	if ((pc->flags & MINIMAL_MODE) && (pc->curext->flags & NO_MINIMAL_COMMANDS)) {
+		error(INFO, 
+		      "%s\" does not contain any commands which support minimal mode\n",
+		      pc->curext->filename);
+		return;
+	}
+
+	if (pc->flags & MINIMAL_MODE) {
+		for (cp = command_table; cp->name; cp++) {
+			if (!(cp->flags & MINIMAL)) {
+				error(WARNING, 
+				      "%s: command \"%s\" does not support minimal mode\n",
+				      pc->curext->filename, cp->name);
+			}
+		}
 	}
 
         for (cp = command_table; cp->name; cp++) {
diff --git a/global_data.c b/global_data.c
index 2172627..a244bb1 100755
--- a/global_data.c
+++ b/global_data.c
@@ -75,20 +75,20 @@ struct command_table_entry linux_command_table[] = {
         {"bt",      cmd_bt,      help_bt,      REFRESH_TASK_TABLE},
 	{"btop",    cmd_btop,    help_btop,    0},
 	{"dev",     cmd_dev,     help_dev,     0},
-	{"dis",     cmd_dis,     help_dis,     0},
-	{"eval",    cmd_eval,    help_eval,    0},
-	{"exit",    cmd_quit,    help_exit,    0},
-	{"extend",  cmd_extend,  help_extend,  0},
+	{"dis",     cmd_dis,     help_dis,     MINIMAL},
+	{"eval",    cmd_eval,    help_eval,    MINIMAL},
+	{"exit",    cmd_quit,    help_exit,    MINIMAL},
+	{"extend",  cmd_extend,  help_extend,  MINIMAL},
 	{"files",   cmd_files,   help_files,   REFRESH_TASK_TABLE},
 	{"foreach", cmd_foreach, help_foreach, REFRESH_TASK_TABLE},
 	{"fuser",   cmd_fuser,   help_fuser,   REFRESH_TASK_TABLE},
 	{"gdb",     cmd_gdb,     help_gdb,     REFRESH_TASK_TABLE},
-        {"help",    cmd_help,    help_help,    0},
+        {"help",    cmd_help,    help_help,    MINIMAL},
 	{"ipcs",    cmd_ipcs,    help_ipcs,    REFRESH_TASK_TABLE},
 	{"irq",     cmd_irq,     help_irq,     0},
 	{"kmem",    cmd_kmem,    help_kmem,    0},
 	{"list",    cmd_list,    help__list,   REFRESH_TASK_TABLE},
-	{"log",     cmd_log,     help_log,     0},
+	{"log",     cmd_log,     help_log,     MINIMAL},
 	{"mach",    cmd_mach,    help_mach,    0},
 	{"map",     cmd_map,     help_map,     HIDDEN_COMMAND},
 	{"mod",     cmd_mod,     help_mod,     0},
@@ -99,17 +99,17 @@ struct command_table_entry linux_command_table[] = {
 	{"pte",     cmd_pte,     help_pte,     0},
 	{"ptob",    cmd_ptob,    help_ptob,    0},
 	{"ptov",    cmd_ptov,    help_ptov,    0},
-        {"q",       cmd_quit,    help_quit,    0},
+        {"q",       cmd_quit,    help_quit,    MINIMAL},
         {"tree",    cmd_tree,    help_tree,    REFRESH_TASK_TABLE},
-        {"rd",      cmd_rd,      help_rd,      0},
+        {"rd",      cmd_rd,      help_rd,      MINIMAL},
 	{"repeat",  cmd_repeat,  help_repeat,  0},
 	{"runq",    cmd_runq,    help_runq,    REFRESH_TASK_TABLE},
         {"search",  cmd_search,  help_search,  0},
-        {"set",     cmd_set,     help_set,     REFRESH_TASK_TABLE},
+        {"set",     cmd_set,     help_set,     REFRESH_TASK_TABLE | MINIMAL},
         {"sig",     cmd_sig,     help_sig,     REFRESH_TASK_TABLE},
         {"struct",  cmd_struct,  help_struct,  0},
 	{"swap",    cmd_swap,    help_swap,    0},
-        {"sym",     cmd_sym,     help_sym,     0},
+        {"sym",     cmd_sym,     help_sym,     MINIMAL},
         {"sys",     cmd_sys,     help_sys,     REFRESH_TASK_TABLE},
         {"task",    cmd_task,    help_task,    REFRESH_TASK_TABLE},
 	{"test",    cmd_test,    NULL,         HIDDEN_COMMAND},
diff --git a/help.c b/help.c
index bf0c01b..625f45c 100755
--- a/help.c
+++ b/help.c
@@ -1947,10 +1947,11 @@ char *help_extend[] = {
 "  the command's function address, a pointer to an array of help data strings,",
 "  and a flags field.  The help_data field is optional; if it is non-NULL, it",
 "  should point to an array of character strings used by the \"help\"",
-"  command, and during command failures.  The flags field currently has one",
-"  available bit setting, REFRESH_TASK_TABLE, which should be set if it is ",
+"  command, and during command failures.  The flags field currently has two",
+"  available bit settings, REFRESH_TASK_TABLE, which should be set if it is ",
 "  preferable to reload the current set of running processes just prior to ",
-"  executing the command (on a live system).  Terminate the array of ",
+"  executing the command (on a live system) and MINIMAL, which should be "
+"  set if the command should be available in minimal mode.  Terminate the array of ",
 "  command_table_entry structures with an entry with a NULL command name.  ",
 " ",
 "  Below is an example shared object file consisting of just one command, ",
diff --git a/main.c b/main.c
index 7650b8c..357725d 100755
--- a/main.c
+++ b/main.c
@@ -687,7 +687,7 @@ main_loop(void)
 
 	if (pc->flags & MINIMAL_MODE)
             error(NOTE, 
-		"minimal mode commands: log, dis, rd, sym, eval, set and exit\n\n");
+		"minimal mode commands: log, dis, rd, sym, eval, set, extend and exit\n\n");
 
         pc->flags |= RUNTIME;
 
@@ -795,7 +795,7 @@ reattempt:
 	if (pc->flags & MINIMAL_MODE)
 		error(INFO, 
 		    "%s: command not available in minimal mode\n"
-		    "NOTE: minimal mode commands: log, dis, rd, sym, eval, set and exit\n",
+		    "NOTE: minimal mode commands: log, dis, rd, sym, eval, set, extend and exit\n",
 			args[0]);
 	else
 		error(INFO, "command not found: %s\n", args[0]);
@@ -829,18 +829,21 @@ get_command_table_entry(char *name)
 			name = "gdb";
 	}
 	
-	if ((pc->flags & MINIMAL_MODE) && !minimal_functions(name)) 
-		return NULL;
-  
 	for (cp = pc->cmd_table; cp->name; cp++) {
                 if (STREQ(cp->name, name))
-                        return cp;
+			if (!(pc->flags & MINIMAL_MODE) || (cp->flags & MINIMAL))
+				return cp;
+			else
+				return NULL;
         }
                 
         for (ext = extension_table; ext; ext = ext->next) {
                 for (cp = ext->command_table; cp->name; cp++) {
                         if (STREQ(cp->name, name)) {
-                                return cp;
+				if (!(pc->flags & MINIMAL_MODE) || (cp->flags & MINIMAL))
+					return cp;
+				else
+					return NULL;
 			}
                 }
         }       
--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux