Changeset b55f62a in mainline for uspace/srv/sysman/connection_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/srv/sysman/connection_ctl.c

    r2df7d824 rb55f62a  
    2929#include <errno.h>
    3030#include <ipc/sysman.h>
     31#include <macros.h>
    3132#include <stdlib.h>
     33#include <str.h>
    3234
    3335#include "configuration.h"
     
    6163        job_del_ref(&job);
    6264}
    63 
    6465static void sysman_unit_start(ipc_callid_t iid, ipc_call_t *icall)
    6566{
     
    7778        sysman_log(LVL_DEBUG2, "%s(%s, %x)", __func__, unit_name, flags);
    7879
     80        // TODO this is connection fibril, UNSYNCHRONIZED access to units!
    7981        unit_t *unit = configuration_find_unit_by_name(unit_name);
    8082        if (unit == NULL) {
     
    109111}
    110112
     113static int fill_handles_buffer(unit_handle_t *buffer, size_t size,
     114    size_t *act_size)
     115{
     116        if (size % sizeof(unit_handle_t) != 0) {
     117                return EINVAL;
     118        }
     119
     120        size_t filled = 0;
     121        size_t to_fill = size / sizeof(unit_handle_t);
     122        size_t total = 0;
     123        list_foreach(units, units, unit_t, u) {
     124                if (filled < to_fill) {
     125                        buffer[filled++] = u->handle;
     126                }
     127                ++total;
     128        }
     129        *act_size = total * sizeof(unit_handle_t);
     130        return EOK;
     131}
     132
     133static void sysman_get_units(ipc_callid_t iid, ipc_call_t *icall)
     134{
     135        ipc_callid_t callid;
     136        size_t size;
     137        size_t act_size;
     138        int rc;
     139       
     140        if (!async_data_read_receive(&callid, &size)) {
     141                async_answer_0(callid, EREFUSED);
     142                async_answer_0(iid, EREFUSED);
     143                return;
     144        }
     145       
     146       
     147        unit_handle_t *handles = malloc(size);
     148        if (handles == NULL && size > 0) {
     149                async_answer_0(callid, ENOMEM);
     150                async_answer_0(iid, ENOMEM);
     151                return;
     152        }
     153       
     154       
     155        // TODO UNSYNCHRONIZED access to units!
     156        rc = fill_handles_buffer(handles, size, &act_size);
     157        if (rc != EOK) {
     158                async_answer_0(callid, rc);
     159                async_answer_0(iid, rc);
     160                return;
     161        }
     162       
     163        size_t real_size = min(act_size, size);
     164        sysarg_t retval = async_data_read_finalize(callid, handles, real_size);
     165        free(handles);
     166       
     167        async_answer_1(iid, retval, act_size);
     168}
     169
     170static void sysman_unit_get_name(ipc_callid_t iid, ipc_call_t *icall)
     171{
     172        ipc_callid_t callid;
     173        size_t size;
     174       
     175        if (!async_data_read_receive(&callid, &size)) {
     176                async_answer_0(callid, EREFUSED);
     177                async_answer_0(iid, EREFUSED);
     178                return;
     179        }
     180       
     181        // TODO UNSYNCHRONIZED access to units!
     182        unit_t *u = configuration_find_unit_by_handle(IPC_GET_ARG1(*icall));
     183        if (u == NULL) {
     184                async_answer_0(callid, ENOENT);
     185                async_answer_0(iid, ENOENT);
     186                return;
     187        }
     188       
     189        size_t real_size = min(str_size(u->name) + 1, size);
     190        sysarg_t retval = async_data_read_finalize(callid, u->name, real_size);
     191       
     192        async_answer_0(iid, retval);
     193}
     194
     195static void sysman_unit_get_state(ipc_callid_t iid, ipc_call_t *icall)
     196{
     197        // TODO UNSYNCHRONIZED access to units!
     198        unit_t *u = configuration_find_unit_by_handle(IPC_GET_ARG1(*icall));
     199        if (u == NULL) {
     200                async_answer_0(iid, ENOENT);
     201        } else {
     202                async_answer_1(iid, EOK, u->state);
     203        }
     204}
     205
    111206void sysman_connection_ctl(ipc_callid_t iid, ipc_call_t *icall)
    112207{
     
    128223                        sysman_unit_start(callid, &call);
    129224                        break;
     225                case SYSMAN_CTL_GET_UNITS:
     226                        sysman_get_units(callid, &call);
     227                        break;
     228                case SYSMAN_CTL_UNIT_GET_NAME:
     229                        sysman_unit_get_name(callid, &call);
     230                        break;
     231                case SYSMAN_CTL_UNIT_GET_STATE:
     232                        sysman_unit_get_state(callid, &call);
     233                        break;
    130234                default:
    131235                        async_answer_0(callid, ENOENT);
Note: See TracChangeset for help on using the changeset viewer.