summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cpukit/ChangeLog8
-rw-r--r--cpukit/libblock/src/ide_part_table.c6
-rw-r--r--cpukit/libmisc/monitor/mon-command.c95
-rw-r--r--cpukit/libmisc/monitor/mon-editor.c10
-rw-r--r--cpukit/libmisc/monitor/mon-monitor.c26
-rw-r--r--cpukit/libmisc/monitor/monitor.h8
-rw-r--r--cpukit/libmisc/shell/cmds.c47
7 files changed, 118 insertions, 82 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index d144634663..1dcd875875 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,3 +1,11 @@
+2008-12-19 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/src/ide_part_table.c: Fixed NULL pointer access.
+ * libmisc/monitor/mon-command.c, libmisc/monitor/mon-editor.c,
+ libmisc/monitor/mon-monitor.c, libmisc/monitor/monitor.h,
+ libmisc/shell/cmds.c: The list of registered monitor commands is now
+ private and only accessible via a lookup and iterate function.
+
2008-12-18 Joel Sherrill <joel.sherrill@oarcorp.com>
* rtems/include/rtems/rtems/regionmp.h, sapi/include/rtems/config.h,
diff --git a/cpukit/libblock/src/ide_part_table.c b/cpukit/libblock/src/ide_part_table.c
index cc8763a584..31edc31a41 100644
--- a/cpukit/libblock/src/ide_part_table.c
+++ b/cpukit/libblock/src/ide_part_table.c
@@ -376,10 +376,10 @@ read_mbr(rtems_disk_desc_t *disk_desc)
part_num < RTEMS_IDE_PARTITION_MAX_SUB_PARTITION_NUMBER;
part_num++)
{
- if (is_extended(disk_desc->partitions[part_num]->sys_type))
+ part_desc = disk_desc->partitions[part_num];
+ if (part_desc != NULL && is_extended(part_desc->sys_type))
{
- read_extended_partition(disk_desc->partitions[part_num]->start,
- disk_desc->partitions[part_num]);
+ read_extended_partition(part_desc->start, part_desc);
}
}
diff --git a/cpukit/libmisc/monitor/mon-command.c b/cpukit/libmisc/monitor/mon-command.c
index e5ee6aee53..bd4a6a8277 100644
--- a/cpukit/libmisc/monitor/mon-command.c
+++ b/cpukit/libmisc/monitor/mon-command.c
@@ -24,49 +24,6 @@
#include <rtems.h>
#include <rtems/monitor.h>
-/*
- * Look up a command in a command table
- *
- */
-
-const rtems_monitor_command_entry_t *rtems_monitor_command_lookup(
- const rtems_monitor_command_entry_t *table,
- const char *command_name
-)
-{
- const rtems_monitor_command_entry_t *found_it = NULL;
- size_t command_length = 0;
-
- if (command_name == NULL) {
- return NULL;
- }
-
- command_length = strlen(command_name);
-
- while (table != NULL) {
- if (table->command != NULL) {
- /* Check for ambiguity */
- if (!strncmp(table->command, command_name, command_length)) {
- if (found_it == NULL) {
- found_it = table;
- } else {
- return NULL;
- }
- }
- }
- table = table->next;
- }
-
- /* No ambiguity (the possible partial command was unique after all) */
-
- /* Ignore empty commands */
- if (found_it == NULL || found_it->command_function == NULL) {
- return NULL;
- }
-
- return found_it;
-}
-
static void
rtems_monitor_show_help (
const rtems_monitor_command_entry_t *help_cmd,
@@ -173,7 +130,7 @@ rtems_monitor_command_usage(
if (command_name && (*command_name != '\0'))
{
- command = rtems_monitor_command_lookup (table, command_name);
+ command = rtems_monitor_command_lookup (command_name);
if (command)
rtems_monitor_show_help (command, strlen (command_name));
@@ -231,3 +188,53 @@ void rtems_monitor_help_cmd(
rtems_monitor_command_usage(command, argv[arg]);
}
}
+
+typedef struct {
+ const char *name;
+ size_t length;
+ const rtems_monitor_command_entry_t *match;
+} rtems_monitor_command_lookup_entry;
+
+static bool rtems_monitor_command_lookup_routine(
+ const rtems_monitor_command_entry_t *e,
+ void *arg
+)
+{
+ rtems_monitor_command_lookup_entry *le =
+ (rtems_monitor_command_lookup_entry *) arg;
+
+ /* Check name */
+ if (strncmp(e->command, le->name, le->length) == 0) {
+ /* Check for ambiguity */
+ if (le->match == NULL) {
+ le->match = e;
+ } else {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+/**
+ * @brief Looks for a command with the name @a name in the list of registered
+ * commands.
+ *
+ * The parameter @a name must not be NULL.
+ *
+ * Returns the corresponding command entry or NULL if no command is found.
+ */
+const rtems_monitor_command_entry_t *rtems_monitor_command_lookup(
+ const char *name
+)
+{
+ rtems_monitor_command_lookup_entry e = {
+ .name = name,
+ .length = strlen( name),
+ .match = NULL
+ };
+
+ rtems_monitor_command_iterate(rtems_monitor_command_lookup_routine, &e);
+
+ return e.match;
+}
diff --git a/cpukit/libmisc/monitor/mon-editor.c b/cpukit/libmisc/monitor/mon-editor.c
index c204e2716c..de10a02317 100644
--- a/cpukit/libmisc/monitor/mon-editor.c
+++ b/cpukit/libmisc/monitor/mon-editor.c
@@ -597,12 +597,10 @@ rtems_monitor_task(
if (0 == rtems_monitor_command_read(command_buffer, &argc, argv))
continue;
if (argc < 1
- || (command = rtems_monitor_command_lookup(rtems_monitor_commands,
- argv [0])) == 0)
- {
- /* no command */
- fprintf(stdout,"Unrecognised command; try 'help'\n");
- continue;
+ || (command = rtems_monitor_command_lookup(argv [0])) == 0) {
+ /* no command */
+ fprintf(stdout,"Unrecognised command; try 'help'\n");
+ continue;
}
command->command_function(argc, argv, &command->command_arg, verbose);
diff --git a/cpukit/libmisc/monitor/mon-monitor.c b/cpukit/libmisc/monitor/mon-monitor.c
index 06f72e0f04..f60c9a33ed 100644
--- a/cpukit/libmisc/monitor/mon-monitor.c
+++ b/cpukit/libmisc/monitor/mon-monitor.c
@@ -60,7 +60,7 @@ rtems_symbol_table_t *rtems_monitor_symbols;
* The top-level commands
*/
-const rtems_monitor_command_entry_t rtems_monitor_commands[] = {
+static const rtems_monitor_command_entry_t rtems_monitor_commands[] = {
{ "config",
"Show the system configuration.",
0,
@@ -480,3 +480,27 @@ rtems_monitor_insert_cmd (
return 1;
}
+
+/**
+ * @brief Iterates through all registerd commands.
+ *
+ * For each command the interation routine @a routine is called with the
+ * command entry and the user provided argument @a arg. It is guaranteed that
+ * the command name and function are not NULL.
+ */
+void rtems_monitor_command_iterate(
+ rtems_monitor_per_command_routine routine,
+ void *arg
+)
+{
+ const rtems_monitor_command_entry_t *e = rtems_monitor_registered_commands;
+
+ while (e != NULL) {
+ if (e->command != NULL && e->command_function != NULL) {
+ if (!routine(e, arg)) {
+ break;
+ }
+ }
+ e = e->next;
+ }
+}
diff --git a/cpukit/libmisc/monitor/monitor.h b/cpukit/libmisc/monitor/monitor.h
index 28e6831834..bb7d5aafd7 100644
--- a/cpukit/libmisc/monitor/monitor.h
+++ b/cpukit/libmisc/monitor/monitor.h
@@ -368,6 +368,7 @@ typedef struct {
rtems_monitor_object_dump_fn dump;
} rtems_monitor_object_info_t;
+typedef bool (*rtems_monitor_per_command_routine)(const rtems_monitor_command_entry_t *, void *);
/* monitor.c */
void rtems_monitor_pause_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
@@ -377,8 +378,8 @@ void rtems_monitor_debugger_cmd(int, char **, const rtems_monitor_command_arg
void rtems_monitor_node_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
void rtems_monitor_symbols_loadup(void);
int rtems_monitor_insert_cmd(rtems_monitor_command_entry_t *);
-int rtems_monitor_erase_cmd(rtems_monitor_command_entry_t *);
void rtems_monitor_wakeup(void);
+void rtems_monitor_command_iterate(rtems_monitor_per_command_routine routine, void *arg);
rtems_status_code rtems_monitor_suspend(rtems_interval timeout);
/* editor.c */
@@ -395,9 +396,9 @@ void rtems_monitor_server_init(uint32_t );
/* command.c */
int rtems_monitor_make_argv(char *, int *, char **);
int rtems_monitor_command_read(char *, int *, char **);
-const rtems_monitor_command_entry_t *rtems_monitor_command_lookup(const rtems_monitor_command_entry_t *table, const char *command_name);
void rtems_monitor_command_usage(const rtems_monitor_command_entry_t *, const char *);
void rtems_monitor_help_cmd(int, char **, const rtems_monitor_command_arg_t *, bool);
+const rtems_monitor_command_entry_t *rtems_monitor_command_lookup(const char *name);
/* prmisc.c */
void rtems_monitor_separator(void);
@@ -519,9 +520,6 @@ const rtems_monitor_object_info_t *rtems_monitor_object_lookup(
/* shared data */
extern rtems_symbol_table_t *rtems_monitor_symbols;
-/* FIXME: This should not be here */
-extern const rtems_monitor_command_entry_t rtems_monitor_commands[];
-
#define MONITOR_WAKEUP_EVENT RTEMS_EVENT_0
#ifdef __cplusplus
diff --git a/cpukit/libmisc/shell/cmds.c b/cpukit/libmisc/shell/cmds.c
index 4664f482ea..2a3a029add 100644
--- a/cpukit/libmisc/shell/cmds.c
+++ b/cpukit/libmisc/shell/cmds.c
@@ -36,7 +36,7 @@ int rtems_shell_main_monitor(int argc, char **argv) {
return 1;
}
- command = rtems_monitor_command_lookup(rtems_monitor_commands, argv [0]);
+ command = rtems_monitor_command_lookup(argv [0]);
if (command == NULL) {
return 1;
@@ -47,30 +47,31 @@ int rtems_shell_main_monitor(int argc, char **argv) {
return 0;
}
-void rtems_shell_register_monitor_commands(void)
+static bool rtems_shell_register_command(const rtems_monitor_command_entry_t *e, void *arg)
{
- /* Monitor topic */
- const rtems_monitor_command_entry_t *e = rtems_monitor_commands;
-
- while (e != NULL) {
- /* Exclude EXIT (alias quit)*/
- if (e->command != NULL && strcmp("exit", e->command) != 0) {
- rtems_shell_cmd_t *shell_cmd =
- (rtems_shell_cmd_t *) malloc(sizeof(rtems_shell_cmd_t));
-
- if (shell_cmd != NULL) {
- shell_cmd->name = e->command;
- shell_cmd->topic = "monitor";
- shell_cmd->usage = e->usage;
- shell_cmd->command = rtems_shell_main_monitor;
- shell_cmd->alias = NULL;
- shell_cmd->next = NULL;
-
- if (rtems_shell_add_cmd_struct(shell_cmd) == NULL) {
- free(shell_cmd);
- }
+ /* Exclude EXIT (alias quit)*/
+ if (strcmp("exit", e->command) != 0) {
+ rtems_shell_cmd_t *shell_cmd =
+ (rtems_shell_cmd_t *) malloc(sizeof(rtems_shell_cmd_t));
+
+ if (shell_cmd != NULL) {
+ shell_cmd->name = e->command;
+ shell_cmd->topic = "monitor";
+ shell_cmd->usage = e->usage;
+ shell_cmd->command = rtems_shell_main_monitor;
+ shell_cmd->alias = NULL;
+ shell_cmd->next = NULL;
+
+ if (rtems_shell_add_cmd_struct(shell_cmd) == NULL) {
+ free(shell_cmd);
}
}
- e = e->next;
}
+
+ return true;
+}
+
+void rtems_shell_register_monitor_commands(void)
+{
+ rtems_monitor_command_iterate(rtems_shell_register_command, NULL);
}