Rev 3386 | Rev 4327 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3386 | Rev 4153 | ||
---|---|---|---|
Line 44... | Line 44... | ||
44 | #include "util.h" |
44 | #include "util.h" |
45 | #include "exec.h" |
45 | #include "exec.h" |
46 | #include "errors.h" |
46 | #include "errors.h" |
47 | 47 | ||
48 | /* FIXME: Just have find_command() return an allocated string */ |
48 | /* FIXME: Just have find_command() return an allocated string */ |
49 | char *found; |
49 | static char *found; |
50 | 50 | ||
51 | static char *find_command(char *); |
51 | static char *find_command(char *); |
52 | static unsigned int try_access(const char *); |
52 | static int try_access(const char *); |
53 | 53 | ||
54 | /* work-around for access() */ |
54 | /* work-around for access() */ |
55 | static unsigned int try_access(const char *f) |
55 | static int try_access(const char *f) |
56 | { |
56 | { |
57 | int fd; |
57 | int fd; |
58 | 58 | ||
59 | fd = open(f, O_RDONLY); |
59 | fd = open(f, O_RDONLY); |
60 | if (fd > -1) { |
60 | if (fd > -1) { |
Line 78... | Line 78... | ||
78 | /* The user has specified a full or relative path, just give it back. */ |
78 | /* The user has specified a full or relative path, just give it back. */ |
79 | if (-1 != try_access(cmd)) { |
79 | if (-1 != try_access(cmd)) { |
80 | return (char *) cmd; |
80 | return (char *) cmd; |
81 | } |
81 | } |
82 | 82 | ||
83 | path_tok = cli_strdup(PATH); |
83 | path_tok = strdup(PATH); |
84 | 84 | ||
85 | /* Extract the PATH env to a path[] array */ |
85 | /* Extract the PATH env to a path[] array */ |
86 | path[n] = cli_strtok(path_tok, PATH_DELIM); |
86 | path[n] = strtok(path_tok, PATH_DELIM); |
87 | while (NULL != path[n]) { |
87 | while (NULL != path[n]) { |
88 | if ((strlen(path[n]) + x ) > PATH_MAX) { |
88 | if ((strlen(path[n]) + x ) > PATH_MAX) { |
89 | cli_error(CL_ENOTSUP, |
89 | cli_error(CL_ENOTSUP, |
90 | "Segment %d of path is too large, search ends at segment %d", |
90 | "Segment %d of path is too large, search ends at segment %d", |
91 | n, n-1); |
91 | n, n-1); |
92 | break; |
92 | break; |
93 | } |
93 | } |
94 | path[++n] = cli_strtok(NULL, PATH_DELIM); |
94 | path[++n] = strtok(NULL, PATH_DELIM); |
95 | } |
95 | } |
96 | 96 | ||
97 | /* We now have n places to look for the command */ |
97 | /* We now have n places to look for the command */ |
98 | for (i=0; path[i]; i++) { |
98 | for (i=0; path[i]; i++) { |
99 | memset(found, 0, sizeof(found)); |
99 | memset(found, 0, sizeof(found)); |
Line 112... | Line 112... | ||
112 | unsigned int try_exec(char *cmd, char **argv) |
112 | unsigned int try_exec(char *cmd, char **argv) |
113 | { |
113 | { |
114 | task_id_t tid; |
114 | task_id_t tid; |
115 | char *tmp; |
115 | char *tmp; |
116 | 116 | ||
117 | tmp = cli_strdup(find_command(cmd)); |
117 | tmp = strdup(find_command(cmd)); |
118 | free(found); |
118 | free(found); |
119 | 119 | ||
120 | tid = task_spawn((const char *)tmp, (const char **)argv); |
120 | tid = task_spawn((const char *)tmp, argv); |
121 | free(tmp); |
121 | free(tmp); |
122 | 122 | ||
123 | if (tid == 0) { |
123 | if (tid == 0) { |
124 | cli_error(CL_EEXEC, "Can not spawn %s", cmd); |
124 | cli_error(CL_EEXEC, "Cannot spawn `%s'.", cmd); |
125 | return 1; |
125 | return 1; |
126 | } else { |
126 | } else { |
127 | return 0; |
127 | return 0; |
128 | } |
128 | } |
129 | } |
129 | } |