Ejemplo n.º 1
0
static void
exit_hook( void )
{
	cmdline_cleanup();
	monitor_cleanup();
	symbols_cleanup();
}
Ejemplo n.º 2
0
Archivo: hook.c Proyecto: jollywho/nav
void call_cmd_hook(Hook *hook, HookArg *hka)
{
  log_msg("HOOK", "call_cmd_hook");
  if (hook->pat && hka && !regex_match(hook->pat, hka->arg))
    return;
  Cmdline cmd;
  cmdline_build(&cmd, hook->data.cmd);
  cmdline_req_run(NULL, &cmd);
  cmdline_cleanup(&cmd);
}
Ejemplo n.º 3
0
char* repl_elem(char *line, char *expr, List *args, int fst, int lst)
{
  Cmdline cmd;
  cmdline_build(&cmd, line);
  Token *ary = tok_arg(cmdline_lst(&cmd), 0);
  log_msg("CMDLINE", "line %s", cmd.line);
  Token *elem = container_elem(ary, args, fst, lst);
  if (!elem) {
    cmdline_cleanup(&cmd);
    return NULL;
  }

  int len = strlen(line) - (elem->end - elem->start) + strlen(expr);
  char *newexpr = malloc(sizeof(char*)*len);
  newexpr[0] = '\0';
  strncat(newexpr, line, elem->start);
  strcat(newexpr, expr);
  strcat(newexpr, &line[elem->end]);
  cmdline_cleanup(&cmd);
  return newexpr;
}
Ejemplo n.º 4
0
void stop_ex_cmd()
{
  log_msg("EXCMD", "stop_ex_cmd");
  if (ex.ex_state == EX_CMD_STATE)
    menu_stop(ex.menu);
  ex.lm = NULL;
  ex.fil = NULL;
  free(ex.line);
  cmdline_cleanup(&ex.cmd);

  if (!message_pending) {
    werase(ex.nc_win);
    wnoutrefresh(ex.nc_win);
  }
  ex.ex_state = EX_OFF_STATE;
  window_ex_cmd_end();
  cmd_flush();
  window_refresh();
}
Ejemplo n.º 5
0
static int config_cleanup(void)
{
	prefs_unload();
	cmdline_cleanup(); 
	return 0;
}
Ejemplo n.º 6
0
Archivo: main.c Proyecto: emaste/deebe
int main(int argc, char *argv[])
{
	int ret = -1;

#if 1
#ifndef DEEBE_RELEASE
	FILE *try_log = fopen(LOG_FILENAME, "wt");
	if (NULL != try_log)
		fp_log = try_log;
	else
		fp_log = stdout;

	try_log = NULL;
#endif
#else
	fp_log = stdout;
#endif

	/* Signal handlers */
	signal_handle_sigio = main_sigio;
	signal_handle_sigrtmin = main_sigrtmin;
	signal_handle_sigchld = main_sigchld;

	if (0 != cmdline_init(argc, argv)) {
		/* start the watchdog timer */
		if (cmdline_watchdog_minutes > 0) {
			/* watchdog is in seconds, for *= 60 */
			long seconds = 60 * cmdline_watchdog_minutes;
			if (!watchdog_init(seconds)) {
				/*
				 * Only report this error if timer_create
				 * is supported.  If it isn't then the watchdog
				 * functionality is simulated in the network
				 * code where read or connect delays are
				 * expected.
				 */
#ifdef HAVE_TIMER_CREATE
				fprintf(stderr, "Problem initializing watchdog timer for %ld seconds\n",
					seconds);
				/*
				 * watchdog_init does not turn on the
				 * the signal unless it is successful
				 * so we do not have to disable it
				 */
#endif
			}
		}

		if (cmdline_port_fwd > 0)
			ret = main_forward();
		else
			ret = main_debug();
	}
	cmdline_cleanup();

	if (fp_log) {
		if (fp_log != stdout) {
			fflush(fp_log);
			fclose(fp_log);
			fp_log = stdout;
		}
	}
	return ret;
}
Ejemplo n.º 7
0
extern bool cmdline_init(int argc, char *argv[]) {
  bool ret = true;
  int option_args = 0;
  int argo = 1;

  /* In case init is called multiple times.. */
  cmdline_cleanup();

  if (argc > 0)
    cmdline_program_name = strdup(argv[0]);

  for (argo = 1; argo < argc; argo++) {
    bool option_found = false;

    if (_has_parameter(argv[argo], "--version")) {
      fprintf(stdout, "%s\n", version());
      cmdline_msg = true;
      goto end;
    }

    if (_has_parameter(argv[argo], "--copyright")) {
      fprintf(stdout, "%s\n", version_copyright());
      cmdline_msg = true;
      goto end;
    }

    if (_has_parameter(argv[argo], "--license")) {
      fprintf(stdout, "%s\n", version_license());
      cmdline_msg = true;
      goto end;
    }

    if (_has_parameter(argv[argo], "--once")) {
      cmdline_once = true;
      option_found = true;
    }

    if (_has_parameter(argv[argo], "--silence-mre")) {
      cmdline_silence_memory_read_errors = true;
      option_found = true;
    }

    if (_has_parameter(argv[argo], "--watchdog")) {
      argo++;
      if (argo < argc) {
        char *m = argv[argo];
        char *e = NULL;
        long try_minutes = 0;
        try_minutes = strtol(m, &e, 10);
        /* Check for a trailing problem */
        if (try_minutes > 0) {
          /* trailing problem */
          if (e != m + strlen(m)) {
            fprintf(stderr, "Warning : Expecting a positive number for the "
                            "watchdog parameter instead of %s\n",
                    m);
            fprintf(stderr, "          Please review usage\n");
            try_minutes = 0;
          }
        } else {
          fprintf(stderr, "Warning : Expecting positive number for watchdog "
                          "parameter instead of %s\n",
                  m);
          fprintf(stderr, "          Please review usage\n");
          try_minutes = 0;
        }
        if (try_minutes > 0)
          cmdline_watchdog_minutes = try_minutes;
      }
      option_found = true;
    }

    if (!option_found)
      break;
  }
  option_args = argo - 1;

  if (argc >= option_args + 3) {

    if (_set_network_port(argv[option_args + 1], &cmdline_net, &cmdline_port)) {

      if (_has_parameter(argv[option_args + 2], "--forward")) {

        if (argc == option_args + 4) {
          /* Success */
          if (!_set_network_port(argv[option_args + 3], &cmdline_net_fwd,
                                 &cmdline_port_fwd)) {
            /* Error */
            fprintf(stderr, "Error : Unexpected --forward parameter\n");
            fprintf(stderr, "        Please review usage\n");
            print_usage();
          }
        } else {
          /* Failure */
          fprintf(stderr, "Error : Unexpected --forward parameter\n");
          fprintf(stderr, "        Please review usage\n");
          print_usage();
        }

      } else if (_has_parameter(argv[option_args + 2], "--attach")) {
        if (argc == option_args + 4) {
          /* Success */
          cmdline_pid = strtol(argv[option_args + 3], NULL, 10);
          if (0 >= cmdline_pid) {
            /* Error */
            fprintf(stderr, "Error : Unexpected --attach parameter\n");
            fprintf(stderr, "        Please review usage\n");
            print_usage();
          }
        } else {
          /* Failure */
          fprintf(stderr, "Error : Unexpected --attach parameter\n");
          fprintf(stderr, "        Please review usage\n");
          print_usage();
        }
      } else {

        cmdline_argc = argc - 2 - option_args;
        /*
         * Add 1 so array can be null terminated and
         * passed directly to execv
         */
        cmdline_argv = (char **)malloc((cmdline_argc + 1) * sizeof(char *));
        if (cmdline_argv) {
          int a;
          for (a = 0; a < cmdline_argc; a++) {
            cmdline_argv[a] = strdup(argv[a + 2 + option_args]);
            if (cmdline_argv[a] == NULL) {
              ret = false;
              fprintf(stderr, "Error : copying command line parameters\n");
            }
          }
          /* NULL terminate the last entry */
          cmdline_argv[cmdline_argc] = NULL;
        } else {
          ret = false;
          fprintf(stderr, "Error : allocating command line parameters\n");
        }
      }

    } else {
      ret = false;
      fprintf(stderr, "Error : Setting network parameters\n");
      fprintf(stderr, "        Please review usage\n");
      print_usage();
    }
  } else {
    ret = false;
    fprintf(stderr, "Error : Unexpected command line arguements\n");
    fprintf(stderr, "        Please review usage\n");
    print_usage();
  }
end:
  return ret;
}