Ejemplo n.º 1
0
static pwr_tStatus events (
  ini_sContext	*cp
)
{
  pwr_tStatus	sts = INI__SUCCESS;
  qcom_sGet	get;
#if defined(OS_LYNX) || defined(OS_LINUX)
  int		tmo_ms = 1000;
#else
  int		tmo_ms = qcom_cTmoEternal;
#endif

  cp->myQ.qix = 550715;
  cp->myQ.nid = 0;

  qcom_CreateQ(&sts, &cp->myQ, NULL, "events");
  if (EVEN(sts)) {
    errh_LogFatal(&cp->log, "qcom_CreateQ, %m", sts);
    exit(sts);
  }

  for (;;) {

    get.data = NULL;
    qcom_Get(&sts, &cp->myQ, &get, tmo_ms);
    
    /* Request for termination ?? */
    if (sts != QCOM__TMO && sts != QCOM__QEMPTY && get.type.b == 11) {
      sts = terminate(cp);
      return sts;
    }    

  }
  return INI__SUCCESS;
}
Ejemplo n.º 2
0
static int checkErrors(ini_sContext* cp)
{

  if (cp->warnings == 0 && cp->errors == 0 && cp->fatals == 0)
    return 1;

  if (cp->fatals > 0)
  {
    errh_LogFatal(&cp->log,
                  "Found %d warning(s), %d error(s) and %d fatal error(s)",
                  cp->warnings, cp->errors, cp->fatals);
    if (cp->flags.b.ignoreFatal)
    {
      errh_LogInfo(&cp->log,
                   "Ignoring fatal errors, errors and warnings, continued...");
      return 1;
    }
    else
    {
      return ask_yes_no("Do you want to continue");
    }
  }
  if (cp->errors > 0)
  {
    errh_LogError(&cp->log,
                  "Found %d warning(s), %d error(s) and %d fatal error(s)",
                  cp->warnings, cp->errors, cp->fatals);
    if (cp->flags.b.ignoreError)
    {
      errh_LogInfo(&cp->log, "Ignoring errors and warnings, continued...");
      return 1;
    }
    else
    {
      return ask_yes_no("Do you want to continue");
    }
  }
  if (cp->warnings > 0)
  {
    errh_LogWarning(&cp->log,
                    "Found %d warning(s), %d error(s) and %d fatal error(s)",
                    cp->warnings, cp->errors, cp->fatals);
    if (cp->flags.b.ignoreWarning)
    {
      errh_LogInfo(&cp->log, "Ignoring warnings, continued...");
      return 1;
    }
    else
    {
      return ask_yes_no("Do you want to continue");
    }
  }
  return 1;
}
Ejemplo n.º 3
0
static pwr_tStatus
events (
  ini_sContext	*cp
)
{
  lst_sEntry	*pl;
  ini_sProc	*pp;
  pid_t		pid;
  pid_t		last_pid = 1;
  pwr_tStatus	sts = INI__SUCCESS;
  qcom_sGet	get;
#if defined OS_POSIX
  int		tmo_ms = 1000;
#else
  int		tmo_ms = qcom_cTmoEternal;
#endif

  cp->myQ.qix = 550715;
  cp->myQ.nid = 0;

  qcom_CreateQ(&sts, &cp->myQ, NULL, "events");
  if (EVEN(sts)) {
    errh_LogFatal(&cp->log, "qcom_CreateQ, %m", sts);
    exit(sts);
  }

  for (;;) {
    int status;

    get.data = NULL;
    qcom_Get(&sts, &cp->myQ, &get, tmo_ms);
    
    /* Request for termination ?? */
    if (sts != QCOM__TMO && sts != QCOM__QEMPTY && get.type.b == 11) {
      sts = terminate(cp);
      return sts;
    }
    
    /* Request for restart */
    if (sts != QCOM__TMO && sts != QCOM__QEMPTY && get.data != NULL) {
      int len, i, argc, totlen;
      char **argv, *s;
      ini_sContext *ncp;

      for (argc = 0, s = get.data, totlen = 0; totlen < get.size; argc++) {
	len = strlen(s);
	s += len + 1;
	totlen += len + 1;
      }
      argv = (char **) calloc(sizeof(void*), argc);
      for (i = 0, s = get.data; i < argc; i++) {
	len = strlen(s);
	argv[i] = s;
	s += len + 1;
      }
      ncp = createContext(argc, argv);
      if (ncp != NULL) {
	ncp->log.put.type.b = 10;
	ncp->log.put.type.s = 1;
	ncp->log.send = 1;
	ncp->log.put.reply = cp->myQ;
	ncp->log.logQ = get.reply;
	ncp->eventQ = cp->eventQ;
	ncp->yourQ = get.reply;
	restart(ncp);
	free(ncp);
      }
      free(argv);
      qcom_Free(NULL, get.data);
    }

#if defined OS_POSIX
    if (lst_Succ(NULL, &cp->proc_lh, &pl) == NULL) break;
    pid = waitpid(-1, &status, WNOHANG|WUNTRACED);
    if (pid == 0) continue;
    if (pid == last_pid) break;
    
    for (pp = lst_Succ(NULL, &cp->proc_lh, &pl); pp != NULL; pp = lst_Succ(NULL, pl, &pl)) {
      if (pp->proc.pid == pid) {
	errh_LogInfo(&cp->log, "Process %s exited with status %d", pp->proc.name, status);
	break;
      }
    }
#endif

  }
  return INI__SUCCESS;
}
Ejemplo n.º 4
0
static pwr_tStatus
interactive (
  int		argc,
  char		**argv,
  ini_sContext	*cp
)
{
  pwr_tStatus	sts;
  qcom_sQid	qid;
  qcom_sPut	put;
  qcom_sGet	get;
  char		*bp, *sp;
  int		i;
  int		len;
  int		totlen;

  errh_Interactive();

  if (!qcom_Init(&sts, 0, "pwr_ini_restart")) {
    errh_LogFatal(&cp->log, "qcom_Init, %m", sts);
    exit(sts);
  } 

  qcom_CreateQ(&sts, &cp->myQ, NULL, "pwr_ini_restart");
  if (EVEN(sts)) {
    errh_LogFatal(&cp->log, "qcom_CreateQ, %m", sts);
    exit(sts);
  }

  for (i = 0, totlen = 0; i < argc; i++) {
    len = strlen(argv[i]);
    totlen += 1 + len;
    errh_LogInfo(&cp->log, "argv[%d]: %d \"%s\"", i, len, argv[i]);
  }
  bp = malloc(totlen);
  for (i = 0, sp = bp; i < argc; i++) {
    len = strlen(argv[i]);
    memcpy(sp, argv[i], len + 1);
    sp += len + 1;
  }
  
  qid.qix = 550715;
  qid.nid = 0;
    put.type.b = 10;
    put.type.s = 1;
    put.reply = cp->myQ;
    put.data = bp;
    put.size = totlen;
  qcom_Put(&sts, &qid, &put);

  while (1) {
    char *s;

    get.data = NULL;
    s = qcom_Get(&sts, &cp->myQ, &get, 100000);
    if (sts == QCOM__TMO && sts == QCOM__QEMPTY) {
      break;
    } else if (s != NULL) {
      printf("%s\n", s);
      qcom_Free(NULL, s);
    }
    if (get.type.s == 2)
      break;
  }

  return sts;
}
Ejemplo n.º 5
0
static pwr_tStatus
start (
  ini_sContext *cp
)
{
  pwr_tStatus sts;
  char console[80];

#if defined OS_POSIX
  int	fd;

  if ( strcmp( cp->console, "") == 0)
    strcpy( console, "/dev/console");
  else
    strcpy( console, cp->console);
  if ((fd = open(console, O_APPEND | O_WRONLY)) == -1)
    errl_Init(NULL, ini_errl_cb, cp);
  else {
    close(fd);
    errl_Init(console, ini_errl_cb, cp);
  }
#else
  errl_Init("CONSOLE:", ini_errl_cb, cp);
#endif

  errh_Init("pwr_ini", errh_eAnix_ini);

  if ( cp->flags.b.interactive)    
    errh_Interactive();

  mh_UtilCreateEvent();

  ini_CheckContext(&sts, cp);

  ini_ReadBootFile(&sts, cp);
  ini_ReadNodeFile(&sts, cp);
  ini_CheckNode(&sts, cp);

  cp->me = tree_Find(&sts, cp->nid_t, &cp->node.nid);
  if (cp->me == NULL) {
    errh_LogFatal(&cp->log, "Cannot find my own node in %s\n", cp->nodefile.name);
    exit(QCOM__WEIRD);
  }

  if (!checkErrors(cp))
    exit(0);

  if (cp->flags.b.verbose)
    logCardinality(cp);

  ini_CreateDb(&sts, cp);

  ini_LoadNode(&sts, cp);

  ini_BuildNode(&sts, cp);

  if (cp->np != NULL) {
    if (cp->np->ErrLogTerm[0] != '\0') {
      errh_LogInfo(&cp->log, "Setting log terminal to: %s", cp->np->ErrLogTerm);
      errl_SetTerm(cp->np->ErrLogTerm);
    }

/* Logfile is always $pwrp_log/pwr.log from V4.0.0 and handled by Linux log rotation */ 

    char fname[256];
    sprintf(fname, "$pwrp_log/pwr_%s.log", cp->nodename);
    dcli_translate_filename(fname, fname);
    errl_SetFile(fname);
    errh_LogInfo(&cp->log, "Setting log file to: %s", fname);

/*
    if (cp->np->ErrLogFile[0] != '\0') {
      struct tm *tp;
      char fname[256];
      time_t t;

      time(&t);
      tp = localtime(&t);
      strftime(fname, sizeof(fname), cp->np->ErrLogFile, tp );
      dcli_translate_filename( fname, fname);
      errl_SetFile(fname);
      errh_LogInfo(&cp->log, "Setting log file to: %s", cp->np->ErrLogFile);
    }
*/
  }

  ini_SetSystemStatus( cp, PWR__STARTUP);
  errh_SetStatus( PWR__STARTUP);

  sts = ini_RcReadAndSet(cp->dir, cp->nodename, cp->busid);
  if (EVEN(sts))
    errh_LogError(&cp->log, "ini_RcReadAndSet, %m", sts);

  sts = ini_SetAttribute(cp->aliasfile.name, cp->nodename, 0);
  if (EVEN(sts) && sts != INI__FILE)
    errh_LogError(&cp->log, "ini_SetAttribute, %m", sts);

  qini_BuildDb(&sts, cp->nid_t, cp->me, NULL, cp->busid);

  io_init_signals();

  load_backup();

#if defined OS_ELN
  ker$initialization_done(NULL);
#endif

  ini_ProcTable(&sts, cp);
  ini_ProcIter(&sts, cp, proc_mProcess_system, 0, ini_ProcLoad);
  ini_ProcIter(&sts, cp, proc_mProcess_system, 0, ini_ProcStart);
  ini_ProcIter(&sts, cp, proc_mProcess_system, 0, ini_ProcPrio);

  net_Connect(&sts, &gdbroot->my_aid, &gdbroot->my_qid, NULL, "pwr_ini");
  /*if (!qcom_Init(&sts, 0)) {*/
  if (EVEN(sts)) {
    errh_LogFatal(&cp->log, "net_Connect, %m", sts);
    exit(sts);
  }   

  qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_newPlcInit | ini_mEvent_newPlcStart);

  ini_ProcIter(&sts, cp, proc_mProcess_user, 0, ini_ProcLoad);
  ini_ProcIter(&sts, cp, proc_mProcess_user, 0, ini_ProcStart);
  ini_ProcIter(&sts, cp, proc_mProcess_user, 0, ini_ProcPrio);

  qcom_CreateQ(&sts, &cp->eventQ, NULL, "iniEvent");
  if (EVEN(sts)) {
    errh_LogFatal(&cp->log, "qcom_CreateQ, %m", sts);
    exit(sts);
  }

  qcom_WaitAnd(&sts, &cp->eventQ, &qcom_cQini, ini_mEvent_newPlcStartDone | cp->plc_sigmask, qcom_cTmoEternal);

  sts = ini_SetAttributeAfterPlc(cp->aliasfile.name, cp->nodename, 0);
  if (EVEN(sts) && sts != INI__FILE)
    errh_LogError(&cp->log, "ini_SetAttributeAfterPlc, %m", sts);
         
  ini_SetSystemStatus( cp, PWR__RUNNING);
  errh_SetStatus( PWR__SRUN);

  return sts;
}
Ejemplo n.º 6
0
static pwr_tStatus start( ini_sContext *cp)
{
  pwr_tStatus sts;
  char console[80];
  qini_sNode		*nep;
  qcom_sAid aid;

  int	fd;

  if ( strcmp( cp->console, "") == 0)
    strcpy( console, "/dev/console");
  else
    strcpy( console, cp->console);
  if ((fd = open(console, O_APPEND | O_WRONLY)) == -1)
    errl_Init(NULL, ini_errl_cb, cp);
  else {
    close(fd);
    errl_Init(console, ini_errl_cb, cp);
  }

  errh_Init("pwr_ini", errh_eAnix_ini);

  if ( cp->flags.b.interactive)    
    errh_Interactive();

  ini_CheckContext(&sts, cp);

  ini_ReadBootFile(&sts, cp);
  ini_ReadNodeFile(&sts, cp);


  for (nep = tree_Minimum(&sts, cp->nid_t); nep != NULL; nep = tree_Successor(&sts, cp->nid_t, nep)) {
    if ( strcmp( cp->nodename, nep->name) == 0) {
      cp->me = nep;
      break;
    }
  }      
  if (cp->me == NULL) {
    errh_LogFatal(&cp->log, "Cannot find my own node in %s\n", cp->nodefile.name);
    exit(QCOM__WEIRD);
  }

  if (!checkErrors(cp))
    exit(0);

  /* Logfile is always $pwrp_log/pwr.log from V4.0.0 and handled by Linux log rotation */ 

  char fname[256];
  sprintf(fname, "$pwrp_log/pwr_%s.log", cp->nodename);
  dcli_translate_filename(fname, fname);
  errl_SetFile(fname);
  errh_LogInfo(&cp->log, "Setting log file to: %s", fname);

  // ini_SetSystemStatus( cp, PWR__STARTUP);
  errh_SetStatus( PWR__STARTUP);

  qini_BuildDb(&sts, cp->nid_t, cp->me, NULL, cp->busid);


  ini_ProcTable(&sts, cp);
  ini_ProcIter(&sts, cp, proc_mProcess_system, ini_ProcStart);
  ini_ProcIter(&sts, cp, proc_mProcess_system, ini_ProcPrio);

  ini_ProcIter(&sts, cp, proc_mProcess_user, ini_ProcStart);
  ini_ProcIter(&sts, cp, proc_mProcess_user, ini_ProcPrio);

  qcom_Init(&sts, &aid, "pwr_sev_init");
  if (EVEN(sts)) {
    errh_LogFatal(&cp->log, "qcom_Init, %m", sts);
    exit(sts);
  }

  qcom_CreateQ(&sts, &cp->eventQ, NULL, "iniEvent");
  if (EVEN(sts)) {
    errh_LogFatal(&cp->log, "qcom_CreateQ, %m", sts);
    exit(sts);
  }
         
  // ini_SetSystemStatus( cp, PWR__RUNNING);
  errh_SetStatus( PWR__SRUN);

  return sts;
}