1
1
- Add functionality to parse multiple arguments provided in the console
- Cleaned up help function
- Added an option to hide commands from the help menu

Working on launching and reaping of daemons from within the console.

This commit was SVN r6699.
Этот коммит содержится в:
Josh Hursey 2005-08-01 22:52:48 +00:00
родитель 4c1dd716c7
Коммит 943a74e266
2 изменённых файлов: 190 добавлений и 54 удалений

Просмотреть файл

@ -26,6 +26,11 @@
#include <unistd.h>
#endif
#if HAVE_READLINE_H
#include <readline/readline.h>
#include <readline/history.h>
#endif
#include "dps/dps.h"
#include "util/sys_info.h"
@ -56,11 +61,11 @@ static bool exit_cmd;
/*
* Globals for catching command line options
*/
orteconsole_globals_t orteconsole_globals;
orte_console_globals_t orte_console_globals;
opal_cmd_line_init_t cmd_line_opts[] = {
{ NULL, NULL, NULL, 'h', NULL, "help", 0,
&orteconsole_globals.help, OPAL_CMD_LINE_TYPE_BOOL,
&orte_console_globals.help, OPAL_CMD_LINE_TYPE_BOOL,
"This help message" },
/* End of list */
@ -74,20 +79,29 @@ opal_cmd_line_init_t cmd_line_opts[] = {
orte_console_command_t console_commands[] = {
{ "quit", "q", 0, ORTE_CONSOLE_TYPE_STD,
orte_console_exit,
"quit",
"Exit the console" },
{ "help", "h", 0, ORTE_CONSOLE_TYPE_STD,
orte_console_help,
"help [command]",
"Print this display" },
{ "contactinfo", "ci", 0, ORTE_CONSOLE_TYPE_STD,
orte_console_contactinfo,
"contactinfo",
"Query Contact Information from Daemons" },
{ "dumpvm", "vm", 0, ORTE_CONSOLE_TYPE_STD,
orte_console_dumpvm,
"dumpvm",
"Get VM List from daemons" },
{ "devel", NULL, 2, ORTE_CONSOLE_TYPE_HIDDEN,
orte_console_devel,
"devel arg1 arg2",
"Development Debugging function" },
/* End of list */
{ NULL, NULL, 0, ORTE_CONSOLE_TYPE_NULL,
NULL,
@ -99,11 +113,12 @@ int main(int argc, char *argv[])
int ret=0;
opal_cmd_line_t *cmd_line;
char *usercmd;
orte_console_input_command_t input_command;
/*
* Setup to check common command line options
*/
memset(&orteconsole_globals, 0, sizeof(orteconsole_globals_t));
memset(&orte_console_globals, 0, sizeof(orte_console_globals_t));
cmd_line = OBJ_NEW(opal_cmd_line_t);
opal_cmd_line_create(cmd_line, cmd_line_opts);
if (OMPI_SUCCESS != (ret = opal_cmd_line_parse(cmd_line, false,
@ -117,7 +132,7 @@ int main(int argc, char *argv[])
}
/* Check for help request */
if(orteconsole_globals.help) {
if(orte_console_globals.help) {
char *args = NULL;
args = opal_cmd_line_get_usage_msg(cmd_line);
opal_show_help("help-orteconsole.txt", "orteconsole:usage", false,
@ -139,12 +154,13 @@ int main(int argc, char *argv[])
* Work Loop
*/
exit_cmd = false;
memset(&input_command, 0, sizeof(orte_console_input_command_t));
while (!exit_cmd) {
printf("ompiconsole> ");
usercmd = orte_console_get_input_line();
usercmd = orte_getinputline();
execute_command(usercmd);
orte_console_parse_command(usercmd, &input_command);
orte_console_execute_command(input_command);
}
/*
@ -159,22 +175,40 @@ int main(int argc, char *argv[])
return ORTE_SUCCESS;
}
static int execute_command(char *command) {
static int command_cmp(char* user_command, orte_console_command_t system_command) {
/*
* Check for Full Name Match
*/
if( 0 == strncmp(user_command, system_command.cmd_full_name,
strlen(system_command.cmd_full_name)) ) {
return 0;
}
/*
* Check for Short Name Match
*/
else if( ( system_command.cmd_short_name != NULL ) &&
( strlen(user_command) == strlen(system_command.cmd_short_name) ) &&
( 0 == strncmp(user_command, system_command.cmd_short_name,
strlen(system_command.cmd_short_name)) ) ) {
return 0;
}
return -1;
}
static int orte_console_execute_command(orte_console_input_command_t input_command) {
orte_console_command_t *cur_cmd;
int i, ret;
for(i = 0; console_commands[i].cmd_type != ORTE_CONSOLE_TYPE_NULL; ++i) {
cur_cmd = &console_commands[i];
/*
* Check Full Name then check short name
* Check the requested command
*/
if ( ( 0 == strncmp(command, cur_cmd->cmd_full_name,
strlen(cur_cmd->cmd_full_name)) ) ||
( ( strlen(command) == strlen(cur_cmd->cmd_short_name) ) &&
( 0 == strncmp(command, cur_cmd->cmd_short_name,
strlen(cur_cmd->cmd_short_name)) ) ) ) {
ret = cur_cmd->cmd_function();
if ( command_cmp(input_command.cmd_name, *cur_cmd) == 0 ){
ret = cur_cmd->cmd_function(input_command);
if(ret == ORTE_ERR_NOT_IMPLEMENTED) {
opal_show_help("help-orteconsole.txt", "orteconsole:unimplemented-command", false,
@ -195,52 +229,125 @@ static int execute_command(char *command) {
*/
if( console_commands[i].cmd_type == ORTE_CONSOLE_TYPE_NULL ) {
opal_show_help("help-orteconsole.txt", "orteconsole:unknown-command", false,
command);
input_command.cmd_name);
return ORTE_ERR_NOT_IMPLEMENTED;
}
return ORTE_SUCCESS;
}
static int orte_console_exit() {
static int orte_console_parse_command(char * usercmd, orte_console_input_command_t *input_command){
char *tok;
input_command->argc = 0;
tok = strtok(usercmd, " ");
while(tok != NULL) {
if(input_command->argc == 0) {
input_command->cmd_name = strdup(tok);
}
input_command->argv[input_command->argc] = strdup(tok);
++(input_command->argc);
tok = strtok(NULL, " ");
}
return ORTE_SUCCESS;
}
static int orte_console_devel(orte_console_input_command_t input_command) {
system("orted --seed --persistent --scope public");
return ORTE_SUCCESS;
}
static int orte_console_exit(orte_console_input_command_t input_command) {
exit_cmd = true;
orte_console_sendcmd(ORTE_DAEMON_EXIT_CMD);
orte_console_send_command(ORTE_DAEMON_EXIT_CMD);
return ORTE_SUCCESS;
}
static int orte_console_help() {
static int orte_console_help(orte_console_input_command_t input_command) {
orte_console_command_t *cur_cmd;
int i;
printf("Open RTE Console Commands:\n\n");
for(i = 0; console_commands[i].cmd_type != ORTE_CONSOLE_TYPE_NULL; ++i) {
cur_cmd = &console_commands[i];
printf("%15s | %5s \t%s\n",
cur_cmd->cmd_full_name,
cur_cmd->cmd_short_name,
cur_cmd->cmd_description);
/*
* Generic Help
*/
if(input_command.argc <= 1) {
printf("Open RTE Console Commands:\n\n");
for(i = 0; console_commands[i].cmd_type != ORTE_CONSOLE_TYPE_NULL; ++i) {
cur_cmd = &console_commands[i];
if(cur_cmd->cmd_type != ORTE_CONSOLE_TYPE_HIDDEN) {
printf("%15s ", cur_cmd->cmd_full_name);
if(cur_cmd->cmd_short_name == NULL) {
printf(" ");
}
else {
printf(" | %5s ", cur_cmd->cmd_short_name);
}
printf("\t%s\n", cur_cmd->cmd_description);
}
}
printf("\n");
}
/*
* Specific Help Message for a Command
*/
else {
for(i = 0; console_commands[i].cmd_type != ORTE_CONSOLE_TYPE_NULL; ++i) {
cur_cmd = &console_commands[i];
printf("\n");
if ( command_cmp(input_command.argv[1], *cur_cmd) == 0 ){
printf("Command:\n");
printf("\t%s ", cur_cmd->cmd_full_name);
if(cur_cmd->cmd_short_name != NULL) {
printf(" | %5s", cur_cmd->cmd_short_name);
}
printf("\n");
printf("Description:\n");
printf("\t%s\n", cur_cmd->cmd_description);
if(cur_cmd->cmd_usage != NULL) {
printf("Usage:\n");
printf("\t%s\n", cur_cmd->cmd_usage);
}
break;
}
}
/*
* Command Not Found
*/
if( console_commands[i].cmd_type == ORTE_CONSOLE_TYPE_NULL ) {
opal_show_help("help-orteconsole.txt", "orteconsole:unknown-command", false,
input_command.argv[1]);
return ORTE_SUCCESS;
}
printf("\n");
}
return ORTE_SUCCESS;
}
static int orte_console_dumpvm() {
static int orte_console_dumpvm(orte_console_input_command_t input_command) {
return ORTE_ERR_NOT_IMPLEMENTED;
}
static int orte_console_contactinfo() {
static int orte_console_contactinfo(orte_console_input_command_t input_command) {
char * str_response;
orte_buffer_t *buffer = NULL;
orte_process_name_t seed={0,0,0};
size_t n;
orte_console_sendcmd(ORTE_DAEMON_CONTACT_QUERY_CMD);
orte_console_send_command(ORTE_DAEMON_CONTACT_QUERY_CMD);
if (0 > orte_rml.recv_buffer(&seed, buffer, ORTE_RML_TAG_DAEMON)) {
printf("****got a bad response\n");
return ORTE_ERROR;
@ -258,7 +365,7 @@ static int orte_console_contactinfo() {
return ORTE_SUCCESS;
}
static void orte_console_sendcmd(orte_daemon_cmd_flag_t usercmd)
static int orte_console_send_command(orte_daemon_cmd_flag_t usercmd)
{
orte_buffer_t *cmd;
orte_daemon_cmd_flag_t command;
@ -268,31 +375,45 @@ static void orte_console_sendcmd(orte_daemon_cmd_flag_t usercmd)
cmd = OBJ_NEW(orte_buffer_t);
if (NULL == cmd) {
fprintf(stderr, "console: comm failure\n");
return;
return ORTE_ERROR;
}
command = usercmd;
if (ORTE_SUCCESS != (rc = orte_dps.pack(cmd, &command, 1, ORTE_DAEMON_CMD))) {
fprintf(stderr, "console: comm failure 1\n");
ORTE_ERROR_LOG(rc);
return;
return ORTE_ERROR;
}
if (0 > orte_rml.send_buffer(&seed, cmd, ORTE_RML_TAG_DAEMON, 0)) {
fprintf(stderr, "console: comm failure 2\n");
ORTE_ERROR_LOG(ORTE_ERR_COMM_FAILURE);
return;
return ORTE_ERR_COMM_FAILURE;
}
OBJ_RELEASE(cmd);
return ORTE_SUCCESS;
}
char *orte_getinputline()
char *orte_console_get_input_line()
{
#if HAVE_READLINE_H
return readline("orteconsole>");
#else
char *ret, *buff;
char input[ORTE_CONSOLE_MAX_LINE_LENGTH];
printf("orteconsole> ");
ret = fgets(input, ORTE_CONSOLE_MAX_LINE_LENGTH, stdin);
if (NULL != ret) {
input[strlen(input)-1] = '\0'; /* remove newline */
buff = strdup(input);
return buff;
}
return NULL;
#endif
}

Просмотреть файл

@ -18,6 +18,7 @@
#define ORTECONSOLE_H
#define ORTE_CONSOLE_MAX_LINE_LENGTH 1024
#define ORTE_CONSOLE_MAX_ARGC 10
/*
* Local Structures
@ -27,45 +28,59 @@
typedef struct {
bool help;
opal_mutex_t lock;
opal_mutex_t lock;
opal_condition_t cond;
} orteconsole_globals_t;
} orte_console_globals_t;
enum orte_console_type_t {
ORTE_CONSOLE_TYPE_NULL,
ORTE_CONSOLE_TYPE_STD
ORTE_CONSOLE_TYPE_STD,
ORTE_CONSOLE_TYPE_HIDDEN
};
typedef enum orte_console_type_t orte_console_type_t;
typedef struct {
/* Command Name */
char * cmd_name;
char * argv[ORTE_CONSOLE_MAX_ARGC];
int argc;
} orte_console_input_command_t;
/* Structure detailing each command allowed by the console */
typedef struct {
/* Full Name for the command */
const char *cmd_full_name;
const char * cmd_full_name;
/* Common abbreviation for this command */
const char *cmd_short_name;
/* Number of expected arguments */
int cmd_args;
const char * cmd_short_name;
/* Number of expected additional arguments */
int cmd_args;
/* Type of command */
orte_console_type_t cmd_type;
/* Pointer to the function to execute */
int (*cmd_function) (void);
int (*cmd_function) (orte_console_input_command_t);
/* Short illustration of how the command should be used */
const char * cmd_usage;
/* Short description of what this command does */
const char *cmd_description;
const char * cmd_description;
} orte_console_command_t;
/*
* Function for each command
*/
static int orte_console_exit(void);
static int orte_console_help(void);
static int orte_console_contactinfo(void);
static int orte_console_dumpvm(void);
static int orte_console_exit(orte_console_input_command_t);
static int orte_console_help(orte_console_input_command_t);
static int orte_console_contactinfo(orte_console_input_command_t);
static int orte_console_dumpvm(orte_console_input_command_t);
static int orte_console_devel(orte_console_input_command_t);
/*
* Support Functions
*/
static char *orte_getinputline(void);
static void orte_console_sendcmd(orte_daemon_cmd_flag_t usercmd);
static int execute_command(char *command);
static char *orte_console_get_input_line(void);
static int orte_console_send_command(orte_daemon_cmd_flag_t usercmd);
static int orte_console_parse_command(char * usercmd, orte_console_input_command_t *input_command);
static int orte_console_execute_command(orte_console_input_command_t command);
#endif /* ORTECONSOLE_H */