Changeset 79ae36dd in mainline for uspace/lib/c/generic/task.c
- Timestamp:
- 2011-06-08T19:01:55Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0eff68e
- Parents:
- 764d71e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/task.c
r764d71e r79ae36dd 35 35 36 36 #include <task.h> 37 #include <libc.h>38 #include <stdlib.h>39 #include <errno.h>40 37 #include <loader/loader.h> 41 38 #include <stdarg.h> … … 43 40 #include <ipc/ns.h> 44 41 #include <macros.h> 42 #include <assert.h> 45 43 #include <async.h> 44 #include <errno.h> 45 #include <malloc.h> 46 #include <libc.h> 47 #include "private/ns.h" 46 48 47 49 task_id_t task_get_id(void) … … 68 70 int task_set_name(const char *name) 69 71 { 72 assert(name); 73 70 74 return __SYSCALL2(SYS_TASK_SET_NAME, (sysarg_t) name, str_size(name)); 71 75 } … … 88 92 * loader API. Arguments are passed as a null-terminated array of strings. 89 93 * 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. 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 * 95 100 */ 96 101 int task_spawnv(task_id_t *id, const char *path, const char *const args[]) 97 102 { 98 loader_t *ldr;99 task_id_t task_id;100 int rc;101 102 103 /* Connect to a program loader. */ 103 l dr = loader_connect();104 loader_t *ldr = loader_connect(); 104 105 if (ldr == NULL) 105 106 return EREFUSED; 106 107 107 108 /* Get task ID. */ 108 rc = loader_get_task_id(ldr, &task_id); 109 task_id_t task_id; 110 int rc = loader_get_task_id(ldr, &task_id); 109 111 if (rc != EOK) 110 112 goto error; … … 163 165 164 166 /* Success */ 165 free(ldr);166 167 167 if (id != NULL) 168 168 *id = task_id; … … 182 182 * loader API. Arguments are passed as a null-terminated list of arguments. 183 183 * 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. 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. 189 * 189 190 */ 190 191 int task_spawnl(task_id_t *task_id, const char *path, ...) 191 192 { 193 /* Count the number of arguments. */ 194 192 195 va_list ap; 193 int rc, cnt;194 196 const char *arg; 195 197 const char **arglist; 196 197 /* Count the number of arguments. */ 198 cnt = 0; 198 int cnt = 0; 199 199 200 va_start(ap, path); 200 201 do { … … 203 204 } while (arg != NULL); 204 205 va_end(ap); 205 206 206 207 /* Allocate argument list. */ 207 208 arglist = malloc(cnt * sizeof(const char *)); 208 209 if (arglist == NULL) 209 210 return ENOMEM; 210 211 211 212 /* Fill in arguments. */ 212 213 cnt = 0; … … 217 218 } while (arg != NULL); 218 219 va_end(ap); 219 220 220 221 /* Spawn task. */ 221 rc = task_spawnv(task_id, path, arglist);222 222 int rc = task_spawnv(task_id, path, arglist); 223 223 224 /* Free argument list. */ 224 225 free(arglist); … … 228 229 int task_wait(task_id_t id, task_exit_t *texit, int *retval) 229 230 { 231 assert(texit); 232 assert(retval); 233 234 async_exch_t *exch = async_exchange_begin(session_ns); 230 235 sysarg_t te, rv; 231 int rc; 232 233 rc = (int) async_req_2_2(PHONE_NS, NS_TASK_WAIT, LOWER32(id), 236 int rc = (int) async_req_2_2(exch, NS_TASK_WAIT, LOWER32(id), 234 237 UPPER32(id), &te, &rv); 238 async_exchange_end(exch); 239 235 240 *texit = te; 236 241 *retval = rv; 237 242 238 243 return rc; 239 244 } … … 241 246 int task_retval(int val) 242 247 { 243 return (int) async_req_1_0(PHONE_NS, NS_RETVAL, val); 248 async_exch_t *exch = async_exchange_begin(session_ns); 249 int rc = (int) async_req_1_0(exch, NS_RETVAL, val); 250 async_exchange_end(exch); 251 252 return rc; 244 253 } 245 254
Note:
See TracChangeset
for help on using the changeset viewer.