This file is indexed.

/usr/include/shevek/process.hh is in libshevek-dev 1.4-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
/* process.hh - fork/exec made userfriendly
 * Copyright 2005-2008 Bas Wijnen <wijnen@debian.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef SHEVEK_PROCESS_HH
#define SHEVEK_PROCESS_HH

#include <string>
#include "refbase.hh"
#include "fd.hh"

namespace shevek
{
  /// Create a process, optionally connection its standard in- and output streams to the calling program.
  class process : public shevek::refbase
  {
  public:
    /// Create a process from a filename and an argument list.
    static Glib::RefPtr <process> create (std::string const &command,
					  std::list <std::string> &argv,
					  bool pipe_stdin = true,
					  bool pipe_stdout = true,
					  bool pipe_stderr = true);
    /// Create a process from a filename, an argument list and an environment.
    static Glib::RefPtr <process> create (std::string const &command,
					  std::list <std::string> &argv,
					  std::list <std::string> const &envp,
					  bool pipe_stdin = true,
					  bool pipe_stdout = true,
					  bool pipe_stderr = true);
    /// Run a string with the shell.
    /** Note that the process is forked from the shell, and so does not get killed when the process goes away.
     */
    static Glib::RefPtr <process> shell (std::string const &command,
					 bool pipe_stdin = true,
					 bool pipe_stdout = true,
					 bool pipe_stderr = true,
					 std::string const &sh = "/bin/sh")
    {
	    std::list <std::string> args;
	    args.push_back (sh);
	    args.push_back ("-c");
	    args.push_back (command);
	    return create (command, args, pipe_stdin, pipe_stdout, pipe_stderr);
    }
    /// The standard input pipe, if it was requested.
    Glib::RefPtr <shevek::fd> in ();
    /// The standard output pipe, if it was requested.
    Glib::RefPtr <shevek::fd> out ();
    /// The standard error pipe, if it was requested.
    Glib::RefPtr <shevek::fd> err ();
    /// The process ID.
    pid_t pid ();
    /// The destructor.  This kills the process if it was still running.
    ~process ();
    /// Run a process and return its output.
    /** A convenience function for running a process and catching its standard output in a string.
     *  This blocks until the process has exited.
     */
    static std::string run (std::string const &command, std::string const &sh);
    /// Create a process without arguments.
    static Glib::RefPtr <process> create (std::string const &command,
					  bool pipe_stdin = true,
					  bool pipe_stdout = true,
					  bool pipe_stderr = true)
    {
	    std::list <std::string> args;
	    args.push_back (command);
	    return create (command, args, pipe_stdin, pipe_stdout, pipe_stderr);
    }
    /// Create a process with one argument.
    static Glib::RefPtr <process> create (std::string const &command,
					  std::string const &a1,
					  bool pipe_stdin = true,
					  bool pipe_stdout = true,
					  bool pipe_stderr = true)
    {
	    std::list <std::string> args;
	    args.push_back (command);
	    args.push_back (a1);
	    return create (command, args, pipe_stdin, pipe_stdout, pipe_stderr);
    }
    /// Create a process with two arguments.
    static Glib::RefPtr <process> create (std::string const &command,
					  std::string const &a1,
					  std::string const &a2,
					  bool pipe_stdin = true,
					  bool pipe_stdout = true,
					  bool pipe_stderr = true)
    {
	    std::list <std::string> args;
	    args.push_back (command);
	    args.push_back (a1);
	    args.push_back (a2);
	    return create (command, args, pipe_stdin, pipe_stdout, pipe_stderr);
    }
    /// Create a process with three arguments.
    static Glib::RefPtr <process> create (std::string const &command,
					  std::string const &a1,
					  std::string const &a2,
					  std::string const &a3,
					  bool pipe_stdin = true,
					  bool pipe_stdout = true,
					  bool pipe_stderr = true)
    {
	    std::list <std::string> args;
	    args.push_back (command);
	    args.push_back (a1);
	    args.push_back (a2);
	    args.push_back (a3);
	    return create (command, args, pipe_stdin, pipe_stdout, pipe_stderr);
    }
    /// Create a process with four arguments.
    static Glib::RefPtr <process> create (std::string const &command,
					  std::string const &a1,
					  std::string const &a2,
					  std::string const &a3,
					  std::string const &a4,
					  bool pipe_stdin = true,
					  bool pipe_stdout = true,
					  bool pipe_stderr = true)
    {
	    std::list <std::string> args;
	    args.push_back (command);
	    args.push_back (a1);
	    args.push_back (a2);
	    args.push_back (a3);
	    args.push_back (a4);
	    return create (command, args, pipe_stdin, pipe_stdout, pipe_stderr);
    }
    /// Create a process with five arguments.
    static Glib::RefPtr <process> create (std::string const &command,
					  std::string const &a1,
					  std::string const &a2,
					  std::string const &a3,
					  std::string const &a4,
					  std::string const &a5,
					  bool pipe_stdin = true,
					  bool pipe_stdout = true,
					  bool pipe_stderr = true)
    {
	    std::list <std::string> args;
	    args.push_back (command);
	    args.push_back (a1);
	    args.push_back (a2);
	    args.push_back (a3);
	    args.push_back (a4);
	    args.push_back (a5);
	    return create (command, args, pipe_stdin, pipe_stdout, pipe_stderr);
    }
    /// Create a process with six arguments.
    static Glib::RefPtr <process> create (std::string const &command,
					  std::string const &a1,
					  std::string const &a2,
					  std::string const &a3,
					  std::string const &a4,
					  std::string const &a5,
					  std::string const &a6,
					  bool pipe_stdin = true,
					  bool pipe_stdout = true,
					  bool pipe_stderr = true)
    {
	    std::list <std::string> args;
	    args.push_back (command);
	    args.push_back (a1);
	    args.push_back (a2);
	    args.push_back (a3);
	    args.push_back (a4);
	    args.push_back (a5);
	    args.push_back (a6);
	    return create (command, args, pipe_stdin, pipe_stdout, pipe_stderr);
    }
    /// Create a process with seven arguments.
    static Glib::RefPtr <process> create (std::string const &command,
					  std::string const &a1,
					  std::string const &a2,
					  std::string const &a3,
					  std::string const &a4,
					  std::string const &a5,
					  std::string const &a6,
					  std::string const &a7,
					  bool pipe_stdin = true,
					  bool pipe_stdout = true,
					  bool pipe_stderr = true)
    {
	    std::list <std::string> args;
	    args.push_back (command);
	    args.push_back (a1);
	    args.push_back (a2);
	    args.push_back (a3);
	    args.push_back (a4);
	    args.push_back (a5);
	    args.push_back (a6);
	    args.push_back (a7);
	    return create (command, args, pipe_stdin, pipe_stdout, pipe_stderr);
    }
    /// Create a process with eight arguments.
    static Glib::RefPtr <process> create (std::string const &command,
					  std::string const &a1,
					  std::string const &a2,
					  std::string const &a3,
					  std::string const &a4,
					  std::string const &a5,
					  std::string const &a6,
					  std::string const &a7,
					  std::string const &a8,
					  bool pipe_stdin = true,
					  bool pipe_stdout = true,
					  bool pipe_stderr = true)
    {
	    std::list <std::string> args;
	    args.push_back (command);
	    args.push_back (a1);
	    args.push_back (a2);
	    args.push_back (a3);
	    args.push_back (a4);
	    args.push_back (a5);
	    args.push_back (a6);
	    args.push_back (a7);
	    args.push_back (a8);
	    return create (command, args, pipe_stdin, pipe_stdout, pipe_stderr);
    }
    /// Create a process with nine arguments.
    static Glib::RefPtr <process> create (std::string const &command,
					  std::string const &a1,
					  std::string const &a2,
					  std::string const &a3,
					  std::string const &a4,
					  std::string const &a5,
					  std::string const &a6,
					  std::string const &a7,
					  std::string const &a8,
					  std::string const &a9,
					  bool pipe_stdin = true,
					  bool pipe_stdout = true,
					  bool pipe_stderr = true)
    {
	    std::list <std::string> args;
	    args.push_back (command);
	    args.push_back (a1);
	    args.push_back (a2);
	    args.push_back (a3);
	    args.push_back (a4);
	    args.push_back (a5);
	    args.push_back (a6);
	    args.push_back (a7);
	    args.push_back (a8);
	    args.push_back (a9);
	    return create (command, args, pipe_stdin, pipe_stdout, pipe_stderr);
    }
  private:
    Glib::RefPtr <shevek::fd> m_in, m_out, m_err;
    pid_t m_pid;
    process (std::string const &command, char **argv, char **envp, bool pipe_stdin, bool pipe_stdout, bool pipe_stderr);
    static char **make_pointers (std::list <std::string> const &source);
    static void clean (char **pointers);
    static char *dup (char const *str);
  };
}

#endif