Ignore:
File:
1 edited

Legend:

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

    r1e9f8ab r0eff68e  
    3535
    3636#include <task.h>
    37 #include <libc.h>
    38 #include <stdlib.h>
    39 #include <errno.h>
    4037#include <loader/loader.h>
    4138#include <stdarg.h>
     
    4340#include <ipc/ns.h>
    4441#include <macros.h>
     42#include <assert.h>
    4543#include <async.h>
     44#include <errno.h>
     45#include <malloc.h>
     46#include <libc.h>
     47#include "private/ns.h"
    4648
    4749task_id_t task_get_id(void)
     
    6870int task_set_name(const char *name)
    6971{
     72        assert(name);
     73       
    7074        return __SYSCALL2(SYS_TASK_SET_NAME, (sysarg_t) name, str_size(name));
    7175}
     
    8892 * loader API. Arguments are passed as a null-terminated array of strings.
    8993 *
    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.
     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 *
    95100 */
    96101int task_spawnv(task_id_t *id, const char *path, const char *const args[])
    97102{
    98         loader_t *ldr;
    99         task_id_t task_id;
    100         int rc;
    101 
    102103        /* Connect to a program loader. */
    103         ldr = loader_connect();
     104        loader_t *ldr = loader_connect();
    104105        if (ldr == NULL)
    105106                return EREFUSED;
    106107       
    107108        /* Get task ID. */
    108         rc = loader_get_task_id(ldr, &task_id);
     109        task_id_t task_id;
     110        int rc = loader_get_task_id(ldr, &task_id);
    109111        if (rc != EOK)
    110112                goto error;
     
    163165       
    164166        /* Success */
    165         free(ldr);
    166        
    167167        if (id != NULL)
    168168                *id = task_id;
     
    173173        /* Error exit */
    174174        loader_abort(ldr);
    175         free(ldr);
    176175        return rc;
    177176}
     
    182181 * loader API. Arguments are passed as a null-terminated list of arguments.
    183182 *
    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.
     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 *
    189189 */
    190190int task_spawnl(task_id_t *task_id, const char *path, ...)
    191191{
     192        /* Count the number of arguments. */
     193       
    192194        va_list ap;
    193         int rc, cnt;
    194195        const char *arg;
    195196        const char **arglist;
    196 
    197         /* Count the number of arguments. */
    198         cnt = 0;
     197        int cnt = 0;
     198       
    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         rc = task_spawnv(task_id, path, arglist);
    222 
     221        int 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);
    230234        sysarg_t te, rv;
    231         int rc;
    232 
    233         rc = (int) async_req_2_2(PHONE_NS, NS_TASK_WAIT, LOWER32(id),
     235        int rc = (int) async_req_2_2(exch, NS_TASK_WAIT, LOWER32(id),
    234236            UPPER32(id), &te, &rv);
     237        async_exchange_end(exch);
     238       
    235239        *texit = te;
    236240        *retval = rv;
    237 
     241       
    238242        return rc;
    239243}
     
    241245int task_retval(int val)
    242246{
    243         return (int) async_req_1_0(PHONE_NS, NS_RETVAL, val);
     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;
    244252}
    245253
Note: See TracChangeset for help on using the changeset viewer.