Changes in uspace/app/bdsh/exec.c [36ab7c7:c4a8e4a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/exec.c
r36ab7c7 rc4a8e4a 40 40 #include <str_error.h> 41 41 #include <errno.h> 42 #include <vfs/vfs.h> 42 43 43 44 #include "config.h" … … 51 52 static char *find_command(char *); 52 53 static int try_access(const char *); 54 55 const char *search_dir[] = { "/app", "/srv", NULL }; 53 56 54 57 /* work-around for access() */ … … 69 72 static char *find_command(char *cmd) 70 73 { 71 char *path_tok; 72 char *path[PATH_MAX]; 73 int n = 0, i = 0; 74 size_t x = str_size(cmd) + 2; 74 size_t i; 75 75 76 76 found = (char *)malloc(PATH_MAX); … … 81 81 } 82 82 83 path_tok = str_dup(PATH);84 85 /* Extract the PATH env to a path[] array */86 path[n] = strtok(path_tok, PATH_DELIM);87 while (NULL != path[n]) {88 if ((str_size(path[n]) + x ) > PATH_MAX) {89 cli_error(CL_ENOTSUP,90 "Segment %d of path is too large, search ends at segment %d",91 n, n-1);92 break;93 }94 path[++n] = strtok(NULL, PATH_DELIM);95 }96 97 83 /* We now have n places to look for the command */ 98 for (i =0; path[i]; i++) {84 for (i = 0; search_dir[i] != NULL; i++) { 99 85 memset(found, 0, sizeof(found)); 100 snprintf(found, PATH_MAX, "%s/%s", path[i], cmd);86 snprintf(found, PATH_MAX, "%s/%s", search_dir[i], cmd); 101 87 if (-1 != try_access(found)) { 102 free(path_tok);103 88 return (char *) found; 104 89 } … … 106 91 107 92 /* We didn't find it, just give it back as-is. */ 108 free(path_tok);109 93 return (char *) cmd; 110 94 } … … 116 100 char *tmp; 117 101 int rc, retval, i; 118 fdi_node_t file_nodes[3];119 fdi_node_t *file_nodes_p[4];102 int file_handles[3]; 103 int *file_handles_p[4]; 120 104 FILE *files[3]; 121 105 … … 128 112 129 113 for (i = 0; i < 3 && files[i] != NULL; i++) { 130 if (f node(files[i], &file_nodes[i]) == EOK) {131 file_ nodes_p[i] = &file_nodes[i];114 if (fhandle(files[i], &file_handles[i]) == EOK) { 115 file_handles_p[i] = &file_handles[i]; 132 116 } 133 117 else { 134 file_ nodes_p[i] = NULL;118 file_handles_p[i] = NULL; 135 119 } 136 120 } 137 file_ nodes_p[i] = NULL;121 file_handles_p[i] = NULL; 138 122 139 rc = task_spawnvf(&tid, tmp, (const char **) argv, file_ nodes_p);123 rc = task_spawnvf(&tid, tmp, (const char **) argv, file_handles_p); 140 124 free(tmp); 141 125 … … 150 134 printf("%s: Failed waiting for command (%s)\n", progname, 151 135 str_error(rc)); 136 return 1; 152 137 } else if (texit != TASK_EXIT_NORMAL) { 153 138 printf("%s: Command failed (unexpectedly terminated)\n", progname); 139 return 1; 154 140 } else if (retval != 0) { 155 141 printf("%s: Command failed (exit code %d)\n", 156 142 progname, retval); 143 return 1; 157 144 } 158 145
Note:
See TracChangeset
for help on using the changeset viewer.