Ignore:
File:
1 edited

Legend:

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

    r3815efb 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
     102        /* Connect to a program loader. */
     103        ldr = loader_connect();
     104        if (ldr == NULL)
     105                return EREFUSED;
     106       
     107        /* Get task ID. */
     108        rc = loader_get_task_id(ldr, &task_id);
     109        if (rc != EOK)
     110                goto error;
     111       
     112        /* Send spawner's current working directory. */
     113        rc = loader_set_cwd(ldr);
     114        if (rc != EOK)
     115                goto error;
     116       
     117        /* Send program pathname. */
     118        rc = loader_set_pathname(ldr, path);
     119        if (rc != EOK)
     120                goto error;
     121       
     122        /* Send arguments. */
     123        rc = loader_set_args(ldr, args);
     124        if (rc != EOK)
     125                goto error;
     126       
    103127        /* Send default files */
    104128        fdi_node_t *files[4];
     
    124148        files[3] = NULL;
    125149       
    126         return task_spawnvf(id, path, args, files);
    127 }
    128 
    129 /** Create a new task by running an executable from the filesystem.
    130  *
    131  * This is really just a convenience wrapper over the more complicated
    132  * loader API. Arguments are passed as a null-terminated array of strings.
    133  * Files are passed as null-terminated array of pointers to fdi_node_t.
    134  *
    135  * @param id    If not NULL, the ID of the task is stored here on success.
    136  * @param path  Pathname of the binary to execute.
    137  * @param argv  Command-line arguments.
    138  * @param files Standard files to use.
    139  *
    140  * @return Zero on success or negative error code.
    141  *
    142  */
    143 int task_spawnvf(task_id_t *id, const char *path, const char *const args[],
    144     fdi_node_t *const files[])
    145 {
    146         /* Connect to a program loader. */
    147         loader_t *ldr = loader_connect();
    148         if (ldr == NULL)
    149                 return EREFUSED;
    150        
    151         /* Get task ID. */
    152         task_id_t task_id;
    153         int rc = loader_get_task_id(ldr, &task_id);
    154         if (rc != EOK)
    155                 goto error;
    156        
    157         /* Send spawner's current working directory. */
    158         rc = loader_set_cwd(ldr);
    159         if (rc != EOK)
    160                 goto error;
    161        
    162         /* Send program pathname. */
    163         rc = loader_set_pathname(ldr, path);
    164         if (rc != EOK)
    165                 goto error;
    166        
    167         /* Send arguments. */
    168         rc = loader_set_args(ldr, args);
    169         if (rc != EOK)
    170                 goto error;
    171        
    172         /* Send files */
    173150        rc = loader_set_files(ldr, files);
    174151        if (rc != EOK)
     
    186163       
    187164        /* Success */
     165        free(ldr);
     166       
    188167        if (id != NULL)
    189168                *id = task_id;
     
    194173        /* Error exit */
    195174        loader_abort(ldr);
     175        free(ldr);
    196176        return rc;
    197177}
     
    202182 * loader API. Arguments are passed as a null-terminated list of arguments.
    203183 *
    204  * @param id   If not NULL, the ID of the task is stored here on success.
    205  * @param path Pathname of the binary to execute.
    206  * @param ...  Command-line arguments.
    207  *
    208  * @return Zero on success or negative error code.
    209  *
     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.
    210189 */
    211190int task_spawnl(task_id_t *task_id, const char *path, ...)
    212191{
    213         /* Count the number of arguments. */
    214        
    215192        va_list ap;
     193        int rc, cnt;
    216194        const char *arg;
    217195        const char **arglist;
    218         int cnt = 0;
    219        
     196
     197        /* Count the number of arguments. */
     198        cnt = 0;
    220199        va_start(ap, path);
    221200        do {
     
    224203        } while (arg != NULL);
    225204        va_end(ap);
    226        
     205
    227206        /* Allocate argument list. */
    228207        arglist = malloc(cnt * sizeof(const char *));
    229208        if (arglist == NULL)
    230209                return ENOMEM;
    231        
     210
    232211        /* Fill in arguments. */
    233212        cnt = 0;
     
    238217        } while (arg != NULL);
    239218        va_end(ap);
    240        
     219
    241220        /* Spawn task. */
    242         int rc = task_spawnv(task_id, path, arglist);
    243        
     221        rc = task_spawnv(task_id, path, arglist);
     222
    244223        /* Free argument list. */
    245224        free(arglist);
     
    249228int task_wait(task_id_t id, task_exit_t *texit, int *retval)
    250229{
    251         assert(texit);
    252         assert(retval);
    253        
    254         async_exch_t *exch = async_exchange_begin(session_ns);
    255230        sysarg_t te, rv;
    256         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),
    257234            UPPER32(id), &te, &rv);
    258         async_exchange_end(exch);
    259        
    260235        *texit = te;
    261236        *retval = rv;
    262        
     237
    263238        return rc;
    264239}
     
    266241int task_retval(int val)
    267242{
    268         async_exch_t *exch = async_exchange_begin(session_ns);
    269         int rc = (int) async_req_1_0(exch, NS_RETVAL, val);
    270         async_exchange_end(exch);
    271        
    272         return rc;
     243        return (int) async_req_1_0(PHONE_NS, NS_RETVAL, val);
    273244}
    274245
Note: See TracChangeset for help on using the changeset viewer.