Пример #1
0
int run_init(periph_t *periph, int argc, char **argv, int interactive, char *wait)
{
  /* Open WAIT synchronization output */
  if ( wait != NULL ) {
    char *err;
    int fd = strtol(wait, &err, 10);

    if ( (err != NULL) && (*err > ' ') )
      fd = -1;

    if ( fd >= 0 ) {
      if ( (run_wait_output = fdopen(fd, "w")) == NULL ) {
        fprintf(stderr, NAME ": Cannot open WAIT synchronization output fd=%d: %s\n", fd, strerror(errno));
        return -1;
      }
    }
    else {
      if ( (run_wait_output = fopen(wait, "w")) == NULL ) {
        fprintf(stderr, NAME ": Cannot open WAIT synchronization output %s: %s\n", wait, strerror(errno));
        return -1;
      }
    }

    setbuf(run_wait_output, NULL);

    /* Child programs should not have access this file descriptor */
    fcntl(fileno(run_wait_output), F_SETFD, FD_CLOEXEC);
  }

  /* Store peripheral descriptor address */
  run_periph = periph;

  /* Setup runtime log gears */
  if ( result_init() )
    return -1;

  /* Create shell engine */
  run_shell = shell_alloc(NAME, argc, argv, NULL);

  /* Set interactive mode */
  shell_set_interactive(run_shell, interactive);

  /* Setup prologue routine */
  shell_set_prologue(run_shell, run_prologue, NULL);

  /* No input echo */
  shell_set_input_echo(run_shell, NULL, NULL);

  /* Setup special commands */
  shell_set_cmd(run_shell, run_commands);

  /* Setup standard commands, standard header routine, help table */
  shell_std_set_header(result_header_engine);
  shell_std_set_echo(run_exec_echo);
  shell_std_set_unknown(run_exec_unknown);
  shell_std_setup(run_shell, run_help);

  return 0;
}
Пример #2
0
/* setenv:
 *	Interface to shell_dealloc() and shell_alloc().
 */
int
setenv(char *name,char *value)
{
	if (!shell_vars)
		return(-1);
	if ((value == (char *)0) || (*value == 0))
		return(shell_dealloc(name));
	else
		return(shell_alloc(name,value));
}
Пример #3
0
/* allocate buffer space for the (fd).
 * this should only be called when the (fd) really lacks buffer space!
 * ----------------------------------------------------------------------- */
void fd_allocbuf(struct fd *fd, unsigned long n) {
  char *p = shell_alloc(n);

  fd_setbuf(fd, p, n);
}