Changes in uspace/lib/c/generic/task.c [3815efb:1e9f8ab] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/task.c
r3815efb r1e9f8ab 35 35 36 36 #include <task.h> 37 #include <libc.h> 38 #include <stdlib.h> 39 #include <errno.h> 37 40 #include <loader/loader.h> 38 41 #include <stdarg.h> … … 40 43 #include <ipc/ns.h> 41 44 #include <macros.h> 42 #include <assert.h>43 45 #include <async.h> 44 #include <errno.h>45 #include <malloc.h>46 #include <libc.h>47 #include "private/ns.h"48 46 49 47 task_id_t task_get_id(void) … … 70 68 int task_set_name(const char *name) 71 69 { 72 assert(name);73 74 70 return __SYSCALL2(SYS_TASK_SET_NAME, (sysarg_t) name, str_size(name)); 75 71 } … … 92 88 * loader API. Arguments are passed as a null-terminated array of strings. 93 89 * 94 * @param id If not NULL, the ID of the task is stored here on success. 95 * @param path Pathname of the binary to execute. 96 * @param argv Command-line arguments. 97 * 98 * @return Zero on success or negative error code. 99 * 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. 100 95 */ 101 96 int task_spawnv(task_id_t *id, const char *path, const char *const args[]) 102 97 { 98 loader_t *ldr; 99 task_id_t task_id; 100 int rc; 101 102 /* Connect to a program loader. */ 103 ldr = loader_connect(); 104 if (ldr == NULL) 105 return EREFUSED; 106 107 /* Get 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); 114 if (rc != EOK) 115 goto error; 116 117 /* Send program pathname. */ 118 rc = loader_set_pathname(ldr, path); 119 if (rc != EOK) 120 goto error; 121 122 /* Send arguments. */ 123 rc = loader_set_args(ldr, args); 124 if (rc != EOK) 125 goto error; 126 103 127 /* Send default files */ 104 128 fdi_node_t *files[4]; … … 124 148 files[3] = NULL; 125 149 126 return task_spawnvf(id, path, args, files);127 }128 129 /** Create a new task by running an executable from the filesystem.130 *131 * This is really just a convenience wrapper over the more complicated132 * loader API. Arguments are passed as a null-terminated array of strings.133 * Files are passed as null-terminated array of pointers to fdi_node_t.134 *135 * @param id If not NULL, the ID of the task is stored here on success.136 * @param path Pathname of the binary to execute.137 * @param argv Command-line arguments.138 * @param files Standard files to use.139 *140 * @return Zero on success or negative error code.141 *142 */143 int task_spawnvf(task_id_t *id, const char *path, const char *const args[],144 fdi_node_t *const files[])145 {146 /* Connect to a program loader. */147 loader_t *ldr = loader_connect();148 if (ldr == NULL)149 return EREFUSED;150 151 /* Get task ID. */152 task_id_t task_id;153 int rc = loader_get_task_id(ldr, &task_id);154 if (rc != EOK)155 goto error;156 157 /* Send spawner's current working directory. */158 rc = loader_set_cwd(ldr);159 if (rc != EOK)160 goto error;161 162 /* Send program pathname. */163 rc = loader_set_pathname(ldr, path);164 if (rc != EOK)165 goto error;166 167 /* Send arguments. */168 rc = loader_set_args(ldr, args);169 if (rc != EOK)170 goto error;171 172 /* Send files */173 150 rc = loader_set_files(ldr, files); 174 151 if (rc != EOK) … … 186 163 187 164 /* Success */ 165 free(ldr); 166 188 167 if (id != NULL) 189 168 *id = task_id; … … 194 173 /* Error exit */ 195 174 loader_abort(ldr); 175 free(ldr); 196 176 return rc; 197 177 } … … 202 182 * loader API. Arguments are passed as a null-terminated list of arguments. 203 183 * 204 * @param id If not NULL, the ID of the task is stored here on success. 205 * @param path Pathname of the binary to execute. 206 * @param ... Command-line arguments. 207 * 208 * @return Zero on success or negative error code. 209 * 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. 210 189 */ 211 190 int task_spawnl(task_id_t *task_id, const char *path, ...) 212 191 { 213 /* Count the number of arguments. */214 215 192 va_list ap; 193 int rc, cnt; 216 194 const char *arg; 217 195 const char **arglist; 218 int cnt = 0; 219 196 197 /* Count the number of arguments. */ 198 cnt = 0; 220 199 va_start(ap, path); 221 200 do { … … 224 203 } while (arg != NULL); 225 204 va_end(ap); 226 205 227 206 /* Allocate argument list. */ 228 207 arglist = malloc(cnt * sizeof(const char *)); 229 208 if (arglist == NULL) 230 209 return ENOMEM; 231 210 232 211 /* Fill in arguments. */ 233 212 cnt = 0; … … 238 217 } while (arg != NULL); 239 218 va_end(ap); 240 219 241 220 /* Spawn task. */ 242 intrc = task_spawnv(task_id, path, arglist);243 221 rc = task_spawnv(task_id, path, arglist); 222 244 223 /* Free argument list. */ 245 224 free(arglist); … … 249 228 int task_wait(task_id_t id, task_exit_t *texit, int *retval) 250 229 { 251 assert(texit);252 assert(retval);253 254 async_exch_t *exch = async_exchange_begin(session_ns);255 230 sysarg_t te, rv; 256 int rc = (int) async_req_2_2(exch, NS_TASK_WAIT, LOWER32(id), 231 int rc; 232 233 rc = (int) async_req_2_2(PHONE_NS, NS_TASK_WAIT, LOWER32(id), 257 234 UPPER32(id), &te, &rv); 258 async_exchange_end(exch);259 260 235 *texit = te; 261 236 *retval = rv; 262 237 263 238 return rc; 264 239 } … … 266 241 int task_retval(int val) 267 242 { 268 async_exch_t *exch = async_exchange_begin(session_ns); 269 int rc = (int) async_req_1_0(exch, NS_RETVAL, val); 270 async_exchange_end(exch); 271 272 return rc; 243 return (int) async_req_1_0(PHONE_NS, NS_RETVAL, val); 273 244 } 274 245
Note:
See TracChangeset
for help on using the changeset viewer.