os_handler_t * ipmi_posix_thread_setup_os_handler(int wake_sig) { os_handler_t *os_hnd; pt_os_hnd_data_t *info; struct sigaction act; int rv; os_hnd = ipmi_posix_thread_get_os_handler(); if (!os_hnd) return NULL; info = os_hnd->internal_data; info->wake_sig = wake_sig; rv = sel_alloc_selector(os_hnd, &info->sel); if (rv) { ipmi_posix_thread_free_os_handler(os_hnd); os_hnd = NULL; goto out; } act.sa_handler = posix_thread_sighandler; sigemptyset(&act.sa_mask); act.sa_flags = 0; rv = sigaction(wake_sig, &act, &info->oldact); if (rv) { ipmi_posix_thread_free_os_handler(os_hnd); os_hnd = NULL; goto out; } out: return os_hnd; }
os_handler_t * ipmi_posix_setup_os_handler(void) { os_handler_t *os_hnd; selector_t *sel; int rv; iposix_info_t *info; os_hnd = ipmi_posix_get_os_handler(); if (!os_hnd) return NULL; rv = sel_alloc_selector(os_hnd, &sel); if (rv) { ipmi_posix_free_os_handler(os_hnd); os_hnd = NULL; goto out; } info = os_hnd->internal_data; info->sel = sel; out: return os_hnd; }
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"); } } }
int main(int argc, char *argv[]) { int i; int err; err = sel_alloc_selector(&ser2net_sel); if (err) { fprintf(stderr, "Could not initialize ser2net selector: '%s'\n", strerror(err)); return -1; } for (i=1; i<argc; i++) { if ((argv[i][0] != '-') || (strlen(argv[i]) != 2)) { fprintf(stderr, "Invalid argument: '%s'\n", argv[i]); arg_error(argv[0]); } switch (argv[i][1]) { case 'n': detach = 0; break; case 'd': detach = 0; debug = 1; break; case 'b': cisco_ios_baud_rates = 1; break; case 'C': /* Get a config line. */ i++; if (i == argc) { fprintf(stderr, "No config line specified with -C\n"); arg_error(argv[0]); } handle_config_line(argv[i]); config_file = NULL; break; case 'c': /* Get a config file. */ i++; if (i == argc) { fprintf(stderr, "No config file specified with -c\n"); arg_error(argv[0]); } config_file = argv[i]; break; case 'p': /* Get the control port. */ i++; if (i == argc) { fprintf(stderr, "No control port specified with -p\n"); arg_error(argv[0]); } config_port = argv[i]; break; case 'P': i++; if (i == argc) { fprintf(stderr, "No pid file specified with -P\n"); arg_error(argv[0]); } pid_file = argv[i]; break; #ifdef USE_UUCP_LOCKING case 'u': uucp_locking_enabled = 0; break; #endif case 'v': printf("%s version %s\n", argv[0], VERSION); exit(0); default: fprintf(stderr, "Invalid option: '%s'\n", argv[i]); arg_error(argv[0]); } } setup_sighup(); if (config_port != NULL) { if (controller_init(config_port) == -1) { fprintf(stderr, "Invalid control port specified with -p\n"); arg_error(argv[0]); } } if (debug && !detach) openlog("ser2net", LOG_PID | LOG_CONS | LOG_PERROR, LOG_DAEMON); if (config_file) { if (readconfig(config_file) == -1) { return 1; } } if (detach) { int pid; /* Detach from the calling terminal. */ openlog("ser2net", LOG_PID | LOG_CONS, LOG_DAEMON); syslog(LOG_NOTICE, "ser2net startup"); if ((pid = fork()) > 0) { exit(0); } else if (pid < 0) { syslog(LOG_ERR, "Error forking first fork"); exit(1); } else { /* setsid() is necessary if we really want to demonize */ setsid(); /* Second fork to really deamonize me. */ if ((pid = fork()) > 0) { exit(0); } else if (pid < 0) { syslog(LOG_ERR, "Error forking second fork"); exit(1); } } /* Close all my standard I/O. */ chdir("/"); close(0); close(1); close(2); } /* write pid file */ make_pidfile(pid_file); /* Ignore SIGPIPEs so they don't kill us. */ signal(SIGPIPE, SIG_IGN); set_sighup_handler(reread_config); sel_select_loop(ser2net_sel); return 0; }