00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PALUDIS_GUARD_PALUDIS_UTIL_SYSTEM_HH
00021 #define PALUDIS_GUARD_PALUDIS_UTIL_SYSTEM_HH 1
00022
00023 #include <paludis/util/exception.hh>
00024 #include <paludis/util/private_implementation_pattern.hh>
00025 #include <paludis/util/wrapped_forward_iterator-fwd.hh>
00026 #include <tr1/memory>
00027 #include <tr1/functional>
00028 #include <string>
00029 #include <sys/types.h>
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 namespace paludis
00042 {
00043 class FSEntry;
00044
00045
00046
00047
00048
00049
00050
00051
00052 class PALUDIS_VISIBLE GetenvError : public Exception
00053 {
00054 public:
00055
00056
00057
00058 GetenvError(const std::string & key) throw ();
00059
00060
00061 };
00062
00063
00064
00065
00066
00067
00068
00069
00070 class PALUDIS_VISIBLE RunCommandError : public Exception
00071 {
00072 public:
00073
00074
00075
00076 RunCommandError(const std::string & message) throw ();
00077 };
00078
00079
00080
00081
00082
00083
00084
00085 std::string getenv_with_default(const std::string & key, const std::string & def) PALUDIS_VISIBLE;
00086
00087
00088
00089
00090
00091
00092
00093 std::string getenv_or_error(const std::string & key) PALUDIS_VISIBLE;
00094
00095
00096
00097
00098
00099
00100 std::string kernel_version() PALUDIS_VISIBLE;
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 class PALUDIS_VISIBLE Command :
00111 private PrivateImplementationPattern<Command>
00112 {
00113 public:
00114
00115
00116
00117 Command(const std::string &);
00118 Command(const char * const);
00119 Command(const Command &);
00120 const Command & operator= (const Command &);
00121 ~Command();
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 Command & with_chdir(const FSEntry &);
00132
00133
00134
00135
00136 Command & with_setenv(const std::string &, const std::string &);
00137
00138
00139
00140
00141
00142
00143
00144 Command & with_clearenv();
00145
00146
00147
00148
00149 Command & with_sandbox();
00150
00151
00152
00153
00154
00155
00156 Command & with_sydbox();
00157
00158
00159
00160
00161 Command & with_echo_to_stderr();
00162
00163
00164
00165
00166 Command & with_uid_gid(const uid_t, const gid_t);
00167
00168
00169
00170
00171 Command & with_stdout_prefix(const std::string &);
00172
00173
00174
00175
00176 Command & with_stderr_prefix(const std::string &);
00177
00178
00179
00180
00181
00182 Command & with_prefix_discard_blank_output();
00183
00184
00185
00186
00187 Command & with_prefix_blank_lines();
00188
00189
00190
00191
00192 Command & with_pipe_command_handler(const std::tr1::function<std::string (const std::string &)> &);
00193
00194
00195
00196
00197 Command & with_captured_stdout_stream(std::ostream * const);
00198
00199
00200
00201
00202
00203
00204 Command & with_captured_stderr_stream(std::ostream * const);
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 Command & with_input_stream(
00217 std::istream * const,
00218 int fd,
00219 const std::string & env_var);
00220
00221
00222
00223
00224
00225
00226 Command & with_ptys();
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 std::string command() const;
00237
00238
00239
00240
00241 std::string chdir() const;
00242
00243
00244
00245
00246 void echo_to_stderr() const;
00247
00248
00249
00250
00251 std::tr1::shared_ptr<const uid_t> uid() const;
00252
00253
00254
00255
00256 std::tr1::shared_ptr<const gid_t> gid() const;
00257
00258
00259
00260
00261 std::string stdout_prefix() const;
00262
00263
00264
00265
00266 std::string stderr_prefix() const;
00267
00268
00269
00270
00271
00272 bool prefix_discard_blank_output() const;
00273
00274
00275
00276
00277 bool prefix_blank_lines() const;
00278
00279
00280
00281
00282 const std::tr1::function<std::string (const std::string &)> & pipe_command_handler() const;
00283
00284
00285
00286
00287 std::ostream * captured_stdout_stream() const;
00288
00289
00290
00291
00292
00293
00294 std::ostream * captured_stderr_stream() const;
00295
00296
00297
00298
00299
00300
00301 std::istream * input_stream() const;
00302
00303
00304
00305
00306
00307
00308 int input_fd() const;
00309
00310
00311
00312
00313
00314
00315 const std::string input_fd_env_var() const;
00316
00317
00318
00319
00320
00321
00322 bool ptys() const;
00323
00324
00325
00326
00327
00328
00329 bool clearenv() const;
00330
00331
00332
00333
00334
00335
00336 struct ConstIteratorTag;
00337 typedef WrappedForwardIterator<ConstIteratorTag, const std::pair<const std::string, std::string> > ConstIterator;
00338 ConstIterator begin_setenvs() const;
00339 ConstIterator end_setenvs() const;
00340
00341
00342 };
00343
00344
00345
00346
00347
00348
00349 int run_command(const Command & cmd) PALUDIS_VISIBLE
00350 PALUDIS_ATTRIBUTE((warn_unused_result));
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362 void become_command(const Command & cmd) PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((noreturn));
00363
00364
00365
00366
00367
00368
00369
00370 void set_run_command_stdout_fds(const int, const int) PALUDIS_VISIBLE;
00371
00372
00373
00374
00375
00376
00377
00378 void set_run_command_stderr_fds(const int, const int) PALUDIS_VISIBLE;
00379
00380
00381
00382
00383
00384
00385 std::string get_user_name(const uid_t) PALUDIS_VISIBLE;
00386
00387
00388
00389
00390
00391
00392 std::string get_group_name(const gid_t) PALUDIS_VISIBLE;
00393 }
00394
00395 #endif
00396