Changes in uspace/app/bdsh/exec.c [aa8053f1:36ab7c7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/exec.c
raa8053f1 r36ab7c7 52 52 static int try_access(const char *); 53 53 54 const char *search_dir[] = { "/app", "/srv", NULL };55 56 54 /* work-around for access() */ 57 55 static int try_access(const char *f) … … 71 69 static char *find_command(char *cmd) 72 70 { 73 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; 74 75 75 76 found = (char *)malloc(PATH_MAX); … … 80 81 } 81 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 82 97 /* We now have n places to look for the command */ 83 for (i = 0; search_dir[i] != NULL; i++) {98 for (i=0; path[i]; i++) { 84 99 memset(found, 0, sizeof(found)); 85 snprintf(found, PATH_MAX, "%s/%s", search_dir[i], cmd);100 snprintf(found, PATH_MAX, "%s/%s", path[i], cmd); 86 101 if (-1 != try_access(found)) { 102 free(path_tok); 87 103 return (char *) found; 88 104 } … … 90 106 91 107 /* We didn't find it, just give it back as-is. */ 108 free(path_tok); 92 109 return (char *) cmd; 93 110 }
Note:
See TracChangeset
for help on using the changeset viewer.