Subversion Repositories HelenOS

Rev

Rev 4263 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4263 Rev 4581
Line 29... Line 29...
29
 
29
 
30
/** @addtogroup libc
30
/** @addtogroup libc
31
 * @{
31
 * @{
32
 */
32
 */
33
/** @file
33
/** @file
34
 */
34
 */
35
 
35
 
36
#include <task.h>
36
#include <task.h>
37
#include <libc.h>
37
#include <libc.h>
38
#include <stdlib.h>
38
#include <stdlib.h>
39
#include <errno.h>
39
#include <errno.h>
40
#include <loader/loader.h>
40
#include <loader/loader.h>
41
#include <string.h>
41
#include <string.h>
-
 
42
#include <ipc/ns.h>
-
 
43
#include <macros.h>
-
 
44
#include <async.h>
42
 
45
 
43
task_id_t task_get_id(void)
46
task_id_t task_get_id(void)
44
{
47
{
45
    task_id_t task_id;
48
    task_id_t task_id;
46
 
-
 
47
    (void) __SYSCALL1(SYS_TASK_GET_ID, (sysarg_t) &task_id);
49
    (void) __SYSCALL1(SYS_TASK_GET_ID, (sysarg_t) &task_id);
48
 
50
   
49
    return task_id;
51
    return task_id;
50
}
52
}
51
 
53
 
52
/** Set the task name.
54
/** Set the task name.
53
 *
55
 *
54
 * @param name  The new name, typically the command used to execute the
56
 * @param name The new name, typically the command used to execute the
55
 *      program.
57
 *             program.
-
 
58
 *
56
 * @return  Zero on success or negative error code.
59
 * @return Zero on success or negative error code.
-
 
60
 *
57
 */
61
 */
58
int task_set_name(const char *name)
62
int task_set_name(const char *name)
59
{
63
{
60
    return __SYSCALL2(SYS_TASK_SET_NAME, (sysarg_t) name, str_size(name));
64
    return __SYSCALL2(SYS_TASK_SET_NAME, (sysarg_t) name, str_size(name));
61
}
65
}
Line 63... Line 67...
63
/** Create a new task by running an executable from the filesystem.
67
/** Create a new task by running an executable from the filesystem.
64
 *
68
 *
65
 * This is really just a convenience wrapper over the more complicated
69
 * This is really just a convenience wrapper over the more complicated
66
 * loader API.
70
 * loader API.
67
 *
71
 *
68
 * @param path  pathname of the binary to execute
72
 * @param path pathname of the binary to execute
69
 * @param argv  command-line arguments
73
 * @param argv command-line arguments
-
 
74
 *
70
 * @return  ID of the newly created task or zero on error.
75
 * @return ID of the newly created task or zero on error.
-
 
76
 *
71
 */
77
 */
72
task_id_t task_spawn(const char *path, char *const argv[])
78
task_id_t task_spawn(const char *path, char *const args[])
73
{
79
{
74
    loader_t *ldr;
-
 
75
    task_id_t task_id;
-
 
76
    int rc;
-
 
77
 
-
 
78
    /* Connect to a program loader. */
80
    /* Connect to a program loader. */
79
    ldr = loader_connect();
81
    loader_t *ldr = loader_connect();
80
    if (ldr == NULL)
82
    if (ldr == NULL)
81
        return 0;
83
        return 0;
82
 
84
   
83
    /* Get task ID. */
85
    /* Get task ID. */
-
 
86
    task_id_t task_id;
84
    rc = loader_get_task_id(ldr, &task_id);
87
    int rc = loader_get_task_id(ldr, &task_id);
85
    if (rc != EOK)
88
    if (rc != EOK)
86
        goto error;
89
        goto error;
87
 
90
   
88
    /* Send program pathname. */
91
    /* Send program pathname. */
89
    rc = loader_set_pathname(ldr, path);
92
    rc = loader_set_pathname(ldr, path);
90
    if (rc != EOK)
93
    if (rc != EOK)
91
        goto error;
94
        goto error;
92
 
95
   
93
    /* Send arguments. */
96
    /* Send arguments. */
94
    rc = loader_set_args(ldr, argv);
97
    rc = loader_set_args(ldr, args);
95
    if (rc != EOK)
98
    if (rc != EOK)
96
        goto error;
99
        goto error;
-
 
100
   
97
 
101
   
-
 
102
    /* Send default files */
-
 
103
    fdi_node_t *files[4];
-
 
104
    fdi_node_t stdin_node;
-
 
105
    fdi_node_t stdout_node;
-
 
106
    fdi_node_t stderr_node;
-
 
107
   
-
 
108
    if ((stdin != NULL) && (fnode(stdin, &stdin_node) == EOK))
-
 
109
        files[0] = &stdin_node;
-
 
110
    else
-
 
111
        files[0] = NULL;
-
 
112
   
-
 
113
    if ((stdout != NULL) && (fnode(stdout, &stdout_node) == EOK))
-
 
114
        files[1] = &stdout_node;
-
 
115
    else
-
 
116
        files[1] = NULL;
-
 
117
   
-
 
118
    if ((stderr != NULL) && (fnode(stderr, &stderr_node) == EOK))
-
 
119
        files[2] = &stderr_node;
-
 
120
    else
-
 
121
        files[2] = NULL;
-
 
122
   
-
 
123
    files[3] = NULL;
-
 
124
   
-
 
125
    rc = loader_set_files(ldr, files);
-
 
126
    if (rc != EOK)
-
 
127
        goto error;
-
 
128
   
98
    /* Load the program. */
129
    /* Load the program. */
99
    rc = loader_load_program(ldr);
130
    rc = loader_load_program(ldr);
100
    if (rc != EOK)
131
    if (rc != EOK)
101
        goto error;
132
        goto error;
102
 
133
   
103
    /* Run it. */
134
    /* Run it. */
104
    rc = loader_run(ldr);
135
    rc = loader_run(ldr);
105
    if (rc != EOK)
136
    if (rc != EOK)
106
        goto error;
137
        goto error;
107
 
138
   
108
    /* Success */
139
    /* Success */
109
 
-
 
110
    free(ldr);
140
    free(ldr);
111
    return task_id;
141
    return task_id;
112
 
142
   
113
    /* Error exit */
-
 
114
error:
143
error:
-
 
144
    /* Error exit */
115
    loader_abort(ldr);
145
    loader_abort(ldr);
116
    free(ldr);
146
    free(ldr);
117
 
147
   
118
    return 0;
148
    return 0;
119
}
149
}
120
 
150
 
-
 
151
int task_wait(task_id_t id)
-
 
152
{
-
 
153
    return (int) async_req_2_0(PHONE_NS, NS_TASK_WAIT, LOWER32(id), UPPER32(id));
-
 
154
}
-
 
155
 
121
/** @}
156
/** @}
122
 */
157
 */