1 #include "rtems_shell_local_config.h"
8 #include <rtems/error.h>
9 #include <rtems/monitor.h>
10 #include <rtems/shell.h>
12 #include <orte_rtems_shell.h>
14 typedef struct orte_spawn_args {
20 orte_spawn_task_func(void *arg_pack)
22 rtems_shell_cmd_t *shell_cmd;
24 orte_spawn_args_t *spawn_args = (orte_spawn_args_t *)arg_pack;
25 int argc = spawn_args->argc;
26 char **argv = &(spawn_args->argv[0]);
32 shell_cmd = rtems_shell_lookup_cmd(argv[0]);
33 if (argv[1] == NULL) {
35 } else if (shell_cmd == NULL) {
36 errorlevel = rtems_shell_script_file(argc, &argv[0]);
38 errorlevel = shell_cmd->command(argc, &argv[0]);
43 return (void *)errorlevel;
47 orte_spawn_main(int argc, char **argv)
49 orte_spawn_args_t *spawn_args;
60 sparg_str_offs = sizeof(orte_spawn_args_t) + (argc + 1) *sizeof(char *);
61 sparg_size = sparg_str_offs;
63 for (i = 0; i < argc; i++)
64 sparg_size += strlen(argv[i]) + 1;
66 spawn_args = malloc(sparg_size);
67 if (spawn_args == NULL)
70 spawn_args->argc = argc;
72 p = (char *)spawn_args + sparg_str_offs;
73 for (i = 0; i < argc; i++) {
74 int len = strlen(argv[i]);
75 spawn_args->argv[i] = p;
76 memcpy(p, argv[i], len);
80 spawn_args->argv[argc] = NULL;
82 status = pthread_create(&task_id, NULL, orte_spawn_task_func, spawn_args);
84 pthread_detach(task_id);
86 return status ? 1 : 0;