Coverage Report

Created: 2025-06-13 06:30

/src/wxwidgets/include/wx/unix/private/execute.h
Line
Count
Source (jump to first uncovered line)
1
/////////////////////////////////////////////////////////////////////////////
2
// Name:        wx/unix/private/execute.h
3
// Purpose:     private details of wxExecute() implementation
4
// Author:      Vadim Zeitlin
5
// Copyright:   (c) 1998 Robert Roebling, Julian Smart, Vadim Zeitlin
6
//              (c) 2013 Vadim Zeitlin
7
// Licence:     wxWindows licence
8
/////////////////////////////////////////////////////////////////////////////
9
10
#ifndef _WX_UNIX_EXECUTE_H
11
#define _WX_UNIX_EXECUTE_H
12
13
#include "wx/app.h"
14
#include "wx/process.h"
15
16
#if wxUSE_STREAMS
17
    #include "wx/unix/pipe.h"
18
    #include "wx/private/streamtempinput.h"
19
#endif
20
21
#include <unordered_map>
22
23
class wxEventLoopBase;
24
25
// Information associated with a running child process.
26
class wxExecuteData
27
{
28
public:
29
    wxExecuteData()
30
0
    {
31
0
        m_flags =
32
0
        m_pid = 0;
33
0
        m_exitcode = -1;
34
35
0
        m_process = nullptr;
36
37
0
        m_syncEventLoop = nullptr;
38
39
0
#if wxUSE_STREAMS
40
0
        m_fdOut =
41
0
        m_fdErr = wxPipe::INVALID_FD;
42
0
#endif // wxUSE_STREAMS
43
0
    }
44
45
    // This must be called in the parent process as soon as fork() returns to
46
    // update us with the effective child PID. It also ensures that we handle
47
    // SIGCHLD to be able to detect when this PID exits, so wxTheApp must be
48
    // available.
49
    void OnStart(int pid);
50
51
    // Called when the child process exits.
52
    void OnExit(int exitcode);
53
54
    // Return true if we should (or already did) redirect the child IO.
55
0
    bool IsRedirected() const { return m_process && m_process->IsRedirected(); }
56
57
58
    // wxExecute() flags
59
    int m_flags;
60
61
    // the pid of the child process
62
    int m_pid;
63
64
    // The exit code of the process, set once the child terminates.
65
    int m_exitcode;
66
67
    // the associated process object or nullptr
68
    wxProcess *m_process;
69
70
    // Local event loop used to wait for the child process termination in
71
    // synchronous execution case. We can't create it ourselves as its exact
72
    // type depends on the application kind (console/GUI), so we rely on
73
    // wxAppTraits setting up this pointer to point to the appropriate object.
74
    wxEventLoopBase *m_syncEventLoop;
75
76
#if wxUSE_STREAMS
77
    // the input buffer bufOut is connected to stdout, this is why it is
78
    // called bufOut and not bufIn
79
    wxStreamTempInputBuffer m_bufOut,
80
                            m_bufErr;
81
82
    // the corresponding FDs, -1 if not redirected
83
    int m_fdOut,
84
        m_fdErr;
85
#endif // wxUSE_STREAMS
86
87
88
private:
89
    // SIGCHLD signal handler that checks whether any of the currently running
90
    // children have exited.
91
    static void OnSomeChildExited(int sig);
92
93
    // All currently running child processes indexed by their PID.
94
    //
95
    // Notice that the container doesn't own its elements.
96
    using ChildProcessesData = std::unordered_map<int, wxExecuteData*>;
97
    static ChildProcessesData ms_childProcesses;
98
99
    wxDECLARE_NO_COPY_CLASS(wxExecuteData);
100
};
101
102
#endif // _WX_UNIX_EXECUTE_H