mirror of
git://git.gnupg.org/gnupg.git
synced 2025-02-01 16:33:02 +01:00
common,w32: Breakaway detached childs when in job
* common/exechelp-w32.c (gnupg_spawn_process_detached): Add CREATE_BREAKAWAY_FROM_JOB creation flag if required. -- When the gpg process is assigned to a W32 "Job" the child processes are killed once the Job is finished. As we want our detached processes to linger e.g. gpg-agent the breakaway flag is required in that case. GnuPG-Bug-Id: T4333 Thanks to Jan Echternach for reporting this and providing a patch. Signed-off-by: Andre Heinecke <aheinecke@gnupg.org> (cherry picked from commit 03df28b18b92b3fd3d2ba1000903c088dc5b0fcf)
This commit is contained in:
parent
b912f07cdf
commit
f20e9a4644
@ -856,6 +856,7 @@ gnupg_spawn_process_detached (const char *pgmname, const char *argv[],
|
|||||||
int cr_flags;
|
int cr_flags;
|
||||||
char *cmdline;
|
char *cmdline;
|
||||||
gpg_err_code_t ec;
|
gpg_err_code_t ec;
|
||||||
|
BOOL in_job = FALSE;
|
||||||
|
|
||||||
/* We don't use ENVP. */
|
/* We don't use ENVP. */
|
||||||
(void)envp;
|
(void)envp;
|
||||||
@ -883,6 +884,50 @@ gnupg_spawn_process_detached (const char *pgmname, const char *argv[],
|
|||||||
| GetPriorityClass (GetCurrentProcess ())
|
| GetPriorityClass (GetCurrentProcess ())
|
||||||
| CREATE_NEW_PROCESS_GROUP
|
| CREATE_NEW_PROCESS_GROUP
|
||||||
| DETACHED_PROCESS);
|
| DETACHED_PROCESS);
|
||||||
|
|
||||||
|
/* Check if we were spawned as part of a Job.
|
||||||
|
* In a job we need to add CREATE_BREAKAWAY_FROM_JOB
|
||||||
|
* to the cr_flags, otherwise our child processes
|
||||||
|
* are killed when we terminate. */
|
||||||
|
if (!IsProcessInJob (GetCurrentProcess(), NULL, &in_job))
|
||||||
|
{
|
||||||
|
log_error ("IsProcessInJob() failed: %s\n", w32_strerror (-1));
|
||||||
|
in_job = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_job)
|
||||||
|
{
|
||||||
|
/* Only try to break away from job if it is allowed, otherwise
|
||||||
|
* CreateProcess() would fail with an "Access is denied" error. */
|
||||||
|
JOBOBJECT_EXTENDED_LIMIT_INFORMATION info;
|
||||||
|
if (!QueryInformationJobObject (NULL, JobObjectExtendedLimitInformation,
|
||||||
|
&info, sizeof info, NULL))
|
||||||
|
{
|
||||||
|
log_error ("QueryInformationJobObject() failed: %s\n",
|
||||||
|
w32_strerror (-1));
|
||||||
|
}
|
||||||
|
else if ((info.BasicLimitInformation.LimitFlags &
|
||||||
|
JOB_OBJECT_LIMIT_BREAKAWAY_OK))
|
||||||
|
{
|
||||||
|
log_debug ("Using CREATE_BREAKAWAY_FROM_JOB flag\n");
|
||||||
|
cr_flags |= CREATE_BREAKAWAY_FROM_JOB;
|
||||||
|
}
|
||||||
|
else if ((info.BasicLimitInformation.LimitFlags &
|
||||||
|
JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK))
|
||||||
|
{
|
||||||
|
/* The child process should automatically detach from the job. */
|
||||||
|
log_debug ("Not using CREATE_BREAKAWAY_FROM_JOB flag; "
|
||||||
|
"JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK is set\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* It seems that the child process must remain in the job.
|
||||||
|
* This is not necessarily an error, although it can cause premature
|
||||||
|
* termination of the child process when the job is closed. */
|
||||||
|
log_debug ("Not using CREATE_BREAKAWAY_FROM_JOB flag\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* log_debug ("CreateProcess(detached), path='%s' cmdline='%s'\n", */
|
/* log_debug ("CreateProcess(detached), path='%s' cmdline='%s'\n", */
|
||||||
/* pgmname, cmdline); */
|
/* pgmname, cmdline); */
|
||||||
if (!CreateProcess (pgmname, /* Program to start. */
|
if (!CreateProcess (pgmname, /* Program to start. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user