Changeset ee369f3 in mainline for uspace/lib/libc/generic/task.c


Ignore:
Timestamp:
2009-06-03T19:11:31Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e1ab30f8
Parents:
3ddd90c
Message:

pass current task stdin, stdout and stderr as preset files to the loader
add task_wait()

File:
1 edited

Legend:

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

    r3ddd90c ree369f3  
    3232 */
    3333/** @file
    34  */ 
     34 */
    3535
    3636#include <task.h>
     
    4040#include <loader/loader.h>
    4141#include <string.h>
     42#include <ipc/ns.h>
     43#include <macros.h>
     44#include <async.h>
    4245
    4346task_id_t task_get_id(void)
    4447{
    4548        task_id_t task_id;
    46 
    4749        (void) __SYSCALL1(SYS_TASK_GET_ID, (sysarg_t) &task_id);
    48 
     50       
    4951        return task_id;
    5052}
     
    5254/** Set the task name.
    5355 *
    54  * @param name  The new name, typically the command used to execute the
    55  *              program.
    56  * @return      Zero on success or negative error code.
     56 * @param name The new name, typically the command used to execute the
     57 *             program.
     58 *
     59 * @return Zero on success or negative error code.
     60 *
    5761 */
    5862int task_set_name(const char *name)
     
    6670 * loader API.
    6771 *
    68  * @param path  pathname of the binary to execute
    69  * @param argv  command-line arguments
    70  * @return      ID of the newly created task or zero on error.
     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 *
    7177 */
    72 task_id_t task_spawn(const char *path, char *const argv[])
     78task_id_t task_spawn(const char *path, char *const args[])
    7379{
    74         loader_t *ldr;
    75         task_id_t task_id;
    76         int rc;
    77 
    7880        /* Connect to a program loader. */
    79         ldr = loader_connect();
     81        loader_t *ldr = loader_connect();
    8082        if (ldr == NULL)
    8183                return 0;
    82 
     84       
    8385        /* Get task ID. */
    84         rc = loader_get_task_id(ldr, &task_id);
     86        task_id_t task_id;
     87        int rc = loader_get_task_id(ldr, &task_id);
    8588        if (rc != EOK)
    8689                goto error;
    87 
     90       
    8891        /* Send program pathname. */
    8992        rc = loader_set_pathname(ldr, path);
    9093        if (rc != EOK)
    9194                goto error;
    92 
     95       
    9396        /* Send arguments. */
    94         rc = loader_set_args(ldr, argv);
     97        rc = loader_set_args(ldr, args);
    9598        if (rc != EOK)
    9699                goto error;
    97 
     100       
     101       
     102        /* Send default files */
     103        fs_node_t *files[4];
     104        fs_node_t stdin_node;
     105        fs_node_t stdout_node;
     106        fs_node_t stderr_node;
     107       
     108        if ((stdin != NULL) && (stdin != &stdin_null)) {
     109                fnode(stdin, &stdin_node);
     110                files[0] = &stdin_node;
     111        } else
     112                files[0] = NULL;
     113       
     114        if ((stdout != NULL) && (stdout != &stdout_klog)) {
     115                fnode(stdout, &stdout_node);
     116                files[1] = &stdout_node;
     117        } else
     118                files[1] = NULL;
     119       
     120        if ((stderr != NULL) && (stderr != &stdout_klog)) {
     121                fnode(stderr, &stderr_node);
     122                files[2] = &stderr_node;
     123        } else
     124                files[2] = NULL;
     125       
     126        files[3] = NULL;
     127       
     128        rc = loader_set_files(ldr, files);
     129        if (rc != EOK)
     130                goto error;
     131       
    98132        /* Load the program. */
    99133        rc = loader_load_program(ldr);
    100134        if (rc != EOK)
    101135                goto error;
    102 
     136       
    103137        /* Run it. */
    104138        rc = loader_run(ldr);
    105139        if (rc != EOK)
    106140                goto error;
    107 
     141       
    108142        /* Success */
    109 
    110143        free(ldr);
    111144        return task_id;
    112 
     145       
     146error:
    113147        /* Error exit */
    114 error:
    115148        loader_abort(ldr);
    116149        free(ldr);
     150       
     151        return 0;
     152}
    117153
    118         return 0;
     154int task_wait(task_id_t id)
     155{
     156        return (int) async_req_2_0(PHONE_NS, NS_TASK_WAIT, LOWER32(id), UPPER32(id));
    119157}
    120158
Note: See TracChangeset for help on using the changeset viewer.