Changes in uspace/lib/c/generic/task.c [0485135:d9fae235] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/task.c
r0485135 rd9fae235 39 39 #include <errno.h> 40 40 #include <loader/loader.h> 41 #include <stdarg.h>42 41 #include <str.h> 43 42 #include <ipc/ns.h> … … 69 68 * 70 69 * This is really just a convenience wrapper over the more complicated 71 * loader API. Arguments are passed as a null-terminated array of strings.70 * loader API. 72 71 * 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.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. 76 75 * 77 * @return Zero on success or negative error code. 76 * @return ID of the newly created task or zero on error. 77 * 78 78 */ 79 int task_spawnv(task_id_t *id, const char *path, const char *const args[])79 task_id_t task_spawn(const char *path, const char *const args[], int *err) 80 80 { 81 loader_t *ldr;82 task_id_t task_id;83 int rc;84 85 81 /* Connect to a program loader. */ 86 ldr = loader_connect(); 87 if (ldr == NULL) 88 return EREFUSED; 82 loader_t *ldr = loader_connect(); 83 if (ldr == NULL) { 84 if (err != NULL) 85 *err = EREFUSED; 86 87 return 0; 88 } 89 89 90 90 /* Get task ID. */ 91 rc = loader_get_task_id(ldr, &task_id); 91 task_id_t task_id; 92 int rc = loader_get_task_id(ldr, &task_id); 92 93 if (rc != EOK) 93 94 goto error; … … 148 149 free(ldr); 149 150 150 if ( id!= NULL)151 * id = task_id;151 if (err != NULL) 152 *err = EOK; 152 153 153 return EOK;154 return task_id; 154 155 155 156 error: … … 157 158 loader_abort(ldr); 158 159 free(ldr); 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; 160 161 if (err != NULL) 162 *err = rc; 163 164 return 0; 209 165 } 210 166
Note:
See TracChangeset
for help on using the changeset viewer.