Fix problem where trying to run a program on a nonexistent volume gave an unescapable 'insert disk' dialog.

This also gives more sensible error messages when trying to execute nonexistent files.
This commit is contained in:
Stephen Heumann
2014-12-14 22:37:12 -06:00
parent 0c9ebf3839
commit d0dd867542

View File

@@ -141,18 +141,10 @@ int execve(const char *path, char *const *argv, char *const *envp)
goto error_ret;
}
/* This will close the close-on-exec fds even if the exec
* ultimately fails. This should be OK for our uses, because
* hush just prints an error message and exits in those cases. */
close_cloexec_fds();
_execve(path, args);
dealloc_for_current_process(args);
args = NULL;
/* If _execve kernel call failed, consider trying to execute
* the file as a script. */
/* Check that the file exists before we try to _execve it.
* We must do this now, because if we give _execve a path on
* a non-existent volume, it will put up an unescapable GS/OS
* dialog asking for that volume to be inserted. */
pathlen = strlen(path);
path_gs = malloc(strlen(path) + offsetof(GSString255, text) + 1);
if (path_gs == NULL) {
@@ -165,14 +157,30 @@ int execve(const char *path, char *const *argv, char *const *envp)
fileInfoRec.pathname = path_gs;
GetFileInfoGS(&fileInfoRec);
/* If it's not an EXEC file, error out. */
if (toolerror() || fileInfoRec.fileType != 0xB0 || fileInfoRec.auxType != 0x0006) {
if (toolerror()) {
errno = ENOENT;
goto error_ret;
}
free(path_gs);
path_gs = NULL;
/* This will close the close-on-exec fds even if the exec
* ultimately fails. This should be OK for our uses, because
* hush just prints an error message and exits in those cases. */
close_cloexec_fds();
_execve(path, args);
dealloc_for_current_process(args);
args = NULL;
/* If _execve kernel call failed, consider trying to execute
* the file as a script. */
if (fileInfoRec.fileType != 0xB0 || fileInfoRec.auxType != 0x0006) {
errno = EACCES;
goto error_ret;
}
free(path_gs);
path_gs = NULL;
script_fd = open(path, O_RDONLY);
if (script_fd == -1)
goto error_ret;