Changeset 241f1985 in mainline for uspace/srv/sysman/connection_ctl.c


Ignore:
Timestamp:
2019-08-31T10:45:17Z (6 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
102f641
Parents:
f92b315
git-author:
Matthieu Riolo <matthieu.riolo@…> (2019-08-23 22:04:34)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-31 10:45:17)
Message:

Correcting failure from previous merge

The commits from Michal Koutný from the branch system-daemon
where built on a old version of Helenos. Because of this
many types and API functions have changed. This commit
upgrades the merge code

File:
1 edited

Legend:

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

    rf92b315 r241f1985  
    4343
    4444// TODO possibly provide as type-safe function + macro in sysman.h for generic boxing
    45 static ipc_callid_t *box_callid(ipc_callid_t iid)
    46 {
    47         ipc_callid_t *result = malloc(sizeof(ipc_callid_t));
    48         if (result) {
    49                 *result = iid;
    50         }
    51         return result;
     45static ipc_call_t *box_callid(ipc_call_t *icall)
     46{
     47        ipc_call_t *copy = malloc(sizeof(ipc_call_t));
     48        if (copy) {
     49                memcpy(copy, icall, sizeof(ipc_call_t));
     50        }
     51        return copy;
    5252}
    5353
     
    5858        assert(job->retval != JOB_UNDEFINED_);
    5959
    60         ipc_callid_t *iid_ptr = arg;
     60        ipc_call_t *icall = arg;
    6161        // TODO use descriptive return value (probably refactor job retval)
    6262        sysarg_t retval = (job->retval == JOB_OK) ? EOK : EIO;
    63         async_answer_0(*iid_ptr, retval);
    64         free(iid_ptr);
     63        async_answer_0(icall, retval);
     64        free(icall);
    6565        job_del_ref(&job);
    6666}
    6767
    68 static void sysman_unit_handle(ipc_callid_t iid, ipc_call_t *icall)
     68static void sysman_unit_handle(ipc_call_t *icall)
    6969{
    7070        char *unit_name = NULL;
     
    8484        }
    8585
    86         async_answer_1(iid, EOK, unit->handle);
     86        async_answer_1(icall, EOK, unit->handle);
    8787        goto finish;
    8888
    8989fail:
    90         async_answer_0(iid, retval);
     90        async_answer_0(icall, retval);
    9191finish:
    9292        free(unit_name);
    9393}
    9494
    95 static void sysman_unit_start_by_name(ipc_callid_t iid, ipc_call_t *icall)
     95static void sysman_unit_start_by_name(ipc_call_t *icall)
    9696{
    9797        char *unit_name = NULL;
     
    105105        }
    106106
    107         int flags = IPC_GET_ARG1(*icall);
     107        int flags = ipc_get_arg1(icall);
    108108        sysman_log(LVL_DEBUG2, "%s(%s, %x)", __func__, unit_name, flags);
    109109
     
    120120        }
    121121
    122         ipc_callid_t *iid_ptr = box_callid(iid);
    123         if (iid_ptr == NULL) {
     122        ipc_call_t *icall_copy = box_callid(icall);
     123        if (icall_copy == NULL) {
    124124                retval = ENOMEM;
    125125                goto answer;
    126126        }
    127127        retval = sysman_run_job(unit, STATE_STARTED, 0, &answer_callback,
    128             iid_ptr);
     128            icall_copy);
    129129        if (retval != EOK) {
    130130                goto answer;
     
    135135
    136136answer:
    137         async_answer_0(iid, retval);
     137        async_answer_0(icall, retval);
    138138finish:
    139139        free(unit_name);
    140140}
    141141
    142 static void sysman_unit_operation(ipc_callid_t iid, ipc_call_t *icall,
    143     unit_state_t state)
     142static void sysman_unit_operation(ipc_call_t *icall, unit_state_t state)
    144143{
    145144        sysarg_t retval;
    146145
    147         unit_handle_t handle = IPC_GET_ARG1(*icall);
    148         int flags = IPC_GET_ARG2(*icall);
    149         sysman_log(LVL_DEBUG2, "%s(%i, %x, %i)", __func__, handle, flags, state);
     146        unit_handle_t handle = ipc_get_arg1(icall);
     147        sysarg_t flags = ipc_get_arg2(icall);
     148        sysman_log(LVL_DEBUG2, "%s(%p, %lx, %i)", __func__, icall->cap_handle, flags, state);
    150149
    151150        unit_t *unit = repo_find_unit_by_handle(handle);
     
    160159        }
    161160
    162         ipc_callid_t *iid_ptr = box_callid(iid);
    163         if (iid_ptr == NULL) {
     161        ipc_call_t *icall_copy = box_callid(icall);
     162        if (icall_copy == NULL) {
    164163                retval = ENOMEM;
    165164                goto answer;
    166165        }
    167166        retval = sysman_run_job(unit, state, 0, &answer_callback,
    168             iid_ptr);
     167            icall_copy);
    169168        if (retval != EOK) {
    170169                goto answer;
     
    175174
    176175answer:
    177         async_answer_0(iid, retval);
    178 }
    179 
    180 static void sysman_unit_start(ipc_callid_t iid, ipc_call_t *icall)
    181 {
    182         sysman_unit_operation(iid, icall, STATE_STARTED);
    183 }
    184 
    185 static void sysman_unit_stop(ipc_callid_t iid, ipc_call_t *icall)
    186 {
    187         sysman_unit_operation(iid, icall, STATE_STOPPED);
     176        async_answer_0(icall, retval);
     177}
     178
     179static void sysman_unit_start(ipc_call_t *icall)
     180{
     181        sysman_unit_operation(icall, STATE_STARTED);
     182}
     183
     184static void sysman_unit_stop(ipc_call_t *icall)
     185{
     186        sysman_unit_operation(icall, STATE_STOPPED);
    188187}
    189188
     
    210209}
    211210
    212 static void sysman_get_units(ipc_callid_t iid, ipc_call_t *icall)
    213 {
    214         ipc_callid_t callid;
     211static void sysman_get_units(ipc_call_t *icall)
     212{
     213        ipc_call_t call;
    215214        size_t size;
    216215        size_t act_size;
    217216        int rc;
    218217       
    219         if (!async_data_read_receive(&callid, &size)) {
    220                 async_answer_0(callid, EREFUSED);
    221                 async_answer_0(iid, EREFUSED);
     218        if (!async_data_read_receive(&call, &size)) {
     219                async_answer_0(&call, EREFUSED);
     220                async_answer_0(icall, EREFUSED);
    222221                return;
    223222        }
     
    226225        unit_handle_t *handles = malloc(size);
    227226        if (handles == NULL && size > 0) {
    228                 async_answer_0(callid, ENOMEM);
    229                 async_answer_0(iid, ENOMEM);
     227                async_answer_0(&call, ENOMEM);
     228                async_answer_0(icall, ENOMEM);
    230229                return;
    231230        }
     
    234233        rc = fill_handles_buffer(handles, size, &act_size);
    235234        if (rc != EOK) {
    236                 async_answer_0(callid, rc);
    237                 async_answer_0(iid, rc);
     235                async_answer_0(&call, rc);
     236                async_answer_0(icall, rc);
    238237                return;
    239238        }
    240239       
    241240        size_t real_size = min(act_size, size);
    242         sysarg_t retval = async_data_read_finalize(callid, handles, real_size);
     241        sysarg_t retval = async_data_read_finalize(&call, handles, real_size);
    243242        free(handles);
    244243       
    245         async_answer_1(iid, retval, act_size);
    246 }
    247 
    248 static void sysman_unit_get_name(ipc_callid_t iid, ipc_call_t *icall)
    249 {
    250         ipc_callid_t callid;
     244        async_answer_1(icall, retval, act_size);
     245}
     246
     247static void sysman_unit_get_name(ipc_call_t *icall)
     248{
     249        ipc_call_t call;
    251250        size_t size;
    252251       
    253         if (!async_data_read_receive(&callid, &size)) {
    254                 async_answer_0(callid, EREFUSED);
    255                 async_answer_0(iid, EREFUSED);
    256                 return;
    257         }
    258        
    259         unit_t *u = repo_find_unit_by_handle(IPC_GET_ARG1(*icall));
     252        if (!async_data_read_receive(&call, &size)) {
     253                async_answer_0(&call, EREFUSED);
     254                async_answer_0(icall, EREFUSED);
     255                return;
     256        }
     257       
     258        unit_t *u = repo_find_unit_by_handle(ipc_get_arg1(icall));
    260259        if (u == NULL) {
    261                 async_answer_0(callid, ENOENT);
    262                 async_answer_0(iid, ENOENT);
     260                async_answer_0(&call, ENOENT);
     261                async_answer_0(icall, ENOENT);
    263262                return;
    264263        }
    265264       
    266265        size_t real_size = min(str_size(u->name) + 1, size);
    267         sysarg_t retval = async_data_read_finalize(callid, u->name, real_size);
    268        
    269         async_answer_0(iid, retval);
    270 }
    271 
    272 static void sysman_unit_get_state(ipc_callid_t iid, ipc_call_t *icall)
    273 {
    274         unit_t *u = repo_find_unit_by_handle(IPC_GET_ARG1(*icall));
     266        sysarg_t retval = async_data_read_finalize(&call, u->name, real_size);
     267       
     268        async_answer_0(icall, retval);
     269}
     270
     271static void sysman_unit_get_state(ipc_call_t *icall)
     272{
     273        unit_t *u = repo_find_unit_by_handle(ipc_get_arg1(icall));
    275274        if (u == NULL) {
    276                 async_answer_0(iid, ENOENT);
     275                async_answer_0(icall, ENOENT);
    277276        } else {
    278                 async_answer_1(iid, EOK, u->state);
    279         }
    280 }
    281 
    282 static void sysman_shutdown(ipc_callid_t iid, ipc_call_t *icall)
    283 {
    284         int retval;
     277                async_answer_1(icall, EOK, u->state);
     278        }
     279}
     280
     281static void sysman_shutdown(ipc_call_t *icall)
     282{
     283        errno_t retval;
    285284        unit_t *u = repo_find_unit_by_name(TARGET_SHUTDOWN);
    286285        if (u == NULL) {
     
    293292
    294293finish:
    295         async_answer_0(iid, retval);
    296 }
    297 
    298 void sysman_connection_ctl(ipc_callid_t iid, ipc_call_t *icall)
     294        async_answer_0(icall, retval);
     295}
     296
     297void sysman_connection_ctl(ipc_call_t *icall)
    299298{
    300299        sysman_log(LVL_DEBUG2, "%s", __func__);
    301300        /* First, accept connection */
    302         async_answer_0(iid, EOK);
     301        async_answer_0(icall, EOK);
    303302
    304303        while (true) {
    305304                ipc_call_t call;
    306                 ipc_callid_t callid = async_get_call(&call);
    307 
    308                 if (!IPC_GET_IMETHOD(call)) {
     305               
     306                if (!async_get_call(&call) || !ipc_get_imethod(&call)) {
    309307                        /* Client disconnected */
    310308                        break;
    311309                }
    312310
    313                 switch (IPC_GET_IMETHOD(call)) {
     311                switch (ipc_get_imethod(&call)) {
    314312                case SYSMAN_CTL_UNIT_HANDLE:
    315                         sysman_unit_handle(callid, &call);
     313                        sysman_unit_handle(&call);
    316314                        break;
    317315                case SYSMAN_CTL_UNIT_START_BY_NAME:
    318                         sysman_unit_start_by_name(callid, &call);
     316                        sysman_unit_start_by_name(&call);
    319317                        break;
    320318                case SYSMAN_CTL_UNIT_START:
    321                         sysman_unit_start(callid, &call);
     319                        sysman_unit_start(&call);
    322320                        break;
    323321                case SYSMAN_CTL_UNIT_STOP:
    324                         sysman_unit_stop(callid, &call);
     322                        sysman_unit_stop(&call);
    325323                        break;
    326324                case SYSMAN_CTL_GET_UNITS:
    327                         sysman_get_units(callid, &call);
     325                        sysman_get_units(&call);
    328326                        break;
    329327                case SYSMAN_CTL_UNIT_GET_NAME:
    330                         sysman_unit_get_name(callid, &call);
     328                        sysman_unit_get_name(&call);
    331329                        break;
    332330                case SYSMAN_CTL_UNIT_GET_STATE:
    333                         sysman_unit_get_state(callid, &call);
     331                        sysman_unit_get_state(&call);
    334332                        break;
    335333                case SYSMAN_CTL_SHUTDOWN:
    336                         sysman_shutdown(callid, &call);
     334                        sysman_shutdown(&call);
    337335                        break;
    338336                default:
    339                         async_answer_0(callid, ENOENT);
     337                        async_answer_0(&call, ENOENT);
    340338                }
    341339        }
Note: See TracChangeset for help on using the changeset viewer.