Changeset 04803bf in mainline for uspace/lib/c/generic/task.c


Ignore:
Timestamp:
2011-03-21T22:00:17Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
143932e3
Parents:
b50b5af2 (diff), 7308e84 (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 (needs fixes).

File:
1 moved

Legend:

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

    rb50b5af2 r04803bf  
    3939#include <errno.h>
    4040#include <loader/loader.h>
    41 #include <string.h>
     41#include <stdarg.h>
     42#include <str.h>
    4243#include <ipc/ns.h>
    4344#include <macros.h>
     
    4647task_id_t task_get_id(void)
    4748{
     49#ifdef __32_BITS__
    4850        task_id_t task_id;
    4951        (void) __SYSCALL1(SYS_TASK_GET_ID, (sysarg_t) &task_id);
    5052       
    5153        return task_id;
     54#endif  /* __32_BITS__ */
     55       
     56#ifdef __64_BITS__
     57        return (task_id_t) __SYSCALL0(SYS_TASK_GET_ID);
     58#endif  /* __64_BITS__ */
    5259}
    5360
     
    5865 *
    5966 * @return Zero on success or negative error code.
    60  *
    6167 */
    6268int task_set_name(const char *name)
     
    6571}
    6672
     73/** Kill a task.
     74 *
     75 * @param task_id ID of task to kill.
     76 *
     77 * @return Zero on success or negative error code.
     78 */
     79
     80int task_kill(task_id_t task_id)
     81{
     82        return (int) __SYSCALL1(SYS_TASK_KILL, (sysarg_t) &task_id);
     83}
     84
    6785/** Create a new task by running an executable from the filesystem.
    6886 *
    6987 * This is really just a convenience wrapper over the more complicated
    70  * loader API.
    71  *
    72  * @param path pathname of the binary to execute
    73  * @param argv command-line arguments
    74  *
    75  * @return ID of the newly created task or zero on error.
    76  *
    77  */
    78 task_id_t task_spawn(const char *path, char *const args[])
    79 {
     88 * loader API. Arguments are passed as a null-terminated array of strings.
     89 *
     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.
     95 */
     96int task_spawnv(task_id_t *id, const char *path, const char *const args[])
     97{
     98        loader_t *ldr;
     99        task_id_t task_id;
     100        int rc;
     101
    80102        /* Connect to a program loader. */
    81         loader_t *ldr = loader_connect();
     103        ldr = loader_connect();
    82104        if (ldr == NULL)
    83                 return 0;
     105                return EREFUSED;
    84106       
    85107        /* Get task ID. */
    86         task_id_t task_id;
    87         int rc = loader_get_task_id(ldr, &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);
    88114        if (rc != EOK)
    89115                goto error;
     
    98124        if (rc != EOK)
    99125                goto error;
    100        
    101126       
    102127        /* Send default files */
     
    139164        /* Success */
    140165        free(ldr);
    141         return task_id;
     166       
     167        if (id != NULL)
     168                *id = task_id;
     169       
     170        return EOK;
    142171       
    143172error:
     
    145174        loader_abort(ldr);
    146175        free(ldr);
    147        
    148         return 0;
     176        return rc;
     177}
     178
     179/** Create a new task by running an executable from the filesystem.
     180 *
     181 * This is really just a convenience wrapper over the more complicated
     182 * loader API. Arguments are passed as a null-terminated list of arguments.
     183 *
     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.
     189 */
     190int task_spawnl(task_id_t *task_id, const char *path, ...)
     191{
     192        va_list ap;
     193        int rc, cnt;
     194        const char *arg;
     195        const char **arglist;
     196
     197        /* Count the number of arguments. */
     198        cnt = 0;
     199        va_start(ap, path);
     200        do {
     201                arg = va_arg(ap, const char *);
     202                cnt++;
     203        } while (arg != NULL);
     204        va_end(ap);
     205
     206        /* Allocate argument list. */
     207        arglist = malloc(cnt * sizeof(const char *));
     208        if (arglist == NULL)
     209                return ENOMEM;
     210
     211        /* Fill in arguments. */
     212        cnt = 0;
     213        va_start(ap, path);
     214        do {
     215                arg = va_arg(ap, const char *);
     216                arglist[cnt++] = arg;
     217        } while (arg != NULL);
     218        va_end(ap);
     219
     220        /* Spawn task. */
     221        rc = task_spawnv(task_id, path, arglist);
     222
     223        /* Free argument list. */
     224        free(arglist);
     225        return rc;
    149226}
    150227
    151228int task_wait(task_id_t id, task_exit_t *texit, int *retval)
    152229{
    153         ipcarg_t te, rv;
     230        sysarg_t te, rv;
    154231        int rc;
    155232
Note: See TracChangeset for help on using the changeset viewer.