Branch: refs/heads/master Author: Dimitar Zhekov dimitar.zhekov@gmail.com Committer: Dimitar Zhekov dimitar.zhekov@gmail.com Date: Tue, 20 Oct 2015 17:22:51 UTC Commit: 5aa0b02f00e84c6412be8632432726c5894e1ff3 https://github.com/geany/geany/commit/5aa0b02f00e84c6412be8632432726c5894e1f...
Log Message: ----------- Sync spawn glib/unix and Windows messages
In particular, the exec() and CreateProcess() errors are reported directly, but failures in other any functions, which are extremely rare, include some descriptive text, such as "Failed to set pipe handle to inheritable (Access denied)". The example is artificial.
Modified Paths: -------------- src/spawn.c
Modified: src/spawn.c 32 lines changed, 21 insertions(+), 11 deletions(-) =================================================================== @@ -334,7 +334,7 @@ static gchar *spawn_create_process_with_pipes(char *command_line, const char *wo if (!CreatePipe(&hpipe[pindex[i][0]], &hpipe[pindex[i][1]], NULL, 0)) { hpipe[pindex[i][0]] = hpipe[pindex[i][1]] = NULL; - failed = "CreatePipe"; + failed = "create pipe"; goto leave; }
@@ -344,21 +344,21 @@ static gchar *spawn_create_process_with_pipes(char *command_line, const char *wo
if ((*fd[i] = _open_osfhandle((intptr_t) hpipe[i], mode[i])) == -1) { - failed = "_open_osfhandle"; + failed = "convert pipe handle to file descriptor"; message = g_strdup(g_strerror(errno)); goto leave; } } else if (!CloseHandle(hpipe[i])) { - failed = "CloseHandle"; + failed = "close pipe"; goto leave; }
if (!SetHandleInformation(hpipe[i + 3], HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) { - failed = "SetHandleInformation"; + failed = "set pipe handle to inheritable"; goto leave; } } @@ -371,7 +371,7 @@ static gchar *spawn_create_process_with_pipes(char *command_line, const char *wo if (!CreateProcess(NULL, command_line, NULL, NULL, TRUE, pipe_io ? CREATE_NO_WINDOW : 0, environment, working_directory, &startup, &process)) { - failed = "CreateProcess"; + failed = ""; /* report the message only */ /* further errors will not be reported */ } else @@ -389,14 +389,24 @@ static gchar *spawn_create_process_with_pipes(char *command_line, const char *wo if (failed) { if (!message) + { + size_t len; + message = g_win32_error_message(GetLastError()); + len = strlen(message);
- #ifdef SPAWN_TEST - failure = g_strdup_printf("%s() failed: %s", failed, message); - g_free(message); - #else - failure = message; - #endif + /* unlike g_strerror(), the g_win32_error messages may include a final '.' */ + if (len > 0 && message[len - 1] == '.') + message[len - 1] = '\0'; + } + + if (*failed == '\0') + failure = message; + else + { + failure = g_strdup_printf("Failed to %s (%s)", failed, message); + g_free(message); + } }
if (pipe_io)
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).