Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/task.c

    r0eff68e r1e9f8ab  
    3535
    3636#include <task.h>
     37#include <libc.h>
     38#include <stdlib.h>
     39#include <errno.h>
    3740#include <loader/loader.h>
    3841#include <stdarg.h>
     
    4043#include <ipc/ns.h>
    4144#include <macros.h>
    42 #include <assert.h>
    4345#include <async.h>
    44 #include <errno.h>
    45 #include <malloc.h>
    46 #include <libc.h>
    47 #include "private/ns.h"
    4846
    4947task_id_t task_get_id(void)
     
    7068int task_set_name(const char *name)
    7169{
    72         assert(name);
    73        
    7470        return __SYSCALL2(SYS_TASK_SET_NAME, (sysarg_t) name, str_size(name));
    7571}
     
    9288 * loader API. Arguments are passed as a null-terminated array of strings.
    9389 *
    94  * @param id   If not NULL, the ID of the task is stored here on success.
    95  * @param path Pathname of the binary to execute.
    96  * @param argv Command-line arguments.
    97  *
    98  * @return Zero on success or negative error code.
    99  *
     90 * @param id    If not NULL, the ID of the task is stored here on success.
     91 * @param path  Pathname of the binary to execute.
     92 * @param argv  Command-line arguments.
     93 *
     94 * @return      Zero on success or negative error code.
    10095 */
    10196int task_spawnv(task_id_t *id, const char *path, const char *const args[])
    10297{
     98        loader_t *ldr;
     99        task_id_t task_id;
     100        int rc;
     101
    103102        /* Connect to a program loader. */
    104         loader_t *ldr = loader_connect();
     103        ldr = loader_connect();
    105104        if (ldr == NULL)
    106105                return EREFUSED;
    107106       
    108107        /* Get task ID. */
    109         task_id_t task_id;
    110         int rc = loader_get_task_id(ldr, &task_id);
     108        rc = loader_get_task_id(ldr, &task_id);
    111109        if (rc != EOK)
    112110                goto error;
     
    165163       
    166164        /* Success */
     165        free(ldr);
     166       
    167167        if (id != NULL)
    168168                *id = task_id;
     
    173173        /* Error exit */
    174174        loader_abort(ldr);
     175        free(ldr);
    175176        return rc;
    176177}
     
    181182 * loader API. Arguments are passed as a null-terminated list of arguments.
    182183 *
    183  * @param id   If not NULL, the ID of the task is stored here on success.
    184  * @param path Pathname of the binary to execute.
    185  * @param ...  Command-line arguments.
    186  *
    187  * @return Zero on success or negative error code.
    188  *
     184 * @param id    If not NULL, the ID of the task is stored here on success.
     185 * @param path  Pathname of the binary to execute.
     186 * @param ...   Command-line arguments.
     187 *
     188 * @return      Zero on success or negative error code.
    189189 */
    190190int task_spawnl(task_id_t *task_id, const char *path, ...)
    191191{
    192         /* Count the number of arguments. */
    193        
    194192        va_list ap;
     193        int rc, cnt;
    195194        const char *arg;
    196195        const char **arglist;
    197         int cnt = 0;
    198        
     196
     197        /* Count the number of arguments. */
     198        cnt = 0;
    199199        va_start(ap, path);
    200200        do {
     
    203203        } while (arg != NULL);
    204204        va_end(ap);
    205        
     205
    206206        /* Allocate argument list. */
    207207        arglist = malloc(cnt * sizeof(const char *));
    208208        if (arglist == NULL)
    209209                return ENOMEM;
    210        
     210
    211211        /* Fill in arguments. */
    212212        cnt = 0;
     
    217217        } while (arg != NULL);
    218218        va_end(ap);
    219        
     219
    220220        /* Spawn task. */
    221         int rc = task_spawnv(task_id, path, arglist);
    222        
     221        rc = task_spawnv(task_id, path, arglist);
     222
    223223        /* Free argument list. */
    224224        free(arglist);
     
    228228int task_wait(task_id_t id, task_exit_t *texit, int *retval)
    229229{
    230         assert(texit);
    231         assert(retval);
    232        
    233         async_exch_t *exch = async_exchange_begin(session_ns);
    234230        sysarg_t te, rv;
    235         int rc = (int) async_req_2_2(exch, NS_TASK_WAIT, LOWER32(id),
     231        int rc;
     232
     233        rc = (int) async_req_2_2(PHONE_NS, NS_TASK_WAIT, LOWER32(id),
    236234            UPPER32(id), &te, &rv);
    237         async_exchange_end(exch);
    238        
    239235        *texit = te;
    240236        *retval = rv;
    241        
     237
    242238        return rc;
    243239}
     
    245241int task_retval(int val)
    246242{
    247         async_exch_t *exch = async_exchange_begin(session_ns);
    248         int rc = (int) async_req_1_0(exch, NS_RETVAL, val);
    249         async_exchange_end(exch);
    250        
    251         return rc;
     243        return (int) async_req_1_0(PHONE_NS, NS_RETVAL, val);
    252244}
    253245
Note: See TracChangeset for help on using the changeset viewer.