Changes in / [0b81cad0:0578271] in mainline
- Location:
- uspace
- Files:
-
- 4 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/exec.c
r0b81cad0 r0578271 41 41 #include <fcntl.h> 42 42 #include <str_error.h> 43 #include <errno.h>44 43 45 44 #include "config.h" … … 117 116 task_exit_t texit; 118 117 char *tmp; 119 int r c, retval;118 int retval; 120 119 121 120 tmp = str_dup(find_command(cmd)); 122 121 free(found); 123 122 124 rc = task_spawnv(&tid, tmp, (const char **) argv);123 tid = task_spawn(tmp, (const char **) argv, &retval); 125 124 free(tmp); 126 125 127 if ( rc != 0) {126 if (tid == 0) { 128 127 cli_error(CL_EEXEC, "%s: Cannot spawn `%s' (%s)", progname, cmd, 129 str_error(r c));128 str_error(retval)); 130 129 return 1; 131 130 } 132 131 133 rc = task_wait(tid, &texit, &retval); 134 if (rc != EOK) { 135 printf("%s: Failed waiting for command (%s)\n", str_error(rc)); 136 } else if (texit != TASK_EXIT_NORMAL) { 132 task_wait(tid, &texit, &retval); 133 if (texit != TASK_EXIT_NORMAL) { 137 134 printf("%s: Command failed (unexpectedly terminated)\n", progname); 138 135 } else if (retval != 0) { 139 printf("%s: Command failed ( exit code %d)\n",140 progname, retval);136 printf("%s: Command failed (%s)\n", 137 progname, str_error(retval)); 141 138 } 142 139 -
uspace/app/getterm/getterm.c
r0b81cad0 r0578271 41 41 #include <task.h> 42 42 #include <str_error.h> 43 #include <errno.h>44 43 #include "version.h" 45 44 … … 75 74 static task_id_t spawn(const char *fname) 76 75 { 77 task_id_t id; 78 int rc; 76 const char *args[2]; 79 77 80 rc = task_spawnl(&id, fname, fname, NULL); 81 if (rc != EOK) { 78 args[0] = fname; 79 args[1] = NULL; 80 81 int err; 82 task_id_t id = task_spawn(fname, args, &err); 83 84 if (id == 0) 82 85 printf("%s: Error spawning %s (%s)\n", APP_NAME, fname, 83 str_error(rc)); 84 return 0; 85 } 86 str_error(err)); 86 87 87 88 return id; -
uspace/app/init/init.c
r0b81cad0 r0578271 124 124 static void spawn(const char *fname) 125 125 { 126 int rc;126 const char *argv[2]; 127 127 struct stat s; 128 128 … … 131 131 132 132 printf("%s: Spawning %s\n", NAME, fname); 133 rc = task_spawnl(NULL, fname, fname, NULL); 134 if (rc != EOK) { 133 134 argv[0] = fname; 135 argv[1] = NULL; 136 137 int err; 138 if (!task_spawn(fname, argv, &err)) 135 139 printf("%s: Error spawning %s (%s)\n", NAME, fname, 136 str_error(rc)); 137 } 140 str_error(err)); 138 141 } 139 142 140 143 static void srv_start(const char *fname) 141 144 { 145 const char *argv[2]; 142 146 task_id_t id; 143 147 task_exit_t texit; … … 149 153 150 154 printf("%s: Starting %s\n", NAME, fname); 151 rc = task_spawnl(&id, fname, fname, NULL); 155 156 argv[0] = fname; 157 argv[1] = NULL; 158 159 id = task_spawn(fname, argv, &retval); 152 160 if (!id) { 153 161 printf("%s: Error spawning %s (%s)\n", NAME, fname, 154 str_error(r c));162 str_error(retval)); 155 163 return; 156 164 } … … 159 167 if (rc != EOK) { 160 168 printf("%s: Error waiting for %s (%s(\n", NAME, fname, 161 str_error(r c));169 str_error(retval)); 162 170 return; 163 171 } 164 172 165 if (texit != TASK_EXIT_NORMAL) { 166 printf("%s: Server %s failed to start (unexpectedly " 167 "terminated)\n", NAME, fname); 168 return; 169 } 170 171 if (retval != 0) { 172 printf("%s: Server %s failed to start (exit code %d)\n", NAME, 173 fname, retval); 173 if ((texit != TASK_EXIT_NORMAL) || (retval != 0)) { 174 printf("%s: Server %s failed to start (%s)\n", NAME, 175 fname, str_error(retval)); 174 176 } 175 177 } … … 177 179 static void console(const char *dev) 178 180 { 181 const char *argv[3]; 179 182 char hid_in[DEVMAP_NAME_MAXLEN]; 180 183 int rc; … … 187 190 dev_handle_t handle; 188 191 rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING); 189 if (rc != EOK) { 192 193 if (rc == EOK) { 194 argv[0] = SRV_CONSOLE; 195 argv[1] = hid_in; 196 argv[2] = NULL; 197 198 if (!task_spawn(SRV_CONSOLE, argv, &rc)) 199 printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE, 200 hid_in, str_error(rc)); 201 } else 190 202 printf("%s: Error waiting on %s (%s)\n", NAME, hid_in, 191 203 str_error(rc)); 192 return;193 }194 195 rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, hid_in, NULL);196 if (rc != EOK) {197 printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE,198 hid_in, str_error(rc));199 }200 204 } 201 205 202 206 static void getterm(const char *dev, const char *app) 203 207 { 208 const char *argv[4]; 204 209 char term[DEVMAP_NAME_MAXLEN]; 205 210 int rc; … … 212 217 dev_handle_t handle; 213 218 rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING); 214 if (rc != EOK) { 219 220 if (rc == EOK) { 221 argv[0] = APP_GETTERM; 222 argv[1] = term; 223 argv[2] = app; 224 argv[3] = NULL; 225 226 if (!task_spawn(APP_GETTERM, argv, &rc)) 227 printf("%s: Error spawning %s %s %s (%s)\n", NAME, APP_GETTERM, 228 term, app, str_error(rc)); 229 } else 215 230 printf("%s: Error waiting on %s (%s)\n", NAME, term, 216 231 str_error(rc)); 217 return;218 }219 220 rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, term, app, NULL);221 if (rc != EOK) {222 printf("%s: Error spawning %s %s %s (%s)\n", NAME,223 APP_GETTERM, term, app, str_error(rc));224 }225 232 } 226 233 -
uspace/app/netstart/netstart.c
r0b81cad0 r0578271 57 57 static bool spawn(const char *desc, const char *path) 58 58 { 59 int rc;60 61 59 printf("%s: Spawning %s (%s)\n", NAME, desc, path); 62 rc = task_spawnl(NULL, path, path, NULL); 63 if (rc != EOK) { 60 61 const char *argv[2]; 62 63 argv[0] = path; 64 argv[1] = NULL; 65 66 int err; 67 if (task_spawn(path, argv, &err) == 0) { 64 68 fprintf(stderr, "%s: Error spawning %s (%s)\n", NAME, path, 65 str_error( rc));69 str_error(err)); 66 70 return false; 67 71 } -
uspace/app/redir/redir.c
r0b81cad0 r0578271 43 43 #include <task.h> 44 44 #include <str_error.h> 45 #include <errno.h>46 45 47 46 #define NAME "redir" … … 77 76 static task_id_t spawn(int argc, char *argv[]) 78 77 { 79 const char **args; 80 task_id_t id; 81 int rc; 82 83 args = (const char **) calloc(argc + 1, sizeof(char *)); 78 const char **args = (const char **) calloc(argc + 1, sizeof(char *)); 84 79 if (!args) { 85 80 printf("No memory available\n"); … … 93 88 args[argc] = NULL; 94 89 95 rc = task_spawnv(&id, argv[0], args); 90 int err; 91 task_id_t id = task_spawn(argv[0], args, &err); 96 92 97 93 free(args); 98 94 99 if ( rc != EOK) {95 if (id == 0) 100 96 printf("%s: Error spawning %s (%s)\n", NAME, argv[0], 101 str_error(rc)); 102 } 97 str_error(err)); 103 98 104 99 return id; -
uspace/app/sbi/src/os/helenos.c
r0b81cad0 r0578271 249 249 task_id_t tid; 250 250 task_exit_t texit; 251 int r c, retval;252 253 rc = task_spawnv(&tid, cmd[0], (char const * const *) cmd);254 if ( rc != EOK) {251 int retval; 252 253 tid = task_spawn(cmd[0], (char const * const *) cmd, &retval); 254 if (tid == 0) { 255 255 printf("Error: Failed spawning '%s' (%s).\n", cmd[0], 256 str_error(r c));256 str_error(retval)); 257 257 exit(1); 258 258 } 259 259 260 260 /* XXX Handle exit status and return value. */ 261 rc = task_wait(tid, &texit, &retval); 262 (void) rc; 261 task_wait(tid, &texit, &retval); 263 262 264 263 return EOK; -
uspace/lib/c/generic/task.c
r0b81cad0 r0578271 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 -
uspace/lib/c/include/task.h
r0b81cad0 r0578271 48 48 extern int task_set_name(const char *); 49 49 extern task_id_t task_spawn(const char *, const char *const[], int *); 50 extern int task_spawnv(task_id_t *, const char *path, const char *const []);51 extern int task_spawnl(task_id_t *, const char *path, ...);52 53 50 extern int task_wait(task_id_t id, task_exit_t *, int *); 54 51 extern int task_retval(int); -
uspace/lib/net/adt/module_map.c
r0b81cad0 r0578271 132 132 task_id_t spawn(const char *fname) 133 133 { 134 task_id_t id;135 int rc;134 const char *argv[2]; 135 task_id_t res; 136 136 137 rc = task_spawnl(&id, fname, fname, NULL);138 if (rc != EOK)139 return 0;137 argv[0] = fname; 138 argv[1] = NULL; 139 res = task_spawn(fname, argv, NULL); 140 140 141 return id;141 return res; 142 142 } 143 143 -
uspace/srv/devman/devman.c
r0b81cad0 r0578271 37 37 #include <ipc/devman.h> 38 38 #include <devmap.h> 39 #include <str_error.h>40 39 41 40 #include "devman.h" … … 447 446 bool start_driver(driver_t *drv) 448 447 { 449 int rc;450 451 448 printf(NAME ": start_driver '%s'\n", drv->name); 452 449 453 rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL); 454 if (rc != EOK) { 455 printf(NAME ": error spawning %s (%s)\n", 456 drv->name, str_error(rc)); 450 const char *argv[2]; 451 452 argv[0] = drv->name; 453 argv[1] = NULL; 454 455 int err; 456 if (task_spawn(drv->binary_path, argv, &err) == 0) { 457 printf(NAME ": error spawning %s, errno = %d\n", 458 drv->name, err); 457 459 return false; 458 460 } -
uspace/srv/taskmon/taskmon.c
r0b81cad0 r0578271 50 50 static void fault_event(ipc_callid_t callid, ipc_call_t *call) 51 51 { 52 const char *argv[6]; 52 53 const char *fname; 54 char *dump_fname; 53 55 char *s_taskid; 54 int rc;56 const char **s; 55 57 56 58 task_id_t taskid; … … 65 67 } 66 68 67 printf(NAME ": Task %" PRIuTASKID " fault in thread %p.\n", taskid, thread);68 69 fname = "/app/taskdump";70 71 #ifdef CONFIG_WRITE_CORE_FILES72 char *dump_fname;73 74 69 if (asprintf(&dump_fname, "/data/core%" PRIuTASKID, taskid) < 0) { 75 70 printf("Memory allocation failed.\n"); … … 77 72 } 78 73 79 printf(NAME ": Executing %s -c %s -t %s\n", dump_fname, s_taskid); 80 rc = task_spawnl(NULL, fname, fname, "-c", dump_fname, "-t", s_taskid, 81 NULL); 74 printf(NAME ": Task %" PRIuTASKID " fault in thread %p.\n", taskid, thread); 75 76 #ifdef CONFIG_WRITE_CORE_FILES 77 argv[0] = "/app/taskdump"; 78 argv[1] = "-c"; 79 argv[2] = dump_fname; 80 argv[3] = "-t"; 81 argv[4] = s_taskid; 82 argv[5] = NULL; 82 83 #else 83 printf(NAME ": Executing %s -t %s\n", s_taskid); 84 rc = task_spawnl(NULL, fname, fname, "-t", s_taskid, NULL); 84 argv[0] = "/app/taskdump"; 85 argv[1] = "-t"; 86 argv[2] = s_taskid; 87 argv[3] = NULL; 85 88 #endif 86 if (rc != EOK) { 89 fname = argv[0]; 90 91 printf(NAME ": Executing"); 92 93 s = argv; 94 while (*s != NULL) { 95 printf(" %s", *s); 96 ++s; 97 } 98 putchar('\n'); 99 100 int err; 101 if (!task_spawn(fname, argv, &err)) 87 102 printf("%s: Error spawning %s (%s).\n", NAME, fname, 88 str_error(rc)); 89 } 103 str_error(err)); 90 104 } 91 105
Note:
See TracChangeset
for help on using the changeset viewer.