1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-04-17 15:44:34 +02:00

w32: Use call back when ASFW is needed.

--

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2022-11-30 11:05:15 +09:00
parent f9af139685
commit bd062b1dbd
No known key found for this signature in database
GPG Key ID: 640114AF89DE6054
2 changed files with 11 additions and 11 deletions

View File

@ -1106,7 +1106,6 @@ spawn_detached (gnupg_process_t process,
int cr_flags; int cr_flags;
wchar_t *wcmdline = NULL; wchar_t *wcmdline = NULL;
wchar_t *wpgmname = NULL; wchar_t *wpgmname = NULL;
BOOL ask_inherit;
gpg_err_code_t ec; gpg_err_code_t ec;
int ret; int ret;
struct spawn_cb_arg sca; struct spawn_cb_arg sca;
@ -1122,12 +1121,12 @@ spawn_detached (gnupg_process_t process,
memset (&si, 0, sizeof si); memset (&si, 0, sizeof si);
sca.ask_inherit = FALSE; sca.ask_inherit = FALSE;
sca.allow_foreground_window = FALSE;
sca.plpAttributeList = &si.lpAttributeList; sca.plpAttributeList = &si.lpAttributeList;
sca.arg = spawn_cb_arg; sca.arg = spawn_cb_arg;
sca.hd[0] = INVALID_HANDLE_VALUE; sca.hd[0] = INVALID_HANDLE_VALUE;
if (spawn_cb) if (spawn_cb)
(*spawn_cb) (&sca); (*spawn_cb) (&sca);
ask_inherit = sca.ask_inherit;
/* Prepare security attributes. */ /* Prepare security attributes. */
memset (&sec_attr, 0, sizeof sec_attr ); memset (&sec_attr, 0, sizeof sec_attr );
@ -1156,7 +1155,7 @@ spawn_detached (gnupg_process_t process,
wcmdline, /* Command line arguments. */ wcmdline, /* Command line arguments. */
&sec_attr, /* Process security attributes. */ &sec_attr, /* Process security attributes. */
&sec_attr, /* Thread security attributes. */ &sec_attr, /* Thread security attributes. */
ask_inherit, /* Inherit handles. */ sca.ask_inherit, /* Inherit handles. */
cr_flags, /* Creation flags. */ cr_flags, /* Creation flags. */
NULL, /* Environment. */ NULL, /* Environment. */
NULL, /* Use current drive/directory. */ NULL, /* Use current drive/directory. */
@ -1187,6 +1186,9 @@ spawn_detached (gnupg_process_t process,
pi.hProcess, pi.hThread, pi.hProcess, pi.hThread,
(int) pi.dwProcessId, (int) pi.dwThreadId); (int) pi.dwProcessId, (int) pi.dwThreadId);
/* Note: AllowSetForegroundWindow doesn't make sense for background
process. */
CloseHandle (pi.hThread); CloseHandle (pi.hThread);
CloseHandle (pi.hProcess); CloseHandle (pi.hProcess);
@ -1217,7 +1219,6 @@ gnupg_process_spawn (const char *pgmname, const char *argv[],
wchar_t *wcmdline = NULL; wchar_t *wcmdline = NULL;
wchar_t *wpgmname = NULL; wchar_t *wpgmname = NULL;
int ret; int ret;
BOOL ask_inherit;
HANDLE hd_in[2]; HANDLE hd_in[2];
HANDLE hd_out[2]; HANDLE hd_out[2];
HANDLE hd_err[2]; HANDLE hd_err[2];
@ -1342,6 +1343,7 @@ gnupg_process_spawn (const char *pgmname, const char *argv[],
memset (&si, 0, sizeof si); memset (&si, 0, sizeof si);
sca.ask_inherit = FALSE; sca.ask_inherit = FALSE;
sca.allow_foreground_window = FALSE;
sca.plpAttributeList = &si.lpAttributeList; sca.plpAttributeList = &si.lpAttributeList;
sca.arg = spawn_cb_arg; sca.arg = spawn_cb_arg;
i = 0; i = 0;
@ -1354,7 +1356,6 @@ gnupg_process_spawn (const char *pgmname, const char *argv[],
sca.hd[i] = INVALID_HANDLE_VALUE; sca.hd[i] = INVALID_HANDLE_VALUE;
if (spawn_cb) if (spawn_cb)
(*spawn_cb) (&sca); (*spawn_cb) (&sca);
ask_inherit = sca.ask_inherit;
if (i != 0) if (i != 0)
{ {
@ -1387,7 +1388,7 @@ gnupg_process_spawn (const char *pgmname, const char *argv[],
UpdateProcThreadAttribute (si.lpAttributeList, 0, UpdateProcThreadAttribute (si.lpAttributeList, 0,
PROC_THREAD_ATTRIBUTE_HANDLE_LIST, PROC_THREAD_ATTRIBUTE_HANDLE_LIST,
sca.hd, sizeof (HANDLE) * i, NULL, NULL); sca.hd, sizeof (HANDLE) * i, NULL, NULL);
ask_inherit = TRUE; sca.ask_inherit = TRUE;
} }
/* Prepare security attributes. */ /* Prepare security attributes. */
@ -1417,7 +1418,7 @@ gnupg_process_spawn (const char *pgmname, const char *argv[],
wcmdline, /* Command line arguments. */ wcmdline, /* Command line arguments. */
&sec_attr, /* Process security attributes. */ &sec_attr, /* Process security attributes. */
&sec_attr, /* Thread security attributes. */ &sec_attr, /* Thread security attributes. */
ask_inherit, /* Inherit handles. */ sca.ask_inherit, /* Inherit handles. */
cr_flags, /* Creation flags. */ cr_flags, /* Creation flags. */
NULL, /* Environment. */ NULL, /* Environment. */
NULL, /* Use current drive/directory. */ NULL, /* Use current drive/directory. */
@ -1468,14 +1469,14 @@ gnupg_process_spawn (const char *pgmname, const char *argv[],
pi.hProcess, pi.hThread, pi.hProcess, pi.hThread,
(int) pi.dwProcessId, (int) pi.dwThreadId); (int) pi.dwProcessId, (int) pi.dwThreadId);
if ((flags & GNUPG_PROCESS_WINDOWS_ASFW)) if (sca.allow_foreground_window)
{ {
/* Fixme: For unknown reasons AllowSetForegroundWindow returns /* Fixme: For unknown reasons AllowSetForegroundWindow returns
* an invalid argument error if we pass it the correct * an invalid argument error if we pass it the correct
* processID. As a workaround we use -1 (ASFW_ANY). */ * processID. As a workaround we use -1 (ASFW_ANY). */
if (!AllowSetForegroundWindow (ASFW_ANY /*pi.dwProcessId*/)) if (!AllowSetForegroundWindow (ASFW_ANY /*pi.dwProcessId*/))
log_info ("AllowSetForegroundWindow() failed: ec=%d\n", log_info ("AllowSetForegroundWindow() failed: ec=%d\n",
(int)GetLastError ()); (int)GetLastError ());
} }
/* Process has been created suspended; resume it now. */ /* Process has been created suspended; resume it now. */

View File

@ -215,6 +215,7 @@ struct spawn_cb_arg;
#ifdef NEED_STRUCT_SPAWN_CB_ARG #ifdef NEED_STRUCT_SPAWN_CB_ARG
struct spawn_cb_arg { struct spawn_cb_arg {
BOOL ask_inherit; BOOL ask_inherit;
BOOL allow_foreground_window;
void *plpAttributeList; void *plpAttributeList;
HANDLE hd[16]; HANDLE hd[16];
void *arg; void *arg;
@ -232,8 +233,6 @@ struct spawn_cb_arg {
#define GNUPG_PROCESS_INHERIT_FILE (1 << 0) #define GNUPG_PROCESS_INHERIT_FILE (1 << 0)
#define GNUPG_PROCESS_DETACHED (1 << 1) #define GNUPG_PROCESS_DETACHED (1 << 1)
/**/
#define GNUPG_PROCESS_WINDOWS_ASFW (1 << 7)
/* Specify how to keep/connect standard fds. */ /* Specify how to keep/connect standard fds. */
#define GNUPG_PROCESS_STDIN_PIPE (1 << 8) #define GNUPG_PROCESS_STDIN_PIPE (1 << 8)