system.hh
Go to the documentation of this file.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 Command & with_sandbox();
00142
00143
00144
00145
00146 Command & with_echo_to_stderr();
00147
00148
00149
00150
00151 Command & with_uid_gid(const uid_t, const gid_t);
00152
00153
00154
00155
00156 Command & with_stdout_prefix(const std::string &);
00157
00158
00159
00160
00161 Command & with_stderr_prefix(const std::string &);
00162
00163
00164
00165
00166
00167 Command & with_prefix_discard_blank_output();
00168
00169
00170
00171
00172 Command & with_prefix_blank_lines();
00173
00174
00175
00176
00177 Command & with_pipe_command_handler(const std::tr1::function<std::string (const std::string &)> &);
00178
00179
00180
00181
00182 Command & with_captured_stdout_stream(std::ostream * const);
00183
00184
00185
00186
00187
00188
00189 Command & with_captured_stderr_stream(std::ostream * const);
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 std::string command() const;
00200
00201
00202
00203
00204 std::string chdir() const;
00205
00206
00207
00208
00209 void echo_to_stderr() const;
00210
00211
00212
00213
00214 std::tr1::shared_ptr<const uid_t> uid() const;
00215
00216
00217
00218
00219 std::tr1::shared_ptr<const gid_t> gid() const;
00220
00221
00222
00223
00224 std::string stdout_prefix() const;
00225
00226
00227
00228
00229 std::string stderr_prefix() const;
00230
00231
00232
00233
00234
00235 bool prefix_discard_blank_output() const;
00236
00237
00238
00239
00240 bool prefix_blank_lines() const;
00241
00242
00243
00244
00245 const std::tr1::function<std::string (const std::string &)> & pipe_command_handler() const;
00246
00247
00248
00249
00250 std::ostream * captured_stdout_stream() const;
00251
00252
00253
00254
00255
00256
00257 std::ostream * captured_stderr_stream() const;
00258
00259
00260
00261
00262
00263
00264 struct ConstIteratorTag;
00265 typedef WrappedForwardIterator<ConstIteratorTag, const std::pair<const std::string, std::string> > ConstIterator;
00266 ConstIterator begin_setenvs() const;
00267 ConstIterator end_setenvs() const;
00268
00269
00270 };
00271
00272
00273
00274
00275
00276
00277 int run_command(const Command & cmd) PALUDIS_VISIBLE
00278 PALUDIS_ATTRIBUTE((warn_unused_result));
00279
00280
00281
00282
00283
00284
00285
00286 void set_run_command_stdout_fds(const int, const int) PALUDIS_VISIBLE;
00287
00288
00289
00290
00291
00292
00293
00294 void set_run_command_stderr_fds(const int, const int) PALUDIS_VISIBLE;
00295
00296
00297
00298
00299
00300
00301 std::string get_user_name(const uid_t) PALUDIS_VISIBLE;
00302
00303
00304
00305
00306
00307
00308 std::string get_group_name(const gid_t) PALUDIS_VISIBLE;
00309 }
00310
00311 #endif
00312