Esempio n. 1
0
static pwr_tStatus start(ini_sContext* cp)
{
  pwr_tStatus sts;
  char console[80];
  int state;

  int fd;

  if (streq(cp->console, ""))
    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();

  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);

  sts = redu_get_initial_state(cp->nodename, cp->busid, &state);
  if (ODD(sts))
  {
    cp->np->RedundancyState = state;
    qcom_SetRedundancyState(state);
  }

  create_locks();

  io_init_signals();

  load_backup();

  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;
}
Esempio n. 2
0
void config_initialize(void) {
    create_locks();
}
Esempio n. 3
0
ledger_status ledger_partition_open(ledger_partition *partition, const char *topic_path,
                                    unsigned int partition_number, ledger_partition_options *options) {
    ledger_status rc;
    int fd = 0;
    int lock_fd = 0;
    char part_num[5];
    ssize_t path_len;
    char *partition_path = NULL;
    struct stat st;

    partition->path = NULL;
    partition->opened = false;
    partition->number = partition_number;

    rc = snprintf(part_num, 5, "%d", partition_number);
    ledger_check_rc(rc > 0, LEDGER_ERR_GENERAL, "Error building partition dir part");

    path_len = ledger_concat_path(topic_path, part_num, &partition_path);
    ledger_check_rc(path_len > 0, path_len, "Failed to construct partition directory path");

    memcpy(&partition->options, options, sizeof(ledger_partition_options));
    partition->path = partition_path;
    partition->path_len = path_len;

    rc = mkdir(partition_path, 0755);
    ledger_check_rc(rc == 0 || errno == EEXIST, LEDGER_ERR_MKDIR, "Failed to create partition directory");

    init_meta(&partition->meta);

    fd = open_meta(partition);
    ledger_check_rc(fd > 0, rc, "Failed to open meta file");

    rc = fstat(fd, &st);
    ledger_check_rc(rc == 0, LEDGER_ERR_IO, "Failed to stat meta file");

    if(st.st_size == 0) {
        rc = add_journal(partition, fd);
        ledger_check_rc(rc == LEDGER_OK, rc, "Failed to add initial journal");

        rc = fstat(fd, &st);
        ledger_check_rc(rc == 0, LEDGER_ERR_IO, "Failed to restat meta file");
    }

    rc = remap_meta(partition, fd, st.st_size);
    ledger_check_rc(rc == LEDGER_OK, rc, "Failed to read memory mapped meta file");

    lock_fd = open_lockfile(partition);
    ledger_check_rc(lock_fd > 0, rc, "Failed to open lockfile");

    rc = fstat(lock_fd, &st);
    ledger_check_rc(rc == 0, LEDGER_ERR_IO, "Failed to stat lockfile");

    if(st.st_size == 0) {
        rc = create_locks(partition, lock_fd);
        ledger_check_rc(rc == LEDGER_OK, rc, "Failed to create partition locks");

        rc = fstat(lock_fd, &st);
        ledger_check_rc(rc == 0, LEDGER_ERR_IO, "Failed to restat lock file");
    }

    rc = map_lockfile(partition, lock_fd, st.st_size);
    ledger_check_rc(rc == LEDGER_OK, rc, "Failed to read memory mapped lock file");

    close(fd);
    close(lock_fd);

    ledger_signal_init(&partition->message_signal);

    partition->opened = true;

    return LEDGER_OK;

error:
    if(partition_path) {
        free(partition_path);
    }
    if(fd) {
        close(fd);
    }
    if(lock_fd) {
        close(lock_fd);
    }
    return rc;
}