Changes in uspace/lib/c/generic/task.c [1e9f8ab:0eff68e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/task.c
r1e9f8ab r0eff68e 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; … … 173 173 /* Error exit */ 174 174 loader_abort(ldr); 175 free(ldr);176 175 return rc; 177 176 } … … 182 181 * loader API. Arguments are passed as a null-terminated list of arguments. 183 182 * 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. 183 * @param id If not NULL, the ID of the task is stored here on success. 184 * @param path Pathname of the binary to execute. 185 * @param ... Command-line arguments. 186 * 187 * @return Zero on success or negative error code. 188 * 189 189 */ 190 190 int task_spawnl(task_id_t *task_id, const char *path, ...) 191 191 { 192 /* Count the number of arguments. */ 193 192 194 va_list ap; 193 int rc, cnt;194 195 const char *arg; 195 196 const char **arglist; 196 197 /* Count the number of arguments. */ 198 cnt = 0; 197 int cnt = 0; 198 199 199 va_start(ap, path); 200 200 do { … … 203 203 } while (arg != NULL); 204 204 va_end(ap); 205 205 206 206 /* Allocate argument list. */ 207 207 arglist = malloc(cnt * sizeof(const char *)); 208 208 if (arglist == NULL) 209 209 return ENOMEM; 210 210 211 211 /* Fill in arguments. */ 212 212 cnt = 0; … … 217 217 } while (arg != NULL); 218 218 va_end(ap); 219 219 220 220 /* Spawn task. */ 221 rc = task_spawnv(task_id, path, arglist);222 221 int rc = task_spawnv(task_id, path, arglist); 222 223 223 /* Free argument list. */ 224 224 free(arglist); … … 228 228 int task_wait(task_id_t id, task_exit_t *texit, int *retval) 229 229 { 230 assert(texit); 231 assert(retval); 232 233 async_exch_t *exch = async_exchange_begin(session_ns); 230 234 sysarg_t te, rv; 231 int rc; 232 233 rc = (int) async_req_2_2(PHONE_NS, NS_TASK_WAIT, LOWER32(id), 235 int rc = (int) async_req_2_2(exch, NS_TASK_WAIT, LOWER32(id), 234 236 UPPER32(id), &te, &rv); 237 async_exchange_end(exch); 238 235 239 *texit = te; 236 240 *retval = rv; 237 241 238 242 return rc; 239 243 } … … 241 245 int task_retval(int val) 242 246 { 243 return (int) async_req_1_0(PHONE_NS, NS_RETVAL, val); 247 async_exch_t *exch = async_exchange_begin(session_ns); 248 int rc = (int) async_req_1_0(exch, NS_RETVAL, val); 249 async_exchange_end(exch); 250 251 return rc; 244 252 } 245 253
Note:
See TracChangeset
for help on using the changeset viewer.