Changeset aa0faeca in mainline for uspace/srv/sysman/unit.c
- Timestamp:
- 2020-03-08T16:47:18Z (4 years ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/sysman/unit.c
r13b4504 raa0faeca 56 56 static config_item_t unit_configuration[] = { 57 57 { "After", &unit_parse_unit_list, 0, "" }, 58 { "ConditionArchitecture", &unit_parse_condition_architecture, 0, "" }, 58 59 CONFIGURATION_ITEM_SENTINEL 59 60 }; … … 69 70 unit->state = STATE_STOPPED; 70 71 unit->repo_state = REPO_EMBRYO; 72 unit->conditions = UNIT_CONDITION_NONE; 71 73 72 74 link_initialize(&unit->units); … … 137 139 errno_t unit_start(unit_t *unit) 138 140 { 141 assert(unit->conditions == UNIT_CONDITION_NONE); 139 142 sysman_log(LVL_NOTE, "%s('%s')", __func__, unit_name(unit)); 140 143 return UNIT_VMT(unit)->start(unit); … … 147 150 errno_t unit_stop(unit_t *unit) 148 151 { 152 assert(unit->conditions == UNIT_CONDITION_NONE); 149 153 sysman_log(LVL_NOTE, "%s('%s')", __func__, unit_name(unit)); 150 154 return UNIT_VMT(unit)->stop(unit); … … 191 195 { 192 196 return unit->name ? unit->name : ""; 197 } 198 199 /** 200 * Logs a message for the failed conditions of a unit 201 */ 202 void 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 } 193 226 } 194 227 … … 221 254 return result; 222 255 } 256 257 bool 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 288 finish: 289 free(str); 290 return result; 291 }
Note:
See TracChangeset
for help on using the changeset viewer.