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


Ignore:
Timestamp:
2010-11-08T07:13:25Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
63a1e60
Parents:
d70a463 (diff), 3da12d74 (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

    rd70a463 rb40bfac  
    3939#include <errno.h>
    4040#include <loader/loader.h>
     41#include <stdarg.h>
    4142#include <str.h>
    4243#include <ipc/ns.h>
     
    6869 *
    6970 * 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  * @param err  If not NULL, the error value is stored here.
    75  *
    76  * @return ID of the newly created task or zero on error.
    77  *
    78  */
    79 task_id_t task_spawn(const char *path, const char *const args[], int *err)
    80 {
     71 * loader API. Arguments are passed as a null-terminated array of strings.
     72 *
     73 * @param id    If not NULL, the ID of the task is stored here on success.
     74 * @param path  Pathname of the binary to execute.
     75 * @param argv  Command-line arguments.
     76 *
     77 * @return      Zero on success or negative error code.
     78 */
     79int task_spawnv(task_id_t *id, const char *path, const char *const args[])
     80{
     81        loader_t *ldr;
     82        task_id_t task_id;
     83        int rc;
     84
    8185        /* Connect to a program loader. */
    82         loader_t *ldr = loader_connect();
    83         if (ldr == NULL) {
    84                 if (err != NULL)
    85                         *err = EREFUSED;
    86                
    87                 return 0;
    88         }
     86        ldr = loader_connect();
     87        if (ldr == NULL)
     88                return EREFUSED;
    8989       
    9090        /* Get task ID. */
    91         task_id_t task_id;
    92         int rc = loader_get_task_id(ldr, &task_id);
     91        rc = loader_get_task_id(ldr, &task_id);
    9392        if (rc != EOK)
    9493                goto error;
     
    149148        free(ldr);
    150149       
    151         if (err != NULL)
    152                 *err = EOK;
    153        
    154         return task_id;
     150        if (id != NULL)
     151                *id = task_id;
     152       
     153        return EOK;
    155154       
    156155error:
     
    158157        loader_abort(ldr);
    159158        free(ldr);
    160        
    161         if (err != NULL)
    162                 *err = rc;
    163        
    164         return 0;
     159        return rc;
     160}
     161
     162/** Create a new task by running an executable from the filesystem.
     163 *
     164 * This is really just a convenience wrapper over the more complicated
     165 * loader API. Arguments are passed as a null-terminated list of arguments.
     166 *
     167 * @param id    If not NULL, the ID of the task is stored here on success.
     168 * @param path  Pathname of the binary to execute.
     169 * @param ...   Command-line arguments.
     170 *
     171 * @return      Zero on success or negative error code.
     172 */
     173int task_spawnl(task_id_t *task_id, const char *path, ...)
     174{
     175        va_list ap;
     176        int rc, cnt;
     177        const char *arg;
     178        const char **arglist;
     179
     180        /* Count the number of arguments. */
     181        cnt = 0;
     182        va_start(ap, path);
     183        do {
     184                arg = va_arg(ap, const char *);
     185                cnt++;
     186        } while (arg != NULL);
     187        va_end(ap);
     188
     189        /* Allocate argument list. */
     190        arglist = malloc(cnt * sizeof(const char *));
     191        if (arglist == NULL)
     192                return ENOMEM;
     193
     194        /* Fill in arguments. */
     195        cnt = 0;
     196        va_start(ap, path);
     197        do {
     198                arg = va_arg(ap, const char *);
     199                arglist[cnt++] = arg;
     200        } while (arg != NULL);
     201        va_end(ap);
     202
     203        /* Spawn task. */
     204        rc = task_spawnv(task_id, path, arglist);
     205
     206        /* Free argument list. */
     207        free(arglist);
     208        return rc;
    165209}
    166210
Note: See TracChangeset for help on using the changeset viewer.