Changeset b55f62a in mainline for uspace/lib/sysman/src/ctl.c


Ignore:
Timestamp:
2019-08-07T09:29:33Z (6 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
918ac9b
Parents:
2df7d824
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-11-02 00:50:02)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-07 09:29:33)
Message:

sysman: Create control utility sysctl

  • can list units and their states (starts to feel like systemctl :-)
  • helluva boilerplate to get some IPC between sysctl and sysman :-/

Conflicts:

boot/Makefile.common
uspace/Makefile

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/sysman/src/ctl.c

    r2df7d824 rb55f62a  
    2929#include <async.h>
    3030#include <errno.h>
     31#include <stdlib.h>
    3132#include <str.h>
    3233#include <sysman/ctl.h>
     
    5758        return rc;
    5859}
     60
     61static int sysman_get_units_once(sysarg_t *buf, size_t buf_size,
     62    size_t *act_size)
     63{
     64        async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL);
     65
     66        ipc_call_t answer;
     67        aid_t req = async_send_0(exch, SYSMAN_CTL_GET_UNITS, &answer);
     68        int rc = async_data_read_start(exch, buf, buf_size);
     69
     70        sysman_exchange_end(exch);
     71
     72        if (rc != EOK) {
     73                async_forget(req);
     74                return rc;
     75        }
     76
     77        sysarg_t retval;
     78        async_wait_for(req, &retval);
     79
     80        if (retval != EOK) {
     81                return retval;
     82        }
     83
     84        *act_size = IPC_GET_ARG1(answer);
     85        return EOK;
     86}
     87
     88int sysman_get_units(unit_handle_t **units_ptr, size_t *cnt_ptr)
     89{
     90        *units_ptr = NULL;
     91        *cnt_ptr = 0;
     92
     93        unit_handle_t *units = NULL;
     94        size_t alloc_size = 0;
     95        size_t act_size = 0;
     96
     97        while (true) {
     98                int rc = sysman_get_units_once(units, alloc_size, &act_size);
     99                if (rc != EOK) {
     100                        return rc;
     101                }
     102
     103                if (act_size <= alloc_size) {
     104                        break;
     105                }
     106
     107                alloc_size = act_size;
     108                units = realloc(units, alloc_size);
     109                if (units == NULL) {
     110                        return ENOMEM;
     111                }
     112        }
     113
     114        *units_ptr = units;
     115        *cnt_ptr = act_size / sizeof(unit_handle_t);
     116        return EOK;
     117}
     118
     119int sysman_unit_get_name(unit_handle_t handle, char *buf, size_t buf_size)
     120{
     121        async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL);
     122
     123        ipc_call_t answer;
     124        aid_t req = async_send_1(exch, SYSMAN_CTL_UNIT_GET_NAME, handle, &answer);
     125        int rc = async_data_read_start(exch, buf, buf_size);
     126
     127        sysman_exchange_end(exch);
     128
     129        if (rc != EOK) {
     130                async_forget(req);
     131                return rc;
     132        }
     133
     134        sysarg_t retval;
     135        async_wait_for(req, &retval);
     136
     137        if (retval != EOK) {
     138                return retval;
     139        }
     140
     141        return EOK;
     142}
     143
     144int sysman_unit_get_state(unit_handle_t handle, unit_state_t *state)
     145{
     146        async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL);
     147        int rc = async_req_1_1(exch, SYSMAN_CTL_UNIT_GET_STATE, handle, state);
     148        sysman_exchange_end(exch);
     149
     150        return rc;
     151}
Note: See TracChangeset for help on using the changeset viewer.