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


Ignore:
Timestamp:
2019-08-03T09:28:50Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
c0e4fc50
Parents:
2dda1d4
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-05-07 11:49:47)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-03 09:28:50)
Message:

sysman: Naive autostart instrumentation of locsrv

  • Add IPC_FLAG_AUTOSTART flag.
  • libsysman: sysman's broker and control API.
  • Simple implementation of service unit, exposee verification is missing.
  • Simple mapping of exposee to unit name in locsrv.
  • Temporary debug prints in locsrv.

Conflicts:

boot/Makefile.common
boot/arch/amd64/Makefile.inc
uspace/lib/c/include/ipc/services.h
uspace/srv/locsrv/locsrv.c

File:
1 edited

Legend:

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

    r2dda1d4 r5559712  
    3737#include <stdlib.h>
    3838#include <str.h>
     39#include <sysman/unit.h>
    3940
    4041#include "dep.h"
    4142#include "log.h"
     43#include "sysman.h"
    4244#include "unit.h"
    4345
    4446/** Virtual method table for each unit type */
    4547unit_vmt_t *unit_type_vmts[] = {
    46         [UNIT_TARGET]        = &unit_tgt_ops,
    47         [UNIT_MOUNT]         = &unit_mnt_ops,
    48         [UNIT_CONFIGURATION] = &unit_cfg_ops
     48        [UNIT_CONFIGURATION] = &unit_cfg_vmt,
     49        [UNIT_MOUNT]         = &unit_mnt_vmt,
     50        [UNIT_TARGET]        = &unit_tgt_vmt,
     51        [UNIT_SERVICE]       = &unit_svc_vmt
    4952};
    5053
     
    6164        assert(unit);
    6265
    63         // TODO is this necessary?
    64         memset(unit, 0, sizeof(unit_t));
     66        size_t size = unit_type_vmts[type]->size;
     67        memset(unit, 0, size);
    6568       
    6669        unit->type = type;
    67         unit->name = NULL;
    68 
    6970        unit->state = STATE_EMBRYO;
    7071
     
    103104}
    104105
    105 
    106 /** Issue request to restarter to start a unit
    107  *
    108  * Ideally this function is non-blocking synchronous, however, some units
    109  * cannot be started synchronously and thus return from this function generally
    110  * means that start was requested.
    111  *
    112  * Check state of the unit for actual result, start method can end in states:
    113  *   - STATE_STARTED, (succesful synchronous start)
    114  *   - STATE_STARTING, (succesful asynchronous start request)
    115  *   - STATE_FAILED.  (error occured)
    116  */
    117 int unit_start(unit_t *unit)
    118 {
    119         sysman_log(LVL_DEBUG, "%s('%s')", __func__, unit_name(unit));
    120         return UNIT_VMT(unit)->start(unit);
    121 }
    122 
    123106int unit_load(unit_t *unit, ini_configuration_t *ini_conf,
    124107    text_parse_t *text_parse)
     
    140123}
    141124
     125/** Issue request to restarter to start a unit
     126 *
     127 * Ideally this function is non-blocking synchronous, however, some units
     128 * cannot be started synchronously and thus return from this function generally
     129 * means that start was requested.
     130 *
     131 * Check state of the unit for actual result, start method can end in states:
     132 *   - STATE_STARTED, (succesful synchronous start)
     133 *   - STATE_STARTING, (succesful asynchronous start request)
     134 *   - STATE_FAILED.  (unit state changed and error occured)
     135 */
     136int unit_start(unit_t *unit)
     137{
     138        sysman_log(LVL_DEBUG, "%s('%s')", __func__, unit_name(unit));
     139        return UNIT_VMT(unit)->start(unit);
     140}
     141
     142void unit_exposee_created(unit_t *unit)
     143{
     144        sysman_log(LVL_DEBUG, "%s('%s')", __func__, unit_name(unit));
     145        return UNIT_VMT(unit)->exposee_created(unit);
     146}
     147
     148void unit_fail(unit_t *unit)
     149{
     150        sysman_log(LVL_DEBUG, "%s('%s')", __func__, unit_name(unit));
     151        return UNIT_VMT(unit)->fail(unit);
     152}
     153
     154void unit_notify_state(unit_t *unit)
     155{
     156        sysman_raise_event(&sysman_event_unit_state_changed, unit);
     157}
     158
    142159unit_type_t unit_type_name_to_type(const char *type_name)
    143160{
    144         if (str_cmp(type_name, "cfg") == 0)
     161        if (str_cmp(type_name, UNIT_CFG_TYPE_NAME) == 0)
    145162                return UNIT_CONFIGURATION;
    146163
    147         else if (str_cmp(type_name, "mnt") == 0)
     164        else if (str_cmp(type_name, UNIT_MNT_TYPE_NAME) == 0)
    148165                return UNIT_MOUNT;
    149166
    150         else if (str_cmp(type_name, "tgt") == 0)
     167        else if (str_cmp(type_name, UNIT_TGT_TYPE_NAME) == 0)
    151168                return UNIT_TARGET;
     169
     170        else if (str_cmp(type_name, UNIT_SVC_TYPE_NAME) == 0)
     171                return UNIT_SERVICE;
    152172
    153173        else
     
    160180        return unit->name ? unit->name : "";
    161181}
    162 
    163 
    164 
    165182
    166183bool unit_parse_unit_list(const char *value, void *dst, text_parse_t *parse,
Note: See TracChangeset for help on using the changeset viewer.