Changeset aa0faeca in mainline for uspace/srv/sysman/unit.c


Ignore:
Timestamp:
2020-03-08T16:47:18Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
a73aaec1
Parents:
13b4504
git-author:
Matthieu Riolo <matthieu.riolo@…> (2020-03-06 18:10:45)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2020-03-08 16:47:18)
Message:

Adding "ConditionArchitecture" to sysman's unit

the services s3c24xx_uart and s3c24xx_ts are specific for
arm32. This newly flag allows sysman to ignore those units
when they are asked to be loaded

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/sysman/unit.c

    r13b4504 raa0faeca  
    5656static config_item_t unit_configuration[] = {
    5757        { "After", &unit_parse_unit_list, 0, "" },
     58        { "ConditionArchitecture", &unit_parse_condition_architecture, 0, "" },
    5859        CONFIGURATION_ITEM_SENTINEL
    5960};
     
    6970        unit->state = STATE_STOPPED;
    7071        unit->repo_state = REPO_EMBRYO;
     72        unit->conditions = UNIT_CONDITION_NONE;
    7173
    7274        link_initialize(&unit->units);
     
    137139errno_t unit_start(unit_t *unit)
    138140{
     141        assert(unit->conditions == UNIT_CONDITION_NONE);
    139142        sysman_log(LVL_NOTE, "%s('%s')", __func__, unit_name(unit));
    140143        return UNIT_VMT(unit)->start(unit);
     
    147150errno_t unit_stop(unit_t *unit)
    148151{
     152        assert(unit->conditions == UNIT_CONDITION_NONE);
    149153        sysman_log(LVL_NOTE, "%s('%s')", __func__, unit_name(unit));
    150154        return UNIT_VMT(unit)->stop(unit);
     
    191195{
    192196        return unit->name ? unit->name : "";
     197}
     198
     199/**
     200 * Logs a message for the failed conditions of a unit
     201 */
     202void unit_log_condition(unit_t *unit)
     203{
     204        assert(unit->conditions != UNIT_CONDITION_NONE);
     205        unit_condition_t conditions = unit->conditions;
     206        while (conditions != UNIT_CONDITION_NONE) {
     207                const char *type = NULL;
     208                if (conditions & UNIT_CONDITION_ARCHITECTURE) {
     209                        conditions ^= UNIT_CONDITION_ARCHITECTURE;
     210                        type = "architecture";
     211                } else {
     212                        sysman_log(
     213                            LVL_NOTE,
     214                            "Condition restriction: unit '%s' does not meet the unkown condition '%d'",
     215                            unit_name(unit),
     216                            conditions);
     217                        return;
     218                }
     219
     220                sysman_log(
     221                    LVL_NOTE,
     222                    "Condition restriction: unit '%s' does not meet the '%s' condition",
     223                    unit_name(unit),
     224                    type);
     225        }
    193226}
    194227
     
    221254        return result;
    222255}
     256
     257bool unit_parse_condition_architecture(const char *string, void *dst, text_parse_t *parse,
     258    size_t lineno)
     259{
     260        unit_t *unit = dst;
     261        bool result = true;
     262        char *str = NULL;
     263
     264        if (str_length(string) == 0) {
     265                goto finish;
     266        }
     267
     268        str = str_dup(string);
     269        if (str == NULL) {
     270                result = false;
     271                goto finish;
     272        }
     273
     274        char *split = str;
     275        char *tok;
     276        bool conditions = false;
     277        while ((tok = str_tok(split, " ", &split))) {
     278                if (str_casecmp(tok, STRING(UARCH)) == 0) {
     279                        conditions = true;
     280                        break;
     281                }
     282        }
     283
     284        if (!conditions) {
     285                unit->conditions |= UNIT_CONDITION_ARCHITECTURE;
     286        }
     287
     288finish:
     289        free(str);
     290        return result;
     291}
Note: See TracChangeset for help on using the changeset viewer.