Main Page | Class List | Directories | File List | Class Members | File Members

ipmish.c File Reference

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <termios.h>
#include <unistd.h>
#include <signal.h>
#include <OpenIPMI/selector.h>
#include <OpenIPMI/ipmi_conn.h>
#include <OpenIPMI/ipmi_err.h>
#include <OpenIPMI/ipmi_posix.h>
#include <OpenIPMI/ipmi_glib.h>
#include <OpenIPMI/ipmi_cmdlang.h>
#include <OpenIPMI/ipmi_debug.h>
#include <editline/readline.h>
#include <OpenIPMI/internal/ipmi_malloc.h>

Go to the source code of this file.

Classes

struct  out_data_s
struct  exec_list_s

Typedefs

typedef out_data_s out_data_t
typedef exec_list_s exec_list_t

Functions

static void user_input_ready (int fd, void *data, os_hnd_fd_id_t *id)
static void redraw_cmdline (int force)
static void my_vlog (os_handler_t *handler, const char *format, enum ipmi_log_type_e log_type, va_list ap)
static void enable_term_fd (ipmi_cmdlang_t *cmdlang)
static void disable_term_fd (ipmi_cmdlang_t *cmdlang)
static void out_help (FILE *s, int indent, const char *name, const char *v)
static void out_value (ipmi_cmdlang_t *info, const char *name, const char *value)
static void out_binary (ipmi_cmdlang_t *info, const char *name, const char *value, unsigned int len)
static void out_unicode (ipmi_cmdlang_t *info, const char *name, const char *value, unsigned int len)
static void down_level (ipmi_cmdlang_t *info)
static void up_level (ipmi_cmdlang_t *info)
static void cmd_done (ipmi_cmdlang_t *info)
void ipmi_cmdlang_global_err (char *objstr, char *location, char *errstr, int errval)
void ipmi_cmdlang_report_event (ipmi_cmdlang_event_t *event)
static void rl_ipmish_cb_handler (char *cmdline)
static void cleanup_term (void)
static void cleanup_sig (int sig)
static void setup_term (os_handler_t *os_hnd)
static void redisp_cmd (ipmi_cmd_info_t *cmd_info)
static void exit_cmd (ipmi_cmd_info_t *cmd_info)
static void read_cmd (ipmi_cmd_info_t *cmd_info)
static void setup_cmds (void)
static void domain_down (void *cb_data)
static void shutdown_domain_handler (ipmi_domain_t *domain, void *cb_data)
static void add_exec_str (char *str)
static void usage (char *name)
int main (int argc, char *argv[])

Variables

os_handler_t ipmi_debug_os_handlers
selector_tdebug_sel
os_hnd_fd_id_tterm_fd_id
static int done = 0
static int evcount = 0
static int handling_input = 0
static int cmd_redisp = 1
static int columns = 80
static out_data_t lout_data
static char cmdlang_objstr [IPMI_MAX_NAME_LEN]
static ipmi_cmdlang_t cmdlang
int * done_ptr = NULL
static int read_nest = 0
static exec_list_texecs
static exec_list_texecs_tail
static char * usage_str


Typedef Documentation

typedef struct exec_list_s exec_list_t
 

typedef struct out_data_s out_data_t
 


Function Documentation

static void add_exec_str char *  str  )  [static]
 

Definition at line 845 of file ipmish.c.

References e, and exec_list_s::next.

Referenced by main().

00846 {
00847     exec_list_t *e;
00848 
00849     e = malloc(sizeof(*e));
00850     if (!e) {
00851         fprintf(stderr, "Out of memory");
00852         exit(1);
00853     }
00854     e->str = str;
00855     e->next = NULL;
00856     if (execs)
00857         execs_tail->next = e;
00858     else
00859         execs = e;
00860     execs_tail = e;
00861 }

static void cleanup_sig int  sig  )  [static]
 

Definition at line 826 of file ipmish.c.

References cleanup_term(), done, ipmi_domain_iterate_domains(), ipmi_cmdlang_s::os_hnd, os_handler_s::perform_one_op, and shutdown_domain_handler().

Referenced by setup_term().

00827 {
00828     fprintf(stderr, "Exiting due to signal %d\n", sig);
00829     done = 0;
00830     ipmi_domain_iterate_domains(shutdown_domain_handler, &done);
00831     while (done)
00832         cmdlang.os_hnd->perform_one_op(cmdlang.os_hnd, NULL);
00833     cleanup_term();
00834     exit(1);
00835 }

static void cleanup_term void   )  [static]
 

Definition at line 639 of file ipmish.c.

References disable_term_fd(), and rl_callback_handler_remove().

Referenced by cleanup_sig(), and main().

00640 {
00641     rl_callback_handler_remove();
00642     disable_term_fd(&cmdlang);
00643 }

static void cmd_done ipmi_cmdlang_t info  )  [static]
 

Definition at line 506 of file ipmish.c.

References enable_term_fd(), ipmi_cmdlang_s::err, ipmi_cmdlang_s::errstr, ipmi_cmdlang_s::errstr_dynalloc, handling_input, ipmi_get_error_string(), ipmi_mem_free(), ipmi_cmdlang_s::location, ipmi_cmdlang_s::objstr, redraw_cmdline(), out_data_s::stream, and ipmi_cmdlang_s::user_data.

00507 {
00508     out_data_t *out_data = info->user_data;
00509 
00510     if (info->err) {
00511         char errval[128];
00512         if (!info->location)
00513             info->location = "";
00514         if (strlen(info->objstr) == 0) {
00515             fprintf(out_data->stream, "error: %s: %s (0x%x, %s)\n",
00516                     info->location, info->errstr,
00517                     info->err,
00518                     ipmi_get_error_string(info->err, errval, sizeof(errval)));
00519         } else {
00520             fprintf(out_data->stream, "error: %s %s: %s (0x%x, %s)\n",
00521                     info->location, info->objstr, info->errstr,
00522                     info->err,
00523                     ipmi_get_error_string(info->err, errval, sizeof(errval)));
00524         }
00525         if (info->errstr_dynalloc)
00526             ipmi_mem_free(info->errstr);
00527         info->errstr_dynalloc = 0;
00528         info->errstr = NULL;
00529         info->location = NULL;
00530         info->objstr[0] = '\0';
00531         info->err = 0;
00532     }
00533 
00534     if (done_ptr) {
00535         *done_ptr = 1;
00536     } else {
00537         handling_input = 1;
00538         redraw_cmdline(1);
00539         enable_term_fd(info);
00540         fflush(out_data->stream);
00541     }
00542 }

static void disable_term_fd ipmi_cmdlang_t cmdlang  )  [static]
 

Definition at line 201 of file ipmish.c.

References ipmi_cmdlang_s::os_hnd, and os_handler_s::remove_fd_to_wait_for.

Referenced by cleanup_term(), and read_cmd().

00202 {
00203     int rv;
00204 
00205     if (!term_fd_id)
00206         return;
00207 
00208     rv = cmdlang->os_hnd->remove_fd_to_wait_for(cmdlang->os_hnd, term_fd_id);
00209     if (rv) {
00210         fprintf(stderr, "error removing terminal handler, giving up\n");
00211         exit(1);
00212     }
00213     term_fd_id = NULL;
00214 }

static void domain_down void *  cb_data  )  [static]
 

Definition at line 808 of file ipmish.c.

Referenced by shutdown_domain_handler().

00809 {
00810     int *count = cb_data;
00811     (*count)--;
00812 }

static void down_level ipmi_cmdlang_t info  )  [static]
 

Definition at line 463 of file ipmish.c.

References out_data_s::indent, and ipmi_cmdlang_s::user_data.

00464 {
00465     out_data_t *out_data = info->user_data;
00466 
00467     out_data->indent++;
00468 }

static void enable_term_fd ipmi_cmdlang_t cmdlang  )  [static]
 

Definition at line 183 of file ipmish.c.

References os_handler_s::add_fd_to_wait_for, ipmi_cmdlang_s::os_hnd, and user_input_ready().

Referenced by cmd_done(), main(), and read_cmd().

00184 {
00185     int rv;
00186 
00187     if (term_fd_id)
00188         return;
00189 
00190     rv = cmdlang->os_hnd->add_fd_to_wait_for(cmdlang->os_hnd, 0, 
00191                                              user_input_ready,
00192                                              cmdlang,
00193                                              NULL, &term_fd_id);
00194     if (rv) {
00195         fprintf(stderr, "error enabling terminal handler, giving up\n");
00196         exit(1);
00197     }
00198 }

static void exit_cmd ipmi_cmd_info_t cmd_info  )  [static]
 

Definition at line 695 of file ipmish.c.

References done, evcount, and ipmi_cmdlang_out().

Referenced by setup_cmds().

00696 {
00697     done = 1;
00698     evcount = 0;
00699     ipmi_cmdlang_out(cmd_info, "Exiting ipmish", NULL);
00700 }

void ipmi_cmdlang_global_err char *  objstr,
char *  location,
char *  errstr,
int  errval
 

Definition at line 545 of file ipmish.c.

References cmd_redisp, done, evcount, handling_input, and redraw_cmdline().

Referenced by control_event_handler(), domain_change(), domain_con_change(), domain_event_handler(), domain_fully_up(), entity_hot_swap(), event_done(), for_each_control_handler(), for_each_entity_handler(), for_each_fru_handler(), for_each_lanparm_handler(), for_each_mc_handler(), for_each_pef_handler(), for_each_pet_handler(), for_each_sensor_handler(), for_each_solparm_handler(), fru_change(), ipmi_cmdlang_control_change(), ipmi_cmdlang_entity_change(), ipmi_cmdlang_mc_change(), ipmi_cmdlang_sensor_change(), mc_active(), mc_fully_up(), presence_change(), sensor_discrete_event_handler(), and sensor_threshold_event_handler().

00549 {
00550     if (handling_input && !done && cmd_redisp)
00551         fputc('\n', stdout);
00552     if (objstr)
00553         fprintf(stderr, "global error: %s %s: %s (0x%x)", location, objstr,
00554                 errstr, errval);
00555     else
00556         fprintf(stderr, "global error: %s: %s (0x%x)", location,
00557                 errstr, errval);
00558     evcount = 0;
00559     redraw_cmdline(0);
00560 }

void ipmi_cmdlang_report_event ipmi_cmdlang_event_t event  ) 
 

Definition at line 563 of file ipmish.c.

References cmd_redisp, done, evcount, handling_input, i, IPMI_CMDLANG_BINARY, ipmi_cmdlang_event_next_field(), ipmi_cmdlang_event_restart(), IPMI_CMDLANG_STRING, IPMI_CMDLANG_UNICODE, name, and redraw_cmdline().

Referenced by event_done().

00564 {
00565     unsigned int                level, len;
00566     enum ipmi_cmdlang_out_types type;
00567     char                        *name, *value;
00568     int                         indent2;
00569     int                         i;
00570 
00571     if (handling_input && !done && cmd_redisp)
00572         fputc('\n', stdout);
00573     ipmi_cmdlang_event_restart(event);
00574     printf("Event\n");
00575     while (ipmi_cmdlang_event_next_field(event, &level, &type, &name, &len,
00576                                          &value))
00577     {
00578         switch (type) {
00579         case IPMI_CMDLANG_STRING:
00580             if (value)
00581                 printf("  %*s%s: %s\n", level*2, "", name, value);
00582             else
00583                 printf("  %*s%s\n", level*2, "", name);
00584             break;
00585 
00586         case IPMI_CMDLANG_BINARY:
00587         case IPMI_CMDLANG_UNICODE:
00588             indent2 = (level * 2) + strlen(name) + 1;
00589             printf("  %*s%s:", level*2, "", name);
00590             for (i=0; i<len; i++) {
00591                 if ((i != 0) && ((i % 8) == 0))
00592                     printf("\n  %*s", indent2, "");
00593                 printf(" 0x%2.2x", value[i] & 0xff);
00594             }
00595             printf("\n");
00596     
00597             fflush(stdout);
00598             break;
00599         }
00600     }
00601     evcount = 0;
00602     redraw_cmdline(0);
00603 }

int main int  argc,
char *  argv[]
 

Definition at line 890 of file ipmish.c.

References add_exec_str(), cleanup_term(), DEBUG_LOCKS_ENABLE, DEBUG_MALLOC_ENABLE, DEBUG_MSG_ENABLE, DEBUG_MSG_ERR_ENABLE, DEBUG_RAWMSG_ENABLE, done, e, enable_term_fd(), evcount, glib_handle_log(), handling_input, ipmi_cmdlang_cleanup(), ipmi_cmdlang_init(), ipmi_debug_malloc_cleanup(), ipmi_domain_iterate_domains(), ipmi_glib_get_os_handler(), ipmi_init(), ipmi_posix_os_handler_get_sel(), ipmi_posix_setup_os_handler(), ipmi_shutdown(), my_vlog(), exec_list_s::next, os_hnd, os_handler_s::perform_one_op, rl_ipmish_cb_handler(), sel_alloc_selector(), os_handler_s::set_log_handler, setup_cmds(), setup_term(), shutdown_domain_handler(), exec_list_s::str, and usage().

00891 {
00892     int              rv;
00893     int              curr_arg = 1;
00894     const char       *arg;
00895 #ifdef HAVE_UCDSNMP
00896     int              init_snmp = 0;
00897     selector_t       *sel;
00898 #endif
00899     os_handler_t     *os_hnd;
00900     int              use_debug_os = 0;
00901     char             *colstr;
00902 #ifdef HAVE_GLIB
00903     int              use_glib = 0;
00904 #endif
00905 
00906     colstr = getenv("COLUMNS");
00907     if (colstr) {
00908         int tmp = strtoul(colstr, NULL, 0);
00909         if (tmp) 
00910             columns = tmp;
00911     }
00912 
00913     while ((curr_arg < argc) && (argv[curr_arg][0] == '-')) {
00914         arg = argv[curr_arg];
00915         curr_arg++;
00916         if (strcmp(arg, "--") == 0) {
00917             break;
00918         } else if ((strcmp(arg, "-x") == 0) || (strcmp(arg, "--execute") == 0))
00919         {
00920             if (curr_arg >= argc) {
00921                 fprintf(stderr, "No option given for %s", arg);
00922                 usage(argv[0]);
00923                 return 1;
00924             }
00925             add_exec_str(argv[curr_arg]);
00926             curr_arg++;
00927         } else if (strcmp(arg, "--dlock") == 0) {
00928             DEBUG_LOCKS_ENABLE();
00929             use_debug_os = 1;
00930         } else if (strcmp(arg, "--dmem") == 0) {
00931             DEBUG_MALLOC_ENABLE();
00932         } else if (strcmp(arg, "--drawmsg") == 0) {
00933             DEBUG_RAWMSG_ENABLE();
00934         } else if (strcmp(arg, "--dmsg") == 0) {
00935             DEBUG_MSG_ENABLE();
00936         } else if (strcmp(arg, "--dmsgerr") == 0) {
00937             DEBUG_MSG_ERR_ENABLE();
00938 #ifdef HAVE_UCDSNMP
00939         } else if (strcmp(arg, "--snmp") == 0) {
00940             init_snmp = 1;
00941 #endif
00942 #ifdef HAVE_GLIB
00943         } else if (strcmp(arg, "--glib") == 0) {
00944             use_glib = 1;
00945 #endif
00946         } else if (strcmp(arg, "--help") == 0) {
00947             usage(argv[0]);
00948             return 0;
00949         } else {
00950             fprintf(stderr, "Unknown option: %s\n", arg);
00951             usage(argv[0]);
00952             return 1;
00953         }
00954     }
00955 
00956     if (use_debug_os) {
00957         os_hnd = &ipmi_debug_os_handlers;
00958         rv = sel_alloc_selector(os_hnd, &debug_sel);
00959         if (rv) {
00960             fprintf(stderr, "Could not allocate selector\n");
00961             return 1;
00962         }
00963 #ifdef HAVE_UCDSNMP
00964         sel = debug_sel;
00965 #endif
00966 #ifdef HAVE_GLIB
00967     } else if (use_glib) {
00968 #ifdef HAVE_UCDSNMP
00969         init_snmp = 0; /* No SNMP support for glib yet. */
00970         sel = NULL;
00971 #endif
00972         g_thread_init(NULL);
00973         os_hnd = ipmi_glib_get_os_handler();
00974         if (!os_hnd) {
00975             fprintf(stderr,
00976                     "ipmi_smi_setup_con: Unable to allocate os handler\n");
00977             return 1;
00978         }
00979         g_log_set_handler("OpenIPMI",
00980                           G_LOG_LEVEL_ERROR
00981                           | G_LOG_LEVEL_CRITICAL
00982                           | G_LOG_LEVEL_WARNING
00983                           | G_LOG_LEVEL_MESSAGE
00984                           | G_LOG_LEVEL_INFO
00985                           | G_LOG_LEVEL_DEBUG
00986                           | G_LOG_FLAG_FATAL,
00987                           glib_handle_log,
00988                           NULL);
00989 #endif
00990     } else {
00991         os_hnd = ipmi_posix_setup_os_handler();
00992         if (!os_hnd) {
00993             fprintf(stderr,
00994                     "ipmi_smi_setup_con: Unable to allocate os handler\n");
00995             return 1;
00996         }
00997 #ifdef HAVE_UCDSNMP
00998         sel = ipmi_posix_os_handler_get_sel(os_hnd);
00999 #endif
01000     }
01001 
01002     os_hnd->set_log_handler(os_hnd, my_vlog);
01003 
01004     /* Initialize the OpenIPMI library. */
01005     ipmi_init(os_hnd);
01006 
01007 #ifdef HAVE_UCDSNMP
01008     if (init_snmp) {
01009         if (snmp_init(sel) < 0)
01010             return 1;
01011     }
01012 #endif
01013 
01014     rv = ipmi_cmdlang_init(os_hnd);
01015     if (rv) {
01016         fprintf(stderr, "Unable to initialize command processor: 0x%x\n", rv);
01017         return 1;
01018     }
01019 
01020     setup_cmds();
01021 
01022     setup_term(os_hnd);
01023 
01024     while (execs) {
01025         exec_list_t *e = execs;
01026         int         cdone = 0;
01027         read_nest = 1;
01028         execs = e->next;
01029         printf("> %s\n", e->str);
01030         fflush(stdout);
01031         done_ptr = &cdone;
01032         rl_ipmish_cb_handler(e->str);
01033         while (!cdone)
01034             os_hnd->perform_one_op(os_hnd, NULL);
01035         done_ptr = NULL;
01036         free(e);
01037         read_nest = 0;
01038     }
01039 
01040     fflush(stdout);
01041 
01042     handling_input = 1;
01043     enable_term_fd(&cmdlang);
01044 
01045     while (!done)
01046         os_hnd->perform_one_op(os_hnd, NULL);
01047 
01048     cleanup_term();
01049 
01050     /* Shut down all existing domains. */
01051     
01052     done = 0;
01053     ipmi_domain_iterate_domains(shutdown_domain_handler, &done);
01054     while (done)
01055         os_hnd->perform_one_op(os_hnd, NULL);
01056 
01057     ipmi_cmdlang_cleanup();
01058     ipmi_shutdown();
01059 
01060     ipmi_debug_malloc_cleanup();
01061 
01062     os_hnd->free_os_handler(os_hnd);
01063 
01064     /* remove the prompt which editline printed */
01065     printf("\b\b  \b\b");
01066     if (evcount)
01067         printf("\n");
01068     fflush(stdout);
01069 
01070     if (rv)
01071         return 1;
01072     return 0;
01073 }

static void my_vlog os_handler_t handler,
const char *  format,
enum ipmi_log_type_e  log_type,
va_list  ap
[static]
 

Definition at line 101 of file ipmish.c.

References cmd_redisp, done, handling_input, IPMI_LOG_DEBUG, IPMI_LOG_DEBUG_CONT, IPMI_LOG_DEBUG_END, IPMI_LOG_DEBUG_START, IPMI_LOG_ERR_INFO, IPMI_LOG_FATAL, IPMI_LOG_INFO, IPMI_LOG_SEVERE, IPMI_LOG_WARNING, and redraw_cmdline().

Referenced by main(), and test_os_handler().

00105 {
00106     int do_nl = 1;
00107     static int last_was_cont = 0;
00108 
00109     if (handling_input && !last_was_cont && !done && cmd_redisp) 
00110         fputc('\n', stdout);
00111 
00112     last_was_cont = 0;
00113     switch(log_type) {
00114     case IPMI_LOG_INFO:
00115         printf("INFO: ");
00116         break;
00117 
00118     case IPMI_LOG_WARNING:
00119         printf("WARN: ");
00120         break;
00121 
00122     case IPMI_LOG_SEVERE:
00123         printf("SEVR: ");
00124         break;
00125 
00126     case IPMI_LOG_FATAL:
00127         printf("FATL: ");
00128         break;
00129 
00130     case IPMI_LOG_ERR_INFO:
00131         printf("EINF: ");
00132         break;
00133 
00134     case IPMI_LOG_DEBUG_START:
00135         do_nl = 0;
00136         last_was_cont = 1;
00137         /* FALLTHROUGH */
00138     case IPMI_LOG_DEBUG:
00139         printf("DEBG: ");
00140         break;
00141 
00142     case IPMI_LOG_DEBUG_CONT:
00143         last_was_cont = 1;
00144         do_nl = 0;
00145         /* FALLTHROUGH */
00146     case IPMI_LOG_DEBUG_END:
00147         break;
00148     }
00149 
00150     vprintf(format, ap);
00151     if (do_nl) {
00152         printf("\n");
00153         redraw_cmdline(0);
00154     }
00155 }

static void out_binary ipmi_cmdlang_t info,
const char *  name,
const char *  value,
unsigned int  len
[static]
 

Definition at line 432 of file ipmish.c.

References ipmi_cmdlang_s::help, i, out_data_s::indent, out_data_s::stream, and ipmi_cmdlang_s::user_data.

Referenced by out_unicode().

00434 {
00435     out_data_t *out_data = info->user_data;
00436     unsigned char *data = (unsigned char *) value;
00437     int indent2 = (out_data->indent * 2) + strlen(name) + 1;
00438     int i;
00439     char *sep = ":";
00440 
00441     if (info->help)
00442       sep = "";
00443 
00444     fprintf(out_data->stream, "%*s%s%s", out_data->indent*2, "", name, sep);
00445     for (i=0; i<len; i++) {
00446         if ((i != 0) && ((i % 8) == 0))
00447             fprintf(out_data->stream, "\n%*s", indent2, "");
00448         fprintf(out_data->stream, " 0x%2.2x", (data[i] & 0xff));
00449     }
00450     fprintf(out_data->stream, "\n");
00451     
00452     fflush(out_data->stream);
00453 }

static void out_help FILE *  s,
int  indent,
const char *  name,
const char *  v
[static]
 

Definition at line 381 of file ipmish.c.

References pos.

Referenced by out_value().

00382 {
00383     int pos, endpos;
00384     const char *endword;
00385     const char *endspace;
00386 
00387     pos = fprintf(s, "%*s%s ", indent, "", name);
00388     while (*v) {
00389         endword = v;
00390         while (isspace(*endword)) {
00391             if (*endword == '\n') {
00392                 v = endword + 1;
00393                 fprintf(s, "\n%*s", indent+2, "");
00394                 pos = indent + 2;
00395             }
00396             endword++;
00397         }
00398         endspace = endword;
00399         while (*endword && !isspace(*endword))
00400             endword++;
00401         endpos = pos + endword - v;
00402         if (endpos > columns) {
00403             v = endspace;
00404             fprintf(s, "\n%*s", indent+2, "");
00405             pos = indent + 2;
00406         }
00407         fwrite(v, 1, endword-v, s);
00408         pos += endword - v;
00409         v = endword;
00410     }
00411     fputc('\n', s);
00412 }

static void out_unicode ipmi_cmdlang_t info,
const char *  name,
const char *  value,
unsigned int  len
[static]
 

Definition at line 456 of file ipmish.c.

References out_binary().

00458 {
00459     out_binary(info, name, value, len);
00460 }

static void out_value ipmi_cmdlang_t info,
const char *  name,
const char *  value
[static]
 

Definition at line 415 of file ipmish.c.

References ipmi_cmdlang_s::help, out_data_s::indent, out_help(), out_data_s::stream, and ipmi_cmdlang_s::user_data.

00416 {
00417     out_data_t *out_data = info->user_data;
00418 
00419     if (value) {
00420         if (info->help) {
00421             out_help(out_data->stream, out_data->indent*2, name, value);
00422         } else {
00423             fprintf(out_data->stream, "%*s%s: %s\n", out_data->indent*2, "",
00424                     name, value);
00425         }
00426     } else
00427         fprintf(out_data->stream, "%*s%s\n", out_data->indent*2, "", name);
00428     fflush(out_data->stream);
00429 }

static void read_cmd ipmi_cmd_info_t cmd_info  )  [static]
 

Definition at line 704 of file ipmish.c.

References disable_term_fd(), enable_term_fd(), ipmi_cmdlang_s::err, ipmi_cmdlang_s::errstr, handling_input, out_data_s::indent, ipmi_cmdinfo_get_cmdlang(), ipmi_cmdlang_get_argc(), ipmi_cmdlang_get_argv(), ipmi_cmdlang_get_curr_arg(), ipmi_cmdlang_handle(), ipmi_cmdlang_out(), ipmi_cmdlang_s::location, ipmi_cmdlang_s::os_hnd, os_handler_s::perform_one_op, s, out_data_s::stream, and ipmi_cmdlang_s::user_data.

Referenced by setup_cmds().

00705 {
00706     ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info);
00707     int            cdone;
00708     char           cmdline[256];
00709     FILE           *s;
00710     out_data_t     my_out_data;
00711     ipmi_cmdlang_t my_cmdlang = *cmdlang;
00712     int            curr_arg = ipmi_cmdlang_get_curr_arg(cmd_info);
00713     int            argc = ipmi_cmdlang_get_argc(cmd_info);
00714     char           **argv = ipmi_cmdlang_get_argv(cmd_info);
00715     int            *saved_done_ptr;
00716     char           *fname;
00717 
00718     if ((argc - curr_arg) < 1) {
00719         cmdlang->errstr = "No filename entered";
00720         cmdlang->err = EINVAL;
00721         goto out_err;
00722     }
00723 
00724     fname = argv[curr_arg];
00725     curr_arg++;
00726     s = fopen(fname, "r");
00727     if (!s) {
00728         cmdlang->errstr = "Unable to openfile";
00729         cmdlang->err = errno;
00730         goto out_err;
00731     }
00732 
00733     if (!read_nest) {
00734         handling_input = 0;
00735         disable_term_fd(cmdlang);
00736     }
00737     read_nest++;
00738     saved_done_ptr = done_ptr;
00739 
00740     /* not record the file's commands into history */
00741     while (fgets(cmdline, sizeof(cmdline), s)) {
00742         my_out_data.stream = stdout;
00743         my_out_data.indent = 0;
00744         my_cmdlang.user_data = &my_out_data;
00745         cdone = 0;
00746         done_ptr = &cdone;
00747         printf("> %s", cmdline);
00748         fflush(stdout);
00749         ipmi_cmdlang_handle(&my_cmdlang, cmdline);
00750         while (!cdone)
00751             cmdlang->os_hnd->perform_one_op(cmdlang->os_hnd, NULL);
00752         done_ptr = NULL;
00753     }
00754     fclose(s);
00755 
00756     done_ptr = saved_done_ptr;
00757     read_nest--;
00758     if (!read_nest) {
00759         handling_input = 1;
00760         enable_term_fd(cmdlang);
00761     }
00762 
00763     ipmi_cmdlang_out(cmd_info, "File read", fname);
00764 
00765     return;
00766 
00767  out_err:
00768     cmdlang->location = "ipmish.c(read_cmd)";
00769 }

static void redisp_cmd ipmi_cmd_info_t cmd_info  )  [static]
 

Definition at line 664 of file ipmish.c.

References cmd_redisp, ipmi_cmdlang_s::err, ipmi_cmdlang_s::errstr, ipmi_cmdinfo_get_cmdlang(), ipmi_cmdlang_get_argc(), ipmi_cmdlang_get_argv(), ipmi_cmdlang_get_bool(), ipmi_cmdlang_get_curr_arg(), ipmi_cmdlang_out(), and ipmi_cmdlang_s::location.

Referenced by setup_cmds().

00665 {
00666     ipmi_cmdlang_t  *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info);
00667     int             curr_arg = ipmi_cmdlang_get_curr_arg(cmd_info);
00668     int             argc = ipmi_cmdlang_get_argc(cmd_info);
00669     char            **argv = ipmi_cmdlang_get_argv(cmd_info);
00670     int             redisp;
00671 
00672     if ((argc - curr_arg) < 1) {
00673         /* Not enough parameters */
00674         cmdlang->errstr = "Not enough parameters";
00675         cmdlang->err = EINVAL;
00676         goto out_err;
00677     }
00678 
00679     ipmi_cmdlang_get_bool(argv[curr_arg], &redisp, cmd_info);
00680     if (cmdlang->err) {
00681         cmdlang->errstr = "redisp setting invalid";
00682         goto out_err;
00683     }
00684     curr_arg++;
00685 
00686     cmd_redisp = redisp;
00687 
00688     ipmi_cmdlang_out(cmd_info, "redisp set", NULL);
00689 
00690  out_err:
00691     cmdlang->location = "ipmish.c(redisp_cmd)";
00692 }

static void redraw_cmdline int  force  )  [static]
 

Definition at line 88 of file ipmish.c.

References cmd_redisp, done, handling_input, and rl_redisplay().

Referenced by cmd_done(), ipmi_cmdlang_global_err(), ipmi_cmdlang_report_event(), and my_vlog().

00089 {
00090     int redisp = cmd_redisp;
00091 
00092     if (force)
00093         redisp = 1;
00094     if (!done && handling_input && redisp) {
00095         rl_redisplay();
00096         fflush(stdout);
00097     }
00098 }

static void rl_ipmish_cb_handler char *  cmdline  )  [static]
 

Definition at line 612 of file ipmish.c.

References add_history(), done, ipmi_cmdlang_s::err, ipmi_cmdlang_s::errstr, ipmi_cmdlang_s::errstr_dynalloc, evcount, handling_input, history_expand(), ipmi_cmdlang_handle(), and ipmi_cmdlang_s::location.

Referenced by main(), and setup_term().

00613 {
00614     char *expansion = NULL;
00615     int result;
00616 
00617     if (cmdline == NULL) {
00618         done = 1;
00619         evcount = 1; /* Force a newline */
00620         return;
00621     }
00622     result = history_expand(cmdline, &expansion);
00623     if (result < 0 || result == 2) {
00624         fprintf(stderr, "%s\n", expansion);
00625     } else if (expansion && strlen(expansion)){
00626         cmdlang.err = 0;
00627         cmdlang.errstr = NULL;
00628         cmdlang.errstr_dynalloc = 0;
00629         cmdlang.location = NULL;
00630         handling_input = 0;
00631         add_history(expansion);
00632         ipmi_cmdlang_handle(&cmdlang, expansion);
00633     }
00634     if (expansion)
00635         free(expansion);
00636 }

static void setup_cmds void   )  [static]
 

Definition at line 772 of file ipmish.c.

References exit_cmd(), ipmi_cmdlang_reg_cmd(), read_cmd(), and redisp_cmd().

Referenced by main().

00773 {
00774     int rv;
00775 
00776     rv = ipmi_cmdlang_reg_cmd(NULL,
00777                               "redisp_cmd",
00778                               "on|off - If an asynchronous event comes in,"
00779                               " redisplay the current working command.  This"
00780                               " is on by default.",
00781                               redisp_cmd, NULL, NULL, NULL);
00782     if (rv) {
00783         fprintf(stderr, "Error adding exit command: 0x%x\n", rv);
00784         exit(1);
00785     }
00786 
00787     rv = ipmi_cmdlang_reg_cmd(NULL,
00788                               "exit",
00789                               "- leave the program",
00790                               exit_cmd, NULL, NULL, NULL);
00791     if (rv) {
00792         fprintf(stderr, "Error adding exit command: 0x%x\n", rv);
00793         exit(1);
00794     }
00795 
00796     rv = ipmi_cmdlang_reg_cmd(NULL,
00797                               "read",
00798                               "<file> - Read commands from the file and"
00799                               " execute them",
00800                               read_cmd, NULL, NULL, NULL);
00801     if (rv) {
00802         fprintf(stderr, "Error adding read command: 0x%x\n", rv);
00803         exit(1);
00804     }
00805 }

static void setup_term os_handler_t os_hnd  )  [static]
 

Definition at line 648 of file ipmish.c.

References cleanup_sig(), ipmi_cmdlang_s::os_hnd, rl_callback_handler_install(), rl_ipmish_cb_handler(), stifle_history(), and out_data_s::stream.

Referenced by main().

00649 {
00650     signal(SIGINT, cleanup_sig);
00651     signal(SIGPIPE, cleanup_sig);
00652     signal(SIGUSR1, cleanup_sig);
00653     signal(SIGUSR2, cleanup_sig);
00654     signal(SIGPWR, cleanup_sig);
00655 
00656     stifle_history(500);
00657     rl_callback_handler_install("> ", rl_ipmish_cb_handler);
00658     lout_data.stream = stdout;
00659 
00660     cmdlang.os_hnd = os_hnd;
00661 }

static void shutdown_domain_handler ipmi_domain_t domain,
void *  cb_data
[static]
 

Definition at line 815 of file ipmish.c.

References domain_down(), and ipmi_domain_close().

Referenced by cleanup_sig(), and main().

00816 {
00817     int *count = cb_data;
00818     int rv;
00819 
00820     rv = ipmi_domain_close(domain, domain_down, cb_data);
00821     if (!rv)
00822         (*count)++;
00823 }

static void up_level ipmi_cmdlang_t info  )  [static]
 

Definition at line 471 of file ipmish.c.

References out_data_s::indent, and ipmi_cmdlang_s::user_data.

00472 {
00473     out_data_t *out_data = info->user_data;
00474 
00475     out_data->indent--;
00476 }

static void usage char *  name  )  [static]
 

Definition at line 884 of file ipmish.c.

Referenced by main().

00885 {
00886     fprintf(stderr, usage_str, name, name);
00887 }

static void user_input_ready int  fd,
void *  data,
os_hnd_fd_id_t id
[static]
 

Definition at line 606 of file ipmish.c.

References rl_callback_read_char().

Referenced by enable_term_fd(), ipmi_ui_init(), and main().

00607 {
00608     rl_callback_read_char();
00609 }