Changeset c028b22 in mainline for uspace/lib/c/generic/task.c


Ignore:
Timestamp:
2011-07-08T17:01:01Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cc1a727
Parents:
4e36219 (diff), 026793d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

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

    r4e36219 rc028b22  
    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 
    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        
    127103        /* Send default files */
    128104        fdi_node_t *files[4];
     
    148124        files[3] = NULL;
    149125       
     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 */
     143int 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 */
    150173        rc = loader_set_files(ldr, files);
    151174        if (rc != EOK)
     
    163186       
    164187        /* Success */
    165         free(ldr);
    166        
    167188        if (id != NULL)
    168189                *id = task_id;
     
    173194        /* Error exit */
    174195        loader_abort(ldr);
    175         free(ldr);
    176196        return rc;
    177197}
     
    182202 * loader API. Arguments are passed as a null-terminated list of arguments.
    183203 *
    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.
     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 *
    189210 */
    190211int task_spawnl(task_id_t *task_id, const char *path, ...)
    191212{
     213        /* Count the number of arguments. */
     214       
    192215        va_list ap;
    193         int rc, cnt;
    194216        const char *arg;
    195217        const char **arglist;
    196 
    197         /* Count the number of arguments. */
    198         cnt = 0;
     218        int cnt = 0;
     219       
    199220        va_start(ap, path);
    200221        do {
     
    203224        } while (arg != NULL);
    204225        va_end(ap);
    205 
     226       
    206227        /* Allocate argument list. */
    207228        arglist = malloc(cnt * sizeof(const char *));
    208229        if (arglist == NULL)
    209230                return ENOMEM;
    210 
     231       
    211232        /* Fill in arguments. */
    212233        cnt = 0;
     
    217238        } while (arg != NULL);
    218239        va_end(ap);
    219 
     240       
    220241        /* Spawn task. */
    221         rc = task_spawnv(task_id, path, arglist);
    222 
     242        int rc = task_spawnv(task_id, path, arglist);
     243       
    223244        /* Free argument list. */
    224245        free(arglist);
     
    228249int task_wait(task_id_t id, task_exit_t *texit, int *retval)
    229250{
     251        assert(texit);
     252        assert(retval);
     253       
     254        async_exch_t *exch = async_exchange_begin(session_ns);
    230255        sysarg_t te, rv;
    231         int rc;
    232 
    233         rc = (int) async_req_2_2(PHONE_NS, NS_TASK_WAIT, LOWER32(id),
     256        int rc = (int) async_req_2_2(exch, NS_TASK_WAIT, LOWER32(id),
    234257            UPPER32(id), &te, &rv);
     258        async_exchange_end(exch);
     259       
    235260        *texit = te;
    236261        *retval = rv;
    237 
     262       
    238263        return rc;
    239264}
     
    241266int task_retval(int val)
    242267{
    243         return (int) async_req_1_0(PHONE_NS, NS_RETVAL, val);
     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;
    244273}
    245274
Note: See TracChangeset for help on using the changeset viewer.