int main(int argc, char *argv[]) { int rv; int curr_arg; ipmi_args_t *args; int i; progname = argv[0]; /* Have to initalize this first so the usage help will work, since it needs OpenIPMI initialized. */ /* OS handler allocated first. */ os_hnd = ipmi_posix_get_os_handler(); if (!os_hnd) { fprintf(stderr, "ipmi_smi_setup_con: Unable to allocate os handler\n"); exit(1); } /* Create selector with os handler. */ rv = sel_alloc_selector_nothread(&sel); if (rv) { fprintf(stderr, "Error allocating selector: 0x%x\n", rv); exit(1); } /* The OS handler has to know about the selector. */ ipmi_posix_os_handler_set_sel(os_hnd, sel); /* Initialize the OEM handlers. */ rv = ipmi_init(os_hnd); if (rv) { fprintf(stderr, "Error initializing connections: 0x%x\n", rv); exit(1); } for (i=1; i<argc; i++) { if (argv[i][0] != '-') break; if (strcmp(argv[i], "--") == 0) { i++; break; } else if ((strcmp(argv[i], "-k") == 0) || (strcmp(argv[i], "--command") == 0)) { i++; if (i >= argc) { usage(); exit(1); } cmdstr = argv[i]; interactive = 0; } else if ((strcmp(argv[i], "-v") == 0) || (strcmp(argv[i], "--version") == 0)) { printInfo(); exit(0); } else { usage(); exit(1); } } if (i >= argc) { fprintf(stderr, "Not enough arguments\n"); exit(1); } curr_arg = i; if (strcmp(argv[0], "ipmicmd") == 0) /* Backwards compatible interface */ rv = ipmi_parse_args(&curr_arg, argc, argv, &args); else rv = ipmi_parse_args2(&curr_arg, argc, argv, &args); if (rv) { fprintf(stderr, "Error parsing command arguments, argument %d: %s\n", curr_arg, strerror(rv)); exit(1); } rv = ipmi_args_setup_con(args, os_hnd, sel, &con); if (rv) { fprintf(stderr, "ipmi_ip_setup_con: %s\n", strerror(rv)); exit(1); } if (interactive) { rv = con->add_event_handler(con, event_handler, NULL); if (rv) { fprintf(stderr, "Could not set to get events: %x\n", rv); } sel_set_fd_handlers(sel, 0, NULL, user_input_ready, NULL, NULL, NULL); sel_set_fd_read_handler(sel, 0, SEL_FD_HANDLER_ENABLED); } con->add_con_change_handler(con, con_changed_handler, NULL); rv = con->start_con(con); if (rv) { fprintf(stderr, "Could not start connection: %x\n", rv); exit(1); } if (interactive) printf("=> "); fflush(stdout); while (continue_operation) { rv = os_hnd->perform_one_op(os_hnd, NULL); if (rv) break; } leave(rv); return rv; }
int main(int argc, char *argv[]) { int rv; int curr_arg = 1; const char *arg; int full_screen = 1; ipmi_domain_id_t domain_id; int i; #ifdef HAVE_UCDSNMP int init_snmp = 0; #endif ipmi_args_t *con_parms[2]; ipmi_con_t *con[2]; int last_con = 0; selector_t *selector; while ((curr_arg < argc) && (argv[curr_arg][0] == '-')) { arg = argv[curr_arg]; curr_arg++; if (strcmp(arg, "--") == 0) { break; } else if (strcmp(arg, "-c") == 0) { full_screen = 0; } else if (strcmp(arg, "-dlock") == 0) { DEBUG_LOCKS_ENABLE(); } else if (strcmp(arg, "-dmem") == 0) { DEBUG_MALLOC_ENABLE(); } else if (strcmp(arg, "-drawmsg") == 0) { DEBUG_RAWMSG_ENABLE(); } else if (strcmp(arg, "-dmsg") == 0) { DEBUG_MSG_ENABLE(); #ifdef HAVE_UCDSNMP } else if (strcmp(arg, "-snmp") == 0) { init_snmp = 1; #endif } else { fprintf(stderr, "Unknown option: %s\n", arg); return 1; } } rv = ipmi_ui_init(&selector, full_screen); #ifdef HAVE_UCDSNMP if (init_snmp) { if (snmp_init(selector) < 0) goto out; } #endif next_con: rv = ipmi_parse_args(&curr_arg, argc, argv, &con_parms[last_con]); if (rv) { fprintf(stderr, "Error parsing command arguments, argument %d: %s\n", curr_arg, strerror(rv)); exit(1); } last_con++; if (curr_arg < argc) { if (last_con == 2) { fprintf(stderr, "Too many connections\n"); rv = EINVAL; goto out; } goto next_con; } for (i=0; i<last_con; i++) { rv = ipmi_args_setup_con(con_parms[i], &ipmi_ui_cb_handlers, selector, &con[i]); if (rv) { fprintf(stderr, "ipmi_ip_setup_con: %s", strerror(rv)); exit(1); } } for (i=0; i<last_con; i++) ipmi_free_args(con_parms[i]); rv = ipmi_open_domain("first", con, last_con, ipmi_ui_setup_done, NULL, NULL, NULL, NULL, 0, &domain_id); if (rv) { fprintf(stderr, "ipmi_init_domain: %s\n", strerror(rv)); goto out; } sel_select_loop(selector, NULL, 0, NULL); out: ipmi_ui_shutdown(); if (rv) return 1; return 0; }
int main(int argc, const char *argv[]) { int rv; int curr_arg = 1; ipmi_args_t *args; ipmi_con_t *con; progname = argv[0]; /* OS handler allocated first. */ os_hnd = ipmi_posix_get_os_handler(); if (!os_hnd) { printf("ipmi_smi_setup_con: Unable to allocate os handler\n"); exit(1); } /* Create selector with os handler. */ sel_alloc_selector(os_hnd, &sel); /* The OS handler has to know about the selector. */ ipmi_posix_os_handler_set_sel(os_hnd, sel); /* Initialize the OpenIPMI library. */ ipmi_init(os_hnd); #if 1 if(argc > 1) { argc--; sname = argv[1]; argv++; }else { usage(); exit(-1); } #endif rv = ipmi_parse_args(&curr_arg, argc, argv, &args); if (rv) { fprintf(stderr, "Error parsing command arguments, argument %d: %s\n", curr_arg, strerror(rv)); usage(); exit(1); } rv = ipmi_args_setup_con(args, os_hnd, sel, &con); if (rv) { fprintf(stderr, "ipmi_ip_setup_con: %s", strerror(rv)); exit(1); } rv = ipmi_init_domain(&con, 1, setup_done, NULL, NULL, NULL); if (rv) { fprintf(stderr, "ipmi_init_domain: %s\n", strerror(rv)); exit(1); } /* We run the select loop here, this shows how you can use sel_select. You could add your own processing in this loop. */ while (1) { sel_select(sel, NULL, 0, NULL, NULL); if (done) { done = 0; printf("done\n"); } } }