Changeset aeeaf0f in mainline
- Timestamp:
- 2019-05-19T07:28:42Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a78cdcd
- Parents:
- 6aeb60f (diff), 587867a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Jakub Jermář <jakub@…> (2019-05-19 07:28:42)
- git-committer:
- GitHub <noreply@…> (2019-05-19 07:28:42)
- Location:
- uspace/app/bdsh
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/compl.c
r6aeb60f raeeaf0f 40 40 #include "exec.h" 41 41 #include "tok.h" 42 #include "util.h" 42 43 43 44 static errno_t compl_init(wchar_t *text, size_t pos, size_t *cstart, void **state); … … 209 210 } 210 211 *cstart += rpath_sep + 1 - prefix; 211 free(prefix);212 prefix = NULL;213 212 214 213 cs->path_list = malloc(sizeof(char *) * 2); … … 217 216 goto error; 218 217 } 219 cs->path_list[0] = dirname; 218 219 if (!is_path(prefix) && cs->is_command) { 220 cs->path_list[0] = malloc(sizeof(char) * PATH_MAX); 221 if (cs->path_list[0] == NULL) { 222 retval = ENOMEM; 223 goto error; 224 } 225 226 int ret = snprintf(cs->path_list[0], PATH_MAX, "%s/%s", search_dir[0], dirname); 227 if (ret < 0 || ret >= PATH_MAX) { 228 retval = ENOMEM; 229 goto error; 230 } 231 } else { 232 cs->path_list[0] = dirname; 233 } 234 235 free(prefix); 220 236 cs->path_list[1] = NULL; 221 237 /* -
uspace/app/bdsh/exec.c
r6aeb60f raeeaf0f 47 47 #include "errors.h" 48 48 49 /* FIXME: Just have find_command() return an allocated string */ 50 static char *found; 51 52 static char *find_command(char *); 49 static errno_t find_command(char *, char **); 53 50 static int try_access(const char *); 54 51 … … 68 65 } 69 66 70 /** Returns the full path of "cmd" if cmd is found67 /** Returns EOK if no internal failure or else ENOMEM 71 68 * 72 * else just hand back cmd as it was presented 69 * When the parameter `cmd` can be found then the absolute path will be set in `found`. 70 * Or else `found` will be NULL. 71 * `found` will be newly allocated and must be freed by the caller 73 72 */ 74 static char *find_command(char *cmd)73 static errno_t find_command(char *cmd, char **found) 75 74 { 76 size_t i; 75 /* The user has specified a full or relative path, just give it back. */ 76 if (is_path(cmd)) { 77 if (-1 != try_access(cmd)) { 78 *found = str_dup(cmd); 79 return EOK; 80 } 77 81 78 found = (char *)malloc(PATH_MAX); 82 *found = NULL; 83 return EOK; 84 } 79 85 80 /* The user has specified a full or relative path, just give it back. */81 if ( -1 != try_access(cmd)) {82 return (char *) cmd;86 *found = (char *)malloc(PATH_MAX); 87 if (*found == NULL) { 88 return ENOMEM; 83 89 } 84 90 85 91 /* We now have n places to look for the command */ 92 size_t i; 93 size_t cmd_length = str_length(cmd); 86 94 for (i = 0; search_dir[i] != NULL; i++) { 87 memset(found, 0, PATH_MAX); 88 snprintf(found, PATH_MAX, "%s/%s", search_dir[i], cmd); 89 if (-1 != try_access(found)) { 90 return (char *) found; 95 if (str_length(search_dir[i]) + cmd_length + 2 > PATH_MAX) { 96 free(*found); 97 return ENOMEM; 98 } 99 100 memset(*found, 0, PATH_MAX); 101 snprintf(*found, PATH_MAX, "%s/%s", search_dir[i], cmd); 102 if (-1 != try_access(*found)) { 103 return EOK; 91 104 } 92 105 } 106 free(*found); 107 *found = NULL; 93 108 94 /* We didn't find it, just give it back as-is.*/95 return (char *) cmd;109 /* We didn't find it, return NULL */ 110 return EOK; 96 111 } 97 112 … … 107 122 FILE *files[3]; 108 123 109 tmp = str_dup(find_command(cmd)); 110 free(found); 124 rc = find_command(cmd, &tmp); 125 if (rc != EOK) { 126 cli_error(CL_ENOMEM, "%s: failure executing find_command()", progname); 127 return 1; 128 } 129 130 if (tmp == NULL) { 131 cli_error(CL_EEXEC, "%s: Command not found '%s'", progname, cmd); 132 return 1; 133 } 111 134 112 135 files[0] = io->stdin; -
uspace/app/bdsh/util.c
r6aeb60f raeeaf0f 74 74 return 0; 75 75 } 76 77 /* 78 * Returns true if the string is a relative or an absolute path 79 */ 80 bool is_path(const char *cmd) 81 { 82 83 bool ret = str_lcmp(cmd, "/", 1) == 0; 84 ret = ret || str_lcmp(cmd, "./", 2) == 0; 85 ret = ret || str_lcmp(cmd, "../", 3) == 0; 86 87 return ret; 88 } -
uspace/app/bdsh/util.h
r6aeb60f raeeaf0f 31 31 32 32 #include "scli.h" 33 #include <stdbool.h> 33 34 34 35 /* Utility functions */ 35 36 extern unsigned int cli_count_args(char **); 36 37 extern unsigned int cli_set_prompt(cliuser_t *usr); 38 extern bool is_path(const char *cmd); 37 39 38 40 #endif
Note:
See TracChangeset
for help on using the changeset viewer.