Changeset b0f00a9 in mainline for uspace/lib/c/generic/task.c
- Timestamp:
- 2011-11-06T22:21:05Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/fix-logger-deadlock, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 898e847
- Parents:
- 2bdf8313 (diff), 7b5f4c9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
uspace/lib/c/generic/task.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/task.c
r2bdf8313 rb0f00a9 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" 48 #include <vfs/vfs.h> 46 49 47 50 task_id_t task_get_id(void) … … 68 71 int task_set_name(const char *name) 69 72 { 73 assert(name); 74 70 75 return __SYSCALL2(SYS_TASK_SET_NAME, (sysarg_t) name, str_size(name)); 71 76 } … … 88 93 * loader API. Arguments are passed as a null-terminated array of strings. 89 94 * 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. 95 * @param id If not NULL, the ID of the task is stored here on success. 96 * @param path Pathname of the binary to execute. 97 * @param argv Command-line arguments. 98 * 99 * @return Zero on success or negative error code. 100 * 95 101 */ 96 102 int task_spawnv(task_id_t *id, const char *path, const char *const args[]) 97 103 { 98 loader_t *ldr; 99 task_id_t task_id; 100 int rc; 101 104 /* Send default files */ 105 int *files[4]; 106 int fd_stdin; 107 int fd_stdout; 108 int fd_stderr; 109 110 if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK)) 111 files[0] = &fd_stdin; 112 else 113 files[0] = NULL; 114 115 if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK)) 116 files[1] = &fd_stdout; 117 else 118 files[1] = NULL; 119 120 if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK)) 121 files[2] = &fd_stderr; 122 else 123 files[2] = NULL; 124 125 files[3] = NULL; 126 127 return task_spawnvf(id, path, args, files); 128 } 129 130 /** Create a new task by running an executable from the filesystem. 131 * 132 * This is really just a convenience wrapper over the more complicated 133 * loader API. Arguments are passed as a null-terminated array of strings. 134 * Files are passed as null-terminated array of pointers to fdi_node_t. 135 * 136 * @param id If not NULL, the ID of the task is stored here on success. 137 * @param path Pathname of the binary to execute. 138 * @param argv Command-line arguments. 139 * @param files Standard files to use. 140 * 141 * @return Zero on success or negative error code. 142 * 143 */ 144 int task_spawnvf(task_id_t *id, const char *path, const char *const args[], 145 int *const files[]) 146 { 102 147 /* Connect to a program loader. */ 103 l dr = loader_connect();148 loader_t *ldr = loader_connect(); 104 149 if (ldr == NULL) 105 150 return EREFUSED; 106 151 107 152 /* Get task ID. */ 108 rc = loader_get_task_id(ldr, &task_id); 153 task_id_t task_id; 154 int rc = loader_get_task_id(ldr, &task_id); 109 155 if (rc != EOK) 110 156 goto error; … … 125 171 goto error; 126 172 127 /* Send default files */ 128 fdi_node_t *files[4]; 129 fdi_node_t stdin_node; 130 fdi_node_t stdout_node; 131 fdi_node_t stderr_node; 132 133 if ((stdin != NULL) && (fnode(stdin, &stdin_node) == EOK)) 134 files[0] = &stdin_node; 135 else 136 files[0] = NULL; 137 138 if ((stdout != NULL) && (fnode(stdout, &stdout_node) == EOK)) 139 files[1] = &stdout_node; 140 else 141 files[1] = NULL; 142 143 if ((stderr != NULL) && (fnode(stderr, &stderr_node) == EOK)) 144 files[2] = &stderr_node; 145 else 146 files[2] = NULL; 147 148 files[3] = NULL; 149 173 /* Send files */ 150 174 rc = loader_set_files(ldr, files); 151 175 if (rc != EOK) … … 163 187 164 188 /* Success */ 165 free(ldr);166 167 189 if (id != NULL) 168 190 *id = task_id; … … 173 195 /* Error exit */ 174 196 loader_abort(ldr); 175 free(ldr);176 197 return rc; 177 198 } … … 182 203 * loader API. Arguments are passed as a null-terminated list of arguments. 183 204 * 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. 205 * @param id If not NULL, the ID of the task is stored here on success. 206 * @param path Pathname of the binary to execute. 207 * @param ... Command-line arguments. 208 * 209 * @return Zero on success or negative error code. 210 * 189 211 */ 190 212 int task_spawnl(task_id_t *task_id, const char *path, ...) 191 213 { 214 /* Count the number of arguments. */ 215 192 216 va_list ap; 193 int rc, cnt;194 217 const char *arg; 195 218 const char **arglist; 196 197 /* Count the number of arguments. */ 198 cnt = 0; 219 int cnt = 0; 220 199 221 va_start(ap, path); 200 222 do { … … 203 225 } while (arg != NULL); 204 226 va_end(ap); 205 227 206 228 /* Allocate argument list. */ 207 229 arglist = malloc(cnt * sizeof(const char *)); 208 230 if (arglist == NULL) 209 231 return ENOMEM; 210 232 211 233 /* Fill in arguments. */ 212 234 cnt = 0; … … 217 239 } while (arg != NULL); 218 240 va_end(ap); 219 241 220 242 /* Spawn task. */ 221 rc = task_spawnv(task_id, path, arglist);222 243 int rc = task_spawnv(task_id, path, arglist); 244 223 245 /* Free argument list. */ 224 246 free(arglist); … … 228 250 int task_wait(task_id_t id, task_exit_t *texit, int *retval) 229 251 { 252 assert(texit); 253 assert(retval); 254 255 async_exch_t *exch = async_exchange_begin(session_ns); 230 256 sysarg_t te, rv; 231 int rc; 232 233 rc = (int) async_req_2_2(PHONE_NS, NS_TASK_WAIT, LOWER32(id), 257 int rc = (int) async_req_2_2(exch, NS_TASK_WAIT, LOWER32(id), 234 258 UPPER32(id), &te, &rv); 259 async_exchange_end(exch); 260 235 261 *texit = te; 236 262 *retval = rv; 237 263 238 264 return rc; 239 265 } … … 241 267 int task_retval(int val) 242 268 { 243 return (int) async_req_1_0(PHONE_NS, NS_RETVAL, val); 269 async_exch_t *exch = async_exchange_begin(session_ns); 270 int rc = (int) async_req_1_0(exch, NS_RETVAL, val); 271 async_exchange_end(exch); 272 273 return rc; 244 274 } 245 275
Note:
See TracChangeset
for help on using the changeset viewer.
