Changes in uspace/lib/c/generic/task.c [d9fae235:0485135] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/task.c
rd9fae235 r0485135 39 39 #include <errno.h> 40 40 #include <loader/loader.h> 41 #include <stdarg.h> 41 42 #include <str.h> 42 43 #include <ipc/ns.h> … … 68 69 * 69 70 * This is really just a convenience wrapper over the more complicated 70 * loader API. 71 * 72 * @param path Pathname of the binary to execute. 73 * @param argv Command-line arguments. 74 * @param err If not NULL, the error value is stored here. 75 * 76 * @return ID of the newly created task or zero on error. 77 * 78 */ 79 task_id_t task_spawn(const char *path, const char *const args[], int *err) 80 { 71 * loader API. Arguments are passed as a null-terminated array of strings. 72 * 73 * @param id If not NULL, the ID of the task is stored here on success. 74 * @param path Pathname of the binary to execute. 75 * @param argv Command-line arguments. 76 * 77 * @return Zero on success or negative error code. 78 */ 79 int task_spawnv(task_id_t *id, const char *path, const char *const args[]) 80 { 81 loader_t *ldr; 82 task_id_t task_id; 83 int rc; 84 81 85 /* Connect to a program loader. */ 82 loader_t *ldr = loader_connect(); 83 if (ldr == NULL) { 84 if (err != NULL) 85 *err = EREFUSED; 86 87 return 0; 88 } 86 ldr = loader_connect(); 87 if (ldr == NULL) 88 return EREFUSED; 89 89 90 90 /* Get task ID. */ 91 task_id_t task_id; 92 int rc = loader_get_task_id(ldr, &task_id); 91 rc = loader_get_task_id(ldr, &task_id); 93 92 if (rc != EOK) 94 93 goto error; … … 149 148 free(ldr); 150 149 151 if ( err!= NULL)152 * err = EOK;153 154 return task_id;150 if (id != NULL) 151 *id = task_id; 152 153 return EOK; 155 154 156 155 error: … … 158 157 loader_abort(ldr); 159 158 free(ldr); 160 161 if (err != NULL) 162 *err = rc; 163 164 return 0; 159 return rc; 160 } 161 162 /** Create a new task by running an executable from the filesystem. 163 * 164 * This is really just a convenience wrapper over the more complicated 165 * loader API. Arguments are passed as a null-terminated list of arguments. 166 * 167 * @param id If not NULL, the ID of the task is stored here on success. 168 * @param path Pathname of the binary to execute. 169 * @param ... Command-line arguments. 170 * 171 * @return Zero on success or negative error code. 172 */ 173 int task_spawnl(task_id_t *task_id, const char *path, ...) 174 { 175 va_list ap; 176 int rc, cnt; 177 const char *arg; 178 const char **arglist; 179 180 /* Count the number of arguments. */ 181 cnt = 0; 182 va_start(ap, path); 183 do { 184 arg = va_arg(ap, const char *); 185 cnt++; 186 } while (arg != NULL); 187 va_end(ap); 188 189 /* Allocate argument list. */ 190 arglist = malloc(cnt * sizeof(const char *)); 191 if (arglist == NULL) 192 return ENOMEM; 193 194 /* Fill in arguments. */ 195 cnt = 0; 196 va_start(ap, path); 197 do { 198 arg = va_arg(ap, const char *); 199 arglist[cnt++] = arg; 200 } while (arg != NULL); 201 va_end(ap); 202 203 /* Spawn task. */ 204 rc = task_spawnv(task_id, path, arglist); 205 206 /* Free argument list. */ 207 free(arglist); 208 return rc; 165 209 } 166 210
Note:
See TracChangeset
for help on using the changeset viewer.