/* startup a client only ctdb context */ struct ctdb_context *ctdb_cmdline_client(struct tevent_context *ev, struct timeval req_timeout) { struct ctdb_context *ctdb; char *socket_name; int ret; /* initialise ctdb */ ctdb = ctdb_init(ev); if (ctdb == NULL) { fprintf(stderr, "Failed to init ctdb\n"); exit(1); } /* tell ctdb the socket address */ socket_name = getenv("CTDB_SOCKET"); if (socket_name != NULL) { ret = ctdb_set_socketname(ctdb, socket_name); if (ret == -1) { printf("ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb)); exit(1); } } if (ctdb_cmdline.socketname != NULL) { ret = ctdb_set_socketname(ctdb, ctdb_cmdline.socketname); if (ret == -1) { fprintf(stderr, "ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb)); exit(1); } } /* Set the debug level */ if (!parse_debug(ctdb_cmdline.debuglevel, &DEBUGLEVEL)) { DEBUGLEVEL = DEBUG_ERR; } ret = ctdb_socket_connect(ctdb); if (ret != 0) { fprintf(stderr, __location__ " Failed to connect to daemon\n"); talloc_free(ctdb); return NULL; } /* get our pnn */ ctdb->pnn = ctdb_ctrl_getpnn(ctdb, req_timeout, CTDB_CURRENT_NODE); if (ctdb->pnn == (uint32_t)-1) { DEBUG(DEBUG_CRIT,(__location__ " Failed to get ctdb pnn\n")); talloc_free(ctdb); return NULL; } return ctdb; }
void debug_window(Window *win, char *value, int unused) { Window *old_win = win; char *nv = NULL; internal_debug = parse_debug(value, internal_debug, &nv); set_string_var(DEBUG_VAR, nv); if (internal_debug) { Window *tmp = NULL; if (!get_window_by_name("debug") && (tmp = new_window(win->screen))) { malloc_strcpy(&tmp->name, "debug"); tmp->double_status = 0; hide_window(tmp); tmp->window_level = LOG_DEBUG; tmp->absolute_size = 1; tmp->skip = 1; debugging_window = tmp; set_wset_string_var(tmp->wset, STATUS_FORMAT1_WSET, DEFAULT_FORMAT_DEBUG_FSET); build_status(tmp, NULL, 0); update_all_windows(); set_input_prompt(win, get_string_var(INPUT_PROMPT_VAR), 0); cursor_to_input(); set_screens_current_window(old_win->screen, old_win); } } else { if ((old_win = get_window_by_name("debug"))) { delete_window(old_win); debugging_window = NULL; update_all_windows(); set_input_prompt(current_window, get_string_var(INPUT_PROMPT_VAR), 0); cursor_to_input(); } } new_free(&nv); }
static FIO_API_FUNCTION(ftdm_pritap_api) { char *mycmd = NULL, *argv[10] = { 0 }; int argc = 0; if (data) { mycmd = ftdm_strdup(data); argc = ftdm_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); } if (argc > 2) { if (!strcasecmp(argv[0], "debug")) { ftdm_span_t *span = NULL; if (ftdm_span_find_by_name(argv[1], &span) == FTDM_SUCCESS) { pritap_t *pritap = span->signal_data; if (span->start != ftdm_pritap_start) { stream->write_function(stream, "%s: -ERR invalid span.\n", __FILE__); goto done; } pri_set_debug(pritap->pri, parse_debug(argv[2])); stream->write_function(stream, "%s: +OK debug set.\n", __FILE__); goto done; } else { stream->write_function(stream, "%s: -ERR invalid span.\n", __FILE__); goto done; } } } stream->write_function(stream, "%s: -ERR invalid command.\n", __FILE__); done: ftdm_safe_free(mycmd); return FTDM_SUCCESS; }
static void parse_commandline(int argc, char *argv[]) { int c; /* command line arg */ while ((c = getopt(argc, argv, "c:dl:f:r:")) != -1) { switch (c) { case 'c': if (server_root) free(server_root); server_root = strdup(optarg); if (!server_root) { perror("strdup (for server_root)"); exit(EXIT_FAILURE); } break; case 'd': do_fork = 0; break; case 'f': config_file_name = optarg; break; case 'r': if (optarg) { chroot_dir = (char *)malloc(sizeof(optarg)); chroot_dir = strdup(optarg); } break; #ifndef DISABLE_DEBUG case 'l': parse_debug(optarg); break; #endif default: usage(argv[0]); exit(EXIT_FAILURE); } } }
/* startup daemon side of ctdb according to command line options */ struct ctdb_context *ctdb_cmdline_init(struct event_context *ev) { struct ctdb_context *ctdb; int ret; /* initialise ctdb */ ctdb = ctdb_init(ev); if (ctdb == NULL) { printf("Failed to init ctdb\n"); exit(1); } if (ctdb_cmdline.torture) { ctdb_set_flags(ctdb, CTDB_FLAG_TORTURE); } /* command line specified a socket name */ if (ctdb_cmdline.socketname != NULL) { setenv("CTDB_SOCKET", ctdb_cmdline.socketname, 1); ret = ctdb_set_socketname(ctdb, ctdb_cmdline.socketname); if (ret == -1) { printf("ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb)); exit(1); } } /* Set the debug level */ if (!parse_debug(ctdb_cmdline.debuglevel, &DEBUGLEVEL)) { DEBUGLEVEL = DEBUG_ERR; } /* set up the tree to store server ids */ ctdb->server_ids = trbt_create(ctdb, 0); return ctdb; }
static int32_t snmptool_parse_options(struct snmp_toolinfo *snmptoolctx, int argc, char **argv) { int32_t count, optnum = 0; int ch; const char *opts; switch (program) { case BSNMPWALK: opts = "dhnKA:b:C:I:i:l:M:N:o:P:p:r:s:t:U:v:"; break; case BSNMPGET: opts = "aDdehnKA:b:C:I:i:l:M:N:o:P:p:r:s:t:U:v:"; break; case BSNMPSET: opts = "adehnKA:b:C:I:i:l:o:P:r:s:t:U:v:"; break; default: return (-1); } while ((ch = getopt(argc, argv, opts)) != EOF) { switch (ch) { case 'A': count = parse_authentication(snmptoolctx, optarg); break; case 'a': count = parse_skip_access(snmptoolctx); break; case 'b': count = parse_buflen(optarg); break; case 'D': count = parse_discovery(snmptoolctx); break; case 'd': count = parse_debug(); break; case 'e': count = parse_errors(snmptoolctx); break; case 'h': usage(); return (-2); case 'C': count = parse_context(snmptoolctx, optarg); break; case 'I': count = parse_include(snmptoolctx, optarg); break; case 'i': count = parse_file(snmptoolctx, optarg); break; case 'K': count = parse_local_key(snmptoolctx); break; case 'l': count = parse_local_path(optarg); break; case 'M': count = parse_max_repetitions(snmptoolctx, optarg); break; case 'N': count = parse_non_repeaters(snmptoolctx, optarg); break; case 'n': count = parse_num_oids(snmptoolctx); break; case 'o': count = parse_output(snmptoolctx, optarg); break; case 'P': count = parse_privacy(snmptoolctx, optarg); break; case 'p': count = parse_pdu_type(snmptoolctx, optarg); break; case 'r': count = parse_retry(optarg); break; case 's': count = parse_server(optarg); break; case 't': count = parse_timeout(optarg); break; case 'U': count = parse_user_security(snmptoolctx, optarg); break; case 'v': count = parse_version(optarg); break; case '?': default: usage(); return (-1); } if (count < 0) return (-1); optnum += count; } return (optnum); }
void loop_step(const char * input) { char string[65536]; char buffer[256]; // read a line if (input != NULL) { get_local(string,65536,input); } else { get_stdin(string,65536); } // parse if (false) { } else if (string_start_with(string,"debug ")) { if (!Searching) { parse_debug(string); } else { ASSERT(false); } } else if (string_start_with(string,"go ")) { if (!Searching && !Delay) { init(); parse_go(string); } else { ASSERT(false); } } else if (string_equal(string,"isready")) { if (!Searching && !Delay) { init(); } send("readyok"); // no need to wait when searching (fixit SMK) } else if (string_equal(string,"ponderhit")) { if (Searching) { ASSERT(Infinite); SearchInput->infinite = false; Infinite = false; } else if (Delay) { send_best_move(); Delay = false; } else { ASSERT(false); } } else if (string_start_with(string,"position ")) { if (!Searching && !Delay) { init(); parse_position(string); } else { ASSERT(false); } } else if (string_equal(string,"quit")) { ASSERT(!Searching); // violated by Arena UI ASSERT(!Delay); if (Searching && option_get_int("Threads") > 1) { // Arena issue SearchInfo->stop = true; Infinite = false; smp_sleep(); } trans_free(); tb_close(); egbb_close(); smp_close(); exit(EXIT_SUCCESS); } else if (string_start_with(string,"setoption ")) { if (!Searching && !Delay) { parse_setoption(string); } else { ASSERT(false); } } else if (string_equal(string,"stop")) { if (Searching) { SearchInfo->stop = true; Infinite = false; } else if (Delay) { send_best_move(); Delay = false; } } else if (string_equal(string,"uci")) { ASSERT(!Searching); ASSERT(!Delay); send("id name Fruit reloaded %s", my_version(buffer)); send("id author Fabien Letouzey, Ryan Benitez and Daniel Mehrmann"); option_list(); send("uciok"); } else if (string_equal(string,"ucinewgame")) { if (!Searching && !Delay && Init) { trans_clear(); pawn_clear(); material_clear(); } else { ASSERT(false); } } }
/* * Parse data from a file into a policy language. */ int rlm_policy_parse(rbtree_t *policies, const char *filename) { FILE *fp; policy_lex_t token; policy_lex_file_t mylexer, *lexer = NULL; char buffer[32]; fp = fopen(filename, "r"); if (!fp) { fprintf(stderr, "Failed to open %s: %s\n", filename, strerror(errno)); return 0; } lexer = &mylexer; memset(lexer, 0, sizeof(*lexer)); lexer->filename = filename; lexer->fp = fp; lexer->token = POLICY_LEX_BAD; lexer->parse = NULL; /* initial input */ lexer->policies = policies; do { int reserved; token = policy_lex_file(lexer, 0, buffer, sizeof(buffer)); switch (token) { case POLICY_LEX_BARE_WORD: reserved = fr_str2int(policy_reserved_words, buffer, POLICY_RESERVED_UNKNOWN); switch (reserved) { case POLICY_RESERVED_POLICY: if (!parse_named_policy(lexer)) { return 0; } break; case POLICY_RESERVED_INCLUDE: if (!parse_include(lexer)) { return 0; } break; case POLICY_RESERVED_DEBUG: if (!parse_debug(lexer)) { return 0; } break; default: fprintf(stderr, "%s[%d]: Unexpected word \"%s\"\n", lexer->filename, lexer->lineno, buffer); return 0; break; } /* switch over reserved words */ case POLICY_LEX_EOF: break; default: fprintf(stderr, "%s[%d]: Illegal input\n", lexer->filename, lexer->lineno); return 0; } } while (token != POLICY_LEX_EOF); if (((lexer->debug & POLICY_DEBUG_PRINT_POLICY) != 0) && fr_log_fp) { fprintf(fr_log_fp, "# rlm_policy \n"); } debug_tokens("--------------------------------------------------\n"); return 1; }
static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_pritap_configure_span) { uint32_t i; const char *var, *val; const char *debug = NULL; pritap_mix_mode_t mixaudio = PRITAP_MIX_BOTH; ftdm_channel_t *dchan = NULL; pritap_t *pritap = NULL; ftdm_span_t *peerspan = NULL; pritap_iface_t iface = PRITAP_IFACE_UNKNOWN; unsigned paramindex = 0; if (span->trunk_type >= FTDM_TRUNK_NONE) { ftdm_log(FTDM_LOG_WARNING, "Invalid trunk type '%s' defaulting to T1.\n", ftdm_trunk_type2str(span->trunk_type)); span->trunk_type = FTDM_TRUNK_T1; } for (i = 1; i <= span->chan_count; i++) { if (span->channels[i]->type == FTDM_CHAN_TYPE_DQ921) { dchan = span->channels[i]; } } if (!dchan) { ftdm_log(FTDM_LOG_ERROR, "No d-channel specified in freetdm.conf!\n"); return FTDM_FAIL; } for (paramindex = 0; ftdm_parameters[paramindex].var; paramindex++) { var = ftdm_parameters[paramindex].var; val = ftdm_parameters[paramindex].val; ftdm_log(FTDM_LOG_DEBUG, "Tapping PRI key=value, %s=%s\n", var, val); if (!strcasecmp(var, "debug")) { debug = val; } else if (!strcasecmp(var, "mixaudio")) { if (ftdm_true(val) || !strcasecmp(val, "both")) { ftdm_log(FTDM_LOG_DEBUG, "Setting mix audio mode to 'both' for span %s\n", span->name); mixaudio = PRITAP_MIX_BOTH; } else if (!strcasecmp(val, "peer")) { ftdm_log(FTDM_LOG_DEBUG, "Setting mix audio mode to 'peer' for span %s\n", span->name); mixaudio = PRITAP_MIX_PEER; } else { ftdm_log(FTDM_LOG_DEBUG, "Setting mix audio mode to 'self' for span %s\n", span->name); mixaudio = PRITAP_MIX_SELF; } } else if (!strcasecmp(var, "interface")) { if (!strcasecmp(val, "cpe")) { iface = PRITAP_IFACE_CPE; } else if (!strcasecmp(val, "net")) { iface = PRITAP_IFACE_NET; } else { ftdm_log(FTDM_LOG_WARNING, "Ignoring invalid tapping interface type %s\n", val); } } else if (!strcasecmp(var, "peerspan")) { if (ftdm_span_find_by_name(val, &peerspan) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "Invalid tapping peer span %s\n", val); break; } } else { ftdm_log(FTDM_LOG_ERROR, "Unknown pri tapping parameter [%s]", var); } } if (!peerspan) { ftdm_log(FTDM_LOG_ERROR, "No valid peerspan was specified!\n"); return FTDM_FAIL; } pritap = ftdm_calloc(1, sizeof(*pritap)); if (!pritap) { return FTDM_FAIL; } pritap->debug = parse_debug(debug); pritap->dchan = dchan; pritap->peerspan = peerspan; pritap->mixaudio = mixaudio; pritap->iface = iface; span->start = ftdm_pritap_start; span->stop = ftdm_pritap_stop; span->sig_read = ftdm_pritap_sig_read; span->signal_cb = sig_cb; span->signal_data = pritap; span->signal_type = FTDM_SIGTYPE_ISDN; span->outgoing_call = pritap_outgoing_call; span->get_channel_sig_status = pritap_get_channel_sig_status; span->get_span_sig_status = pritap_get_span_sig_status; span->state_map = &pritap_state_map; span->state_processor = state_advance; return FTDM_SUCCESS; }