Ejemplo n.º 1
0
Archivo: conf.c Proyecto: baruch/nut
/* called after SIGHUP */
void conf_reload(void)
{
    upstype_t	*upstmp, *upsnext;

    upslogx(LOG_INFO, "SIGHUP: reloading configuration");

    /* see if we can access upsd.conf before blowing away the config */
    if (!check_file("upsd.conf"))
        return;

    /* reset retain flags on all known UPS entries */
    upstmp = firstups;
    while (upstmp) {
        upstmp->retain = 0;
        upstmp = upstmp->next;
    }

    /* reload from ups.conf */
    read_upsconf();
    upsconf_add(1);			/* 1 = reloading */

    /* now reread upsd.conf */
    load_upsdconf(1);		/* 1 = reloading */

    /* now delete all UPS entries that didn't get reloaded */

    upstmp = firstups;

    while (upstmp) {
        /* upstmp may be deleted during this pass */
        upsnext = upstmp->next;

        if (upstmp->retain == 0)
            delete_ups(upstmp);

        upstmp = upsnext;
    }

    /* did they actually delete the last UPS? */
    if (firstups == NULL)
        upslogx(LOG_WARNING, "Warning: no UPSes currently defined!");

    /* and also make sure upsd.users can be read... */
    if (!check_file("upsd.users"))
        return;

    /* delete all users */
    user_flush();

    /* and finally reread from upsd.users */
    user_load();
}
Ejemplo n.º 2
0
static void reload_conf(void)
{
    utype_t	*tmp, *next;

    upslogx(LOG_INFO, "Reloading configuration");

    /* sanity check */
    if (!check_file(configfile)) {
        reload_flag = 0;
        return;
    }

    /* flip through ups list, clear retain value */
    tmp = firstups;

    while (tmp) {
        tmp->retain = 0;
        tmp = tmp->next;
    }

    /* reset paranoia checker */
    totalpv = 0;

    /* reread upsmon.conf */
    loadconfig();

    /* go through the utype_t struct again */
    tmp = firstups;

    while (tmp) {
        next = tmp->next;

        /* !retain means it wasn't in the .conf this time around */
        if (tmp->retain == 0)
            delete_ups(tmp);

        tmp = next;
    }

    /* see if the user just blew off a foot */
    if (totalpv < minsupplies) {
        upslogx(LOG_CRIT, "Fatal error: total power value (%d) less "
                "than MINSUPPLIES (%d)", totalpv, minsupplies);

        fatalx(EXIT_FAILURE, "Impossible power configuation, unable to continue");
    }

    /* finally clear the flag */
    reload_flag = 0;
}