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