Changeset c028b22 in mainline for uspace/lib/c/generic/task.c
- Timestamp:
- 2011-07-08T17:01:01Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cc1a727
- Parents:
- 4e36219 (diff), 026793d (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
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/task.c
r4e36219 rc028b22 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 /* 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 127 103 /* Send default files */ 128 104 fdi_node_t *files[4]; … … 148 124 files[3] = NULL; 149 125 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 complicated 132 * 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 */ 150 173 rc = loader_set_files(ldr, files); 151 174 if (rc != EOK) … … 163 186 164 187 /* Success */ 165 free(ldr);166 167 188 if (id != NULL) 168 189 *id = task_id; … … 173 194 /* Error exit */ 174 195 loader_abort(ldr); 175 free(ldr);176 196 return rc; 177 197 } … … 182 202 * loader API. Arguments are passed as a null-terminated list of arguments. 183 203 * 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. 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 * 189 210 */ 190 211 int task_spawnl(task_id_t *task_id, const char *path, ...) 191 212 { 213 /* Count the number of arguments. */ 214 192 215 va_list ap; 193 int rc, cnt;194 216 const char *arg; 195 217 const char **arglist; 196 197 /* Count the number of arguments. */ 198 cnt = 0; 218 int cnt = 0; 219 199 220 va_start(ap, path); 200 221 do { … … 203 224 } while (arg != NULL); 204 225 va_end(ap); 205 226 206 227 /* Allocate argument list. */ 207 228 arglist = malloc(cnt * sizeof(const char *)); 208 229 if (arglist == NULL) 209 230 return ENOMEM; 210 231 211 232 /* Fill in arguments. */ 212 233 cnt = 0; … … 217 238 } while (arg != NULL); 218 239 va_end(ap); 219 240 220 241 /* Spawn task. */ 221 rc = task_spawnv(task_id, path, arglist);222 242 int rc = task_spawnv(task_id, path, arglist); 243 223 244 /* Free argument list. */ 224 245 free(arglist); … … 228 249 int task_wait(task_id_t id, task_exit_t *texit, int *retval) 229 250 { 251 assert(texit); 252 assert(retval); 253 254 async_exch_t *exch = async_exchange_begin(session_ns); 230 255 sysarg_t te, rv; 231 int rc; 232 233 rc = (int) async_req_2_2(PHONE_NS, NS_TASK_WAIT, LOWER32(id), 256 int rc = (int) async_req_2_2(exch, NS_TASK_WAIT, LOWER32(id), 234 257 UPPER32(id), &te, &rv); 258 async_exchange_end(exch); 259 235 260 *texit = te; 236 261 *retval = rv; 237 262 238 263 return rc; 239 264 } … … 241 266 int task_retval(int val) 242 267 { 243 return (int) async_req_1_0(PHONE_NS, NS_RETVAL, val); 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; 244 273 } 245 274
Note:
See TracChangeset
for help on using the changeset viewer.