示例#1
0
/* Copied from resrules.c -- _get_actions */
static void
_get_actions_ccs(const char *base, resource_t * res)
{
    char xpath[256];
    int idx = 0;
    char *act, *ret;
    int interval, timeout, depth;

    do {
        /* setting these to -1 prevents overwriting with 0 */
        interval = -1;
        depth = -1;
        act = NULL;
        timeout = -1;

        /* XXX check */
        snprintf(xpath, sizeof(xpath), "%s/action[%d]/@name", base, ++idx);

        if (conf_get(xpath, &act) != 0)
            break;

        /* XXX check */
        snprintf(xpath, sizeof(xpath), "%s/action[%d]/@timeout", base, idx);
        if (conf_get(xpath, &ret) == 0 && ret) {
            timeout = expand_time(ret);
            if (timeout < 0)
                timeout = 0;
            free(ret);
        }

        /* XXX check */
        snprintf(xpath, sizeof(xpath), "%s/action[%d]/@interval", base, idx);
        if (conf_get(xpath, &ret) == 0 && ret) {
            interval = expand_time(ret);
            if (interval < 0)
                interval = 0;
            free(ret);
        }

        if (!strcmp(act, "status") || !strcmp(act, "monitor")) {
            /* XXX check */
            snprintf(xpath, sizeof(xpath), "%s/action[%d]/@depth", base, idx);
            if (conf_get(xpath, &ret) == 0 && ret) {
                /* XXX check/strtol */
                depth = atoi(ret);
                if (depth < 0)
                    depth = 0;

                /* XXX originally unfinished comment here (wildcard?) */
                if (ret[0] == '*')
                    depth = -1;
                free(ret);
            }
        }

        if (store_action(&res->r_actions, act, depth, timeout, interval) != 0)
            free(act);
    } while (1);
}
示例#2
0
static void
_get_actions(xmlDocPtr doc, xmlXPathContextPtr ctx, char *base, resource_rule_t * rr)
{
    char xpath[256];
    int idx = 0;
    char *act, *ret;
    int interval, timeout, depth;

    do {
        interval = 0;
        depth = 0;
        act = NULL;
        timeout = 0;

        snprintf(xpath, sizeof(xpath), "%s/action[%d]/@name", base, ++idx);

        act = xpath_get_one(doc, ctx, xpath);
        if (!act)
            break;

        snprintf(xpath, sizeof(xpath), "%s/action[%d]/@timeout", base, idx);
        ret = xpath_get_one(doc, ctx, xpath);
        if (ret) {
            timeout = expand_time(ret);
            if (timeout < 0)
                timeout = 0;
            free(ret);
        }

        snprintf(xpath, sizeof(xpath), "%s/action[%d]/@interval", base, idx);
        ret = xpath_get_one(doc, ctx, xpath);
        if (ret) {
            interval = expand_time(ret);
            if (interval < 0)
                interval = 0;
            free(ret);
        }

        if (!strcmp(act, "status") || !strcmp(act, "monitor")) {
            snprintf(xpath, sizeof(xpath), "%s/action[%d]/@depth", base, idx);
            ret = xpath_get_one(doc, ctx, xpath);
            if (ret) {
                depth = atoi(ret);
                if (depth < 0)
                    depth = 0;
                free(ret);
            }
        }

        if (store_action(&rr->rr_actions, act, depth, timeout, interval) != 0)
            free(act);
    } while (1);
}