diff options
author | Ron Yorston <rmy@pobox.com> | 2018-12-07 09:37:27 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-12-07 09:37:27 +0000 |
commit | 1fe3f5449a4a3ea6fc8460df40d95d118ed5d4ee (patch) | |
tree | 094cdcd04eb2b9f7ff03b7a76511006b9b746cc1 | |
parent | 9906faf2dff6fd9033cb711619528501cae11721 (diff) | |
download | busybox-w32-1fe3f5449a4a3ea6fc8460df40d95d118ed5d4ee.tar.gz busybox-w32-1fe3f5449a4a3ea6fc8460df40d95d118ed5d4ee.tar.bz2 busybox-w32-1fe3f5449a4a3ea6fc8460df40d95d118ed5d4ee.zip |
win32: improve execution of batch files
It appears that when a batch file is executed the first argument
must contain backslashes if it's a relative path. Absolute paths
work either way. In both cases the extension is optional.
This allows for a considerable simplification of the special case
in spawnveq.
-rw-r--r-- | win32/process.c | 34 |
1 files changed, 8 insertions, 26 deletions
diff --git a/win32/process.c b/win32/process.c index b7f02e431..fda38318a 100644 --- a/win32/process.c +++ b/win32/process.c | |||
@@ -204,7 +204,7 @@ static intptr_t | |||
204 | spawnveq(int mode, const char *path, char *const *argv, char *const *env) | 204 | spawnveq(int mode, const char *path, char *const *argv, char *const *env) |
205 | { | 205 | { |
206 | char **new_argv; | 206 | char **new_argv; |
207 | char *new_path = NULL; | 207 | char *s, *new_path = NULL; |
208 | int i, argc; | 208 | int i, argc; |
209 | intptr_t ret; | 209 | intptr_t ret; |
210 | struct stat st; | 210 | struct stat st; |
@@ -229,31 +229,13 @@ spawnveq(int mode, const char *path, char *const *argv, char *const *env) | |||
229 | new_argv[i] = quote_arg(argv[i]); | 229 | new_argv[i] = quote_arg(argv[i]); |
230 | new_argv[argc] = NULL; | 230 | new_argv[argc] = NULL; |
231 | 231 | ||
232 | /* | 232 | /* Special case: spawnve won't execute a batch file if the first |
233 | * Special case: spawnve won't execute a batch file when the path | 233 | * argument is a relative path containing forward slashes. Absolute |
234 | * starts with a '.' and contains forward slashes. | 234 | * paths are fine but there's no harm in converting them too. */ |
235 | */ | 235 | if (has_bat_suffix(path)) { |
236 | if (new_argv[0][0] == '.') { | 236 | for (s=new_argv[0]; *s; ++s) { |
237 | char *s, *p; | 237 | if (*s == '/') |
238 | 238 | *s = '\\'; | |
239 | if (has_bat_suffix(new_argv[0])) { | ||
240 | p = strdup(new_argv[0]); | ||
241 | } | ||
242 | else { | ||
243 | p = alloc_win32_extension(new_argv[0]); | ||
244 | } | ||
245 | |||
246 | if (p != NULL && has_bat_suffix(p)) { | ||
247 | for (s=p; *s; ++s) { | ||
248 | if (*s == '/') | ||
249 | *s = '\\'; | ||
250 | } | ||
251 | if (new_argv[0] != argv[0]) | ||
252 | free(new_argv[0]); | ||
253 | new_argv[0] = p; | ||
254 | } | ||
255 | else { | ||
256 | free(p); | ||
257 | } | 239 | } |
258 | } | 240 | } |
259 | 241 | ||