1 | /* $Id: winchildren.h 3200 2018-03-28 20:32:11Z bird $ */
|
---|
2 | /** @file
|
---|
3 | * Child process creation and management for kmk.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (c) 2018 knut st. osmundsen <[email protected]>
|
---|
8 | *
|
---|
9 | * This file is part of kBuild.
|
---|
10 | *
|
---|
11 | * kBuild is free software; you can redistribute it and/or modify
|
---|
12 | * it under the terms of the GNU General Public License as published by
|
---|
13 | * the Free Software Foundation; either version 3 of the License, or
|
---|
14 | * (at your option) any later version.
|
---|
15 | *
|
---|
16 | * kBuild is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | * GNU General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with kBuild. If not, see <http://www.gnu.org/licenses/>
|
---|
23 | *
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef INCLUDED_WINCHILDREN_H
|
---|
27 | #define INCLUDED_WINCHILDREN_H
|
---|
28 |
|
---|
29 | #ifdef DECLARE_HANDLE
|
---|
30 | /**
|
---|
31 | * A childcare worker pipe.
|
---|
32 | */
|
---|
33 | typedef struct WINCCWPIPE
|
---|
34 | {
|
---|
35 | /** My end of the pipe. */
|
---|
36 | HANDLE hPipeMine;
|
---|
37 | /** The child end of the pipe. */
|
---|
38 | HANDLE hPipeChild;
|
---|
39 | /** The event for asynchronous reading. */
|
---|
40 | HANDLE hEvent;
|
---|
41 | /** Which pipe this is (1 == stdout, 2 == stderr). */
|
---|
42 | unsigned char iWhich;
|
---|
43 | /** Set if we've got a read pending already. */
|
---|
44 | BOOL fReadPending;
|
---|
45 | /** Indicator that we've written out something. This is cleared before
|
---|
46 | * we start catching output from a new child and use in the CL.exe
|
---|
47 | * supression heuristics. */
|
---|
48 | BOOL fHaveWrittenOut;
|
---|
49 | /** Number of bytes at the start of the buffer that we've already
|
---|
50 | * written out. We try write out whole lines. */
|
---|
51 | DWORD cbWritten;
|
---|
52 | /** The buffer offset of the read currently pending. */
|
---|
53 | DWORD offPendingRead;
|
---|
54 | /** Read buffer size. */
|
---|
55 | DWORD cbBuffer;
|
---|
56 | /** The read buffer allocation. */
|
---|
57 | unsigned char *pbBuffer;
|
---|
58 | /** Overlapped I/O structure. */
|
---|
59 | OVERLAPPED Overlapped;
|
---|
60 | } WINCCWPIPE;
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | typedef struct WINCCWPIPE *PWINCCWPIPE;
|
---|
64 |
|
---|
65 | void MkWinChildInit(unsigned int cJobSlot);
|
---|
66 | void MkWinChildReExecMake(char **papszArgs, char **papszEnv);
|
---|
67 | intptr_t MkWinChildGetCompleteEventHandle(void);
|
---|
68 | int MkWinChildCreate(char **papszArgs, char **papszEnv, const char *pszShell, struct child *pMkChild, pid_t *pPid);
|
---|
69 | int MkWinChildCreateWithStdOutPipe(char **papszArgs, char **papszEnv, int fdErr, pid_t *pPid, int *pfdReadPipe);
|
---|
70 | #ifdef KMK
|
---|
71 | struct KMKBUILTINENTRY;
|
---|
72 | int MkWinChildCreateBuiltIn(struct KMKBUILTINENTRY const *pBuiltIn, int cArgs, char **papszArgs,
|
---|
73 | char **papszEnv, struct child *pMkChild, pid_t *pPid);
|
---|
74 | int MkWinChildCreateAppend(const char *pszFilename, char **ppszAppend, size_t cbAppend, int fTruncate,
|
---|
75 | struct child *pMkChild, pid_t *pPid);
|
---|
76 |
|
---|
77 | int MkWinChildCreateSubmit(intptr_t hEvent, void *pvSubmitWorker, PWINCCWPIPE pStdOut, PWINCCWPIPE pStdErr,
|
---|
78 | struct child *pMkChild, pid_t *pPid);
|
---|
79 | PWINCCWPIPE MkWinChildcareCreateWorkerPipe(unsigned iWhich, unsigned int idxWorker);
|
---|
80 | void MkWinChildcareWorkerDrainPipes(struct WINCHILD *pChild, PWINCCWPIPE pStdOut, PWINCCWPIPE pStdErr);
|
---|
81 | void MkWinChildcareDeleteWorkerPipe(PWINCCWPIPE pPipe);
|
---|
82 |
|
---|
83 | int MkWinChildCreateRedirect(intptr_t hProcess, pid_t *pPid);
|
---|
84 | # ifdef DECLARE_HANDLE
|
---|
85 | int MkWinChildBuiltInExecChild(void *pvWorker, const char *pszExecutable, char **papszArgs, BOOL fQuotedArgv,
|
---|
86 | char **papszEnvVars, const char *pszCwd, BOOL pafReplace[3], HANDLE pahReplace[3]);
|
---|
87 | # endif
|
---|
88 | #endif
|
---|
89 | int MkWinChildKill(pid_t pid, int iSignal, struct child *pMkChild);
|
---|
90 | int MkWinChildWait(int fBlock, pid_t *pPid, int *piExitCode, int *piSignal, int *pfCoreDumped, struct child **ppMkChild);
|
---|
91 | void MkWinChildExclusiveAcquire(void);
|
---|
92 | void MkWinChildExclusiveRelease(void);
|
---|
93 |
|
---|
94 | #undef CLOSE_ON_EXEC
|
---|
95 | #define CLOSE_ON_EXEC(a_fd) MkWinChildUnrelatedCloseOnExec(a_fd)
|
---|
96 | int MkWinChildUnrelatedCloseOnExec(int fd);
|
---|
97 |
|
---|
98 |
|
---|
99 | #endif
|
---|
100 |
|
---|