Ignore:
File:
1 edited

Legend:

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

    r0485135 rd9fae235  
    3939#include <errno.h>
    4040#include <loader/loader.h>
    41 #include <stdarg.h>
    4241#include <str.h>
    4342#include <ipc/ns.h>
     
    6968 *
    7069 * This is really just a convenience wrapper over the more complicated
    71  * loader API. Arguments are passed as a null-terminated array of strings.
     70 * loader API.
    7271 *
    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.
     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.
    7675 *
    77  * @return      Zero on success or negative error code.
     76 * @return ID of the newly created task or zero on error.
     77 *
    7878 */
    79 int task_spawnv(task_id_t *id, const char *path, const char *const args[])
     79task_id_t task_spawn(const char *path, const char *const args[], int *err)
    8080{
    81         loader_t *ldr;
    82         task_id_t task_id;
    83         int rc;
    84 
    8581        /* Connect to a program loader. */
    86         ldr = loader_connect();
    87         if (ldr == NULL)
    88                 return EREFUSED;
     82        loader_t *ldr = loader_connect();
     83        if (ldr == NULL) {
     84                if (err != NULL)
     85                        *err = EREFUSED;
     86               
     87                return 0;
     88        }
    8989       
    9090        /* Get task ID. */
    91         rc = loader_get_task_id(ldr, &task_id);
     91        task_id_t task_id;
     92        int rc = loader_get_task_id(ldr, &task_id);
    9293        if (rc != EOK)
    9394                goto error;
     
    148149        free(ldr);
    149150       
    150         if (id != NULL)
    151                 *id = task_id;
     151        if (err != NULL)
     152                *err = EOK;
    152153       
    153         return EOK;
     154        return task_id;
    154155       
    155156error:
     
    157158        loader_abort(ldr);
    158159        free(ldr);
    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  */
    173 int 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;
     160       
     161        if (err != NULL)
     162                *err = rc;
     163       
     164        return 0;
    209165}
    210166
Note: See TracChangeset for help on using the changeset viewer.