Exemple #1
0
bool RUNSCRIPT::run(JCR *jcr, const char *name)
{
   Dmsg1(100, "runscript: running a RUNSCRIPT object type=%d\n", cmd_type);
   POOLMEM *ecmd = get_pool_memory(PM_FNAME);
   int status;
   BPIPE *bpipe;
   POOL_MEM line(PM_NAME);

   ecmd = edit_job_codes(jcr, ecmd, this->command, "", this->job_code_callback);
   Dmsg1(100, "runscript: running '%s'...\n", ecmd);
   Jmsg(jcr, M_INFO, 0, _("%s: run %s \"%s\"\n"),
        cmd_type==SHELL_CMD?"shell command":"console command", name, ecmd);

   switch (cmd_type) {
   case SHELL_CMD:
      bpipe = open_bpipe(ecmd, 0, "r");
      free_pool_memory(ecmd);

      if (bpipe == NULL) {
         berrno be;
         Jmsg(jcr, M_ERROR, 0, _("Runscript: %s could not execute. ERR=%s\n"), name,
            be.bstrerror());
         goto bail_out;
      }

      while (fgets(line.c_str(), line.size(), bpipe->rfd)) {
         strip_trailing_junk(line.c_str());
         Jmsg(jcr, M_INFO, 0, _("%s: %s\n"), name, line.c_str());
      }

      status = close_bpipe(bpipe);

      if (status != 0) {
         berrno be;
         Jmsg(jcr, M_ERROR, 0, _("Runscript: %s returned non-zero status=%d. ERR=%s\n"), name,
            be.code(status), be.bstrerror(status));
         goto bail_out;
      }

      Dmsg0(100, "runscript OK\n");
      break;
   case CONSOLE_CMD:
      if (console_command) {                 /* can we run console command? */
         if (!console_command(jcr, ecmd)) {  /* yes, do so */
            goto bail_out;
         }
      }
      break;
   }
   return true;

bail_out:
   /* cancel running job properly */
   if (fail_on_error) {
      jcr->setJobStatus(JS_ErrorTerminated);
   }
   Dmsg1(100, "runscript failed. fail_on_error=%d\n", fail_on_error);
   return false;
}
Exemple #2
0
static int console_read(void *p, int flags)
{
	char line[256];
	if(read_line(0,line,sizeof(line),100,0)==-1){
		DBGMSG("stop reading from console\n");
		clear_fd_event(0);		
	}else{
		DBGMSG("%s:%s\n",__func__,line);
	}
	if(console_command(line)==-2) return -1;
	// ignore console command errors, and return 0
	return 0;	
}
Exemple #3
0
int console_mode_main(void)
{
  struct console_state_t cs;
  
  //  DBG_PRINT("wsim:con:main: enter\n");
  console_init(&cs);
  //  DBG_PRINT("wsim:con:main:init done\n");

  console_write(&cs,cs.ps1);
  while (1)
    {
      switch (console_command(&cs))
	{
	case CON_CMD_NONE:
	  console_write(&cs,cs.ps1); /* node number */
	  break;
	case CON_CMD_OK:
	  DBG_PRINT("wsim:con:main: return OK\n");
	  console_write(&cs,cs.ps1); /* node number */
	  break;
	case CON_CMD_OK_SIG:
	  DBG_PRINT("wsim:con:main: return OK_SIG\n");
	  break;
	case CON_CMD_ERROR:
	  DBG_PRINT("wsim:con:main: return ERROR\n");
	  console_write(&cs,cs.ps1); /* add node number */
	  break;
	case CON_CMD_ERROR_SIG:
	  DBG_PRINT("wsim:con:main: return ERROR_SIG\n");
	  break;
	case CON_CMD_QUIT:
	  DBG_PRINT("wsim:con:main:exit\n");
	  return CON_QUIT;
	  break;
	}
    }

  return CON_ERROR;
}