This file is indexed.

/usr/include/bobcat/process is in libbobcat-dev 2.20.01-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#ifndef INCLUDED_BOBCAT_PROCESS_
#define INCLUDED_BOBCAT_PROCESS_

#include <string>
#include <ostream>
#include <istream>

#include <bobcat/fork>
#include <bobcat/string>
#include <bobcat/pipe>
#include <bobcat/selector>
#include <bobcat/ifdstreambuf>
#include <bobcat/ofdstreambuf>
#include <bobcat/iostream>

#if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
    #ifndef BOBCAT_DIY_CLOEXEC_
    #define BOBCAT_DIY_CLOEXEC_
    #endif
#endif

namespace FBB
{

class Process: private Fork, public IOStream
{
    friend Process &operator|(Process &lhs, Process &rhs);

    public:
        enum ProcessType
        {
            NO_PATH,
            USE_PATH,
            USE_SHELL
        };

    private:
        bool            d_active;
        size_t          d_mode;
        size_t          d_timeLimit;      // seconds allowed to child-process
        ProcessType     d_processType;

        size_t          d_setMode;          // these values are set by the 
        size_t          d_setTimeLimit;   // set members and used as 
        ProcessType     d_setProcessType;   // defaults unless overridden by
                                            // actual values
                                            // Constructors set these values 
                                            // too.
        std::string     d_command;

        Pipe d_oChildInPipe;    // cin read by the CHILD
        Pipe d_iChildOutPipe;   // cout written by the CHILD
        Pipe d_iChildErrPipe;   // cerr written by the CHILD    

        OFdStreambuf    d_oChildInbuf;      // Child extracts,  
        IFdStreambuf    d_iChildOutbuf;     // Child inserts,
        IFdStreambuf    d_iChildErrbuf;     // Child inserts
    
        std::ostream   d_oChildIn;          // Parent inserts to child's cin
        std::istream   d_iChildOut;         // Parent extracts child's cout
        std::istream   d_iChildErr;         // Parent extracts child's cerr
    
        Selector        d_selector;         // senses activities on Child's
                                            // out/err streams
        struct RetPid
        {
            int     ret;
            pid_t   pid;
    
            RetPid();
        };
        RetPid d_child;
        RetPid d_monitor;

#ifdef BOBCAT_DIY_CLOEXEC_
        int d_closedByChild;    // DIY CLOSE_ON_EXEC
#endif

    public:
        enum IOMode
        {
            IGNORE_ALL      = 0,
            STD             = 0,

            CIN             = 1 << 0,
            COUT            = 1 << 1,
            CERR            = 1 << 2,

            IGNORE_COUT     = 1 << 3,
            IGNORE_CERR     = 1 << 4,

            MERGE_COUT_CERR = 1 << 5,

            DIRECT          = 1 << 8,

            // flags below are Internal Use Only and cannot be set by
            // users

            IN_PIPE         = 1 << 10,
            OUT_PIPE        = 1 << 11,

            CLOSE_ON_EXEC   = 1 << 12,
        };
        typedef size_t iomode;

        enum ChildOutput
        {
            NOTHING_AVAILABLE   = 0,
            CHILD_COUT          = 1 << 0,
            CHILD_CERR          = 1 << 1,
        };
            
        explicit Process(std::string const &command = "");              // 1
        explicit Process(iomode mode, std::string const &command = ""); // 2
        Process(iomode mode, ProcessType type,                          // 3
                                    std::string const &command = "");
        Process(iomode mode, ProcessType type, size_t timeLimit,      // 4
                                    std::string const &command = "");

        virtual ~Process();                 // stop()s any ongoing process

        iomode ioMode() const;              // returns default IOMode
        ProcessType processType() const;    // returns default ProcessType
        size_t timeLimit() const;           // returns default time limit

        void setIOMode(iomode mode);            // change IOMode

        void setProcessType(ProcessType type);

        void setTimeLimit(size_t timeLimit);    // for the next cmd to start
                                                // 0 means: no time monitor

        void setCommand(std::string const &command);    // sets cmd,
                                                        // eats backticks
        Process &operator+=(std::string const &text);   // adds to the command
        
        void start();
        void start(iomode mode);
        void start(iomode mode, ProcessType type);
        void start(iomode mode, ProcessType type, size_t timeLimit);

        void system();              // calls /bin/sh -c cmd; shell redirs OK
        void system(iomode mode);   
        void system(iomode mode, size_t timeLimit);  


        int operator=(std::string const &cmd);  // sets and starts a command


        std::string const &str() const; // current command

        int stop();                     // terminate a running childprocess

        template <typename Type>
        Process &operator<<(Type const &value);

        Process &operator<<(std::ostream &(*pf)(std::ostream &));

        template <typename Type>
        Process &operator>>(Type &value);

        bool active();

        Process &operator()(iomode mode);
        Process &operator()(iomode mode, ProcessType type);
        Process &operator()(iomode mode, ProcessType type, size_t timeLimit);

        void close();                           // closes input to the child

        std::istream &cerr();                   // READ cerr from the child

        size_t available();                     // returns ChildOutput bit_or
                                                // (cf. manpage)

        void showMode(char const *lab);

        using Fork::waitForChild;
                                
    private:
        Process(Process const &other) = delete;
        Process &operator=(Process const &other) = delete;

        virtual void childProcess();
        virtual void childRedirections();
        virtual void parentProcess();
        virtual void parentRedirections();

        void newPipe(Pipe &pipe);
        pid_t discontinue(RetPid &proc);
        size_t whichStream();
        void close(int fd);
        void closeWriteFd(Pipe &pipe);
        void closeReadFd(Pipe &pipe);

        void forking();
        void initialize(size_t timeLimit, iomode mode, 
                                                ProcessType processType);
        iomode sanitizeIOMode(iomode mode);
        void newPipes();
        void closeChildInputOnExec();

        struct ExecContext
        {
            bool ok;                // true: status is ok
            size_t argc;            // must eventually be at least 1
            char const *message;    // only set if !ok
            char const **args;      // 0-terminated array of pointers to the 
                                    // arguments
        };
        static void execContext(String::SplitPair const &splitPair,
                                ExecContext &ec);
        ExecContext analyzeCommand();
};

inline void Process::start()
{   
    start(d_setMode, d_setProcessType, d_setTimeLimit);
}

inline void Process::start(iomode mode)
{
    start(mode & ~(IN_PIPE | OUT_PIPE | CLOSE_ON_EXEC), 
                                        d_setProcessType, d_setTimeLimit);
}

inline void Process::start(iomode mode, ProcessType type)
{
    start(mode & ~(IN_PIPE | OUT_PIPE | CLOSE_ON_EXEC), type, d_setTimeLimit);
}

template <typename Type>
Process &Process::operator<<(Type const &value)
{
    if (active())
        dynamic_cast<std::ostream &>(*this) << value;

    return *this;
}

template <typename Type>
Process &Process::operator>>(Type &value)
{
    if ((available() & CHILD_COUT) || active())
        dynamic_cast<std::istream &>(*this) >> value;

    return *this;
}

inline std::string const &Process::str() const
{
    return d_command;
}

inline void Process::system()
{
    start(d_mode, USE_SHELL, d_timeLimit);
}

inline void Process::system(iomode mode)
{
    start(mode & ~(IN_PIPE | OUT_PIPE | CLOSE_ON_EXEC), 
                                                USE_SHELL, d_timeLimit);
}

inline void Process::system(iomode mode, size_t timeLimit)
{
    start(mode & ~(IN_PIPE | OUT_PIPE | CLOSE_ON_EXEC), USE_SHELL, timeLimit);
}

inline Process &Process::operator+=(std::string const &command)
{
    d_command += command;
    return *this;
}

inline void Process::setCommand(std::string const &command)
{
    d_command = command;
}

inline void Process::setProcessType(ProcessType type)
{
    d_setProcessType = d_processType = type;
}

inline void Process::setTimeLimit(size_t timeLimit)
{
    d_setTimeLimit = d_timeLimit = timeLimit;
}

inline void Process::setIOMode(iomode mode)
{
    d_setMode = sanitizeIOMode(mode & ~(IN_PIPE | OUT_PIPE | CLOSE_ON_EXEC));
}

inline Process &Process::operator()(iomode mode)
{
    return operator()(mode & ~(IN_PIPE | OUT_PIPE | CLOSE_ON_EXEC), 
                                            d_setProcessType, d_setTimeLimit);
}

inline Process &Process::operator()(iomode mode, ProcessType type)
{
    return operator()(mode & ~(IN_PIPE | OUT_PIPE | CLOSE_ON_EXEC), 
                                                    type, d_setTimeLimit);
}

inline Process::iomode Process::ioMode() const
{
    return d_mode & ~(IN_PIPE | OUT_PIPE | CLOSE_ON_EXEC);
}

inline Process::ProcessType Process::processType() const
{
    return d_setProcessType;
}

inline size_t Process::timeLimit() const
{
    return d_setTimeLimit;
}


} // FBB        

#endif