Changeset aa0faeca in mainline


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

Location:
uspace
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/cfg/sysman/default.tgt

    r13b4504 raa0faeca  
    44After = devman.svc
    55
    6 ; arm32 specific
    7 ; After = s3c24xx_uart.svc
    8 ; After = s3c24xx_ts.svc
     6After = s3c24xx_uart.svc
     7After = s3c24xx_ts.svc
    98
    109After = klog.svc
  • uspace/cfg/sysman/s3c24xx_ts.svc

    r13b4504 raa0faeca  
     1[Unit]
     2ConditionArchitecture = arm32
     3
    14[Service]
    25ExecStart = /srv/hid/s3c24xx_ts
  • uspace/cfg/sysman/s3c24xx_uart.svc

    r13b4504 raa0faeca  
     1[Unit]
     2ConditionArchitecture = arm32
     3
    14[Service]
    25ExecStart = /srv/hid/s3c24xx_uart
  • uspace/srv/sysman/repo.c

    r13b4504 raa0faeca  
    278278}
    279279
     280static bool repo_clean_up_unit(ht_link_t *ht_link, void *arg)
     281{
     282        unit_t *unit = hash_table_get_inst(ht_link, unit_t, units_by_name);
     283
     284        if (unit->conditions != UNIT_CONDITION_NONE) {
     285                unit_log_condition(unit);
     286
     287                list_foreach_safe(unit->edges_in, current_link, iter) {
     288                        unit_edge_t *e = list_get_instance(current_link, unit_edge_t, edges_in);
     289                        edge_remove(&e);
     290                }
     291
     292                list_foreach_safe(unit->edges_out, current_link, iter) {
     293                        unit_edge_t *e = list_get_instance(current_link, unit_edge_t, edges_out);
     294                        edge_remove(&e);
     295                }
     296        }
     297
     298        return true;
     299}
     300
    280301/** Resolve unresolved dependencies between any pair of units_by_name
    281302 *
     
    289310        bool has_error = false;
    290311        hash_table_apply(&units_by_name, &repo_resolve_unit, &has_error);
     312
     313        if (!has_error) {
     314                //once all references have been built test if there are
     315                //units which dont meet the conditions. If yes, remove the edges
     316                hash_table_apply(&units_by_name, &repo_clean_up_unit, &has_error);
     317        }
    291318
    292319        return has_error ? ENOENT : EOK;
  • 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}
  • uspace/srv/sysman/unit.h

    r13b4504 raa0faeca  
    5555} repo_state_t;
    5656
     57typedef enum {
     58        UNIT_CONDITION_NONE = 0,
     59        UNIT_CONDITION_ARCHITECTURE = 1
     60} unit_condition_t;
     61
    5762typedef struct {
    5863        /** Link to name-to-unit hash table */
     
    9297        list_t edges_in;
    9398        list_t edges_out;
     99
     100        /**
     101         * flag for conditions which were not meet
     102         * determines if the unit should be started
     103         */
     104        unit_condition_t conditions;
    94105} unit_t;
    95106
     
    161172
    162173extern const char *unit_name(const unit_t *);
     174extern void unit_log_condition(unit_t *unit);
    163175
    164176extern bool unit_parse_unit_list(const char *, void *, text_parse_t *, size_t);
     177extern bool unit_parse_condition_architecture(const char *, void *, text_parse_t *, size_t);
    165178
    166179#endif
Note: See TracChangeset for help on using the changeset viewer.