1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ExternalProgram.h
11 * \todo replace by Blocxx
16 #ifndef ZYPP_EXTERNALPROGRAM_H
17 #define ZYPP_EXTERNALPROGRAM_H
22 #include "zypp/base/ExternalDataSource.h"
23 #include "zypp/Pathname.h"
28 * @short Execute a program and give access to its io
29 * An object of this class encapsulates the execution of
30 * an external program. It starts the program using fork
31 * and some exec.. call, gives you access to the program's
32 * stdio and closes the program after use.
34 class ExternalProgram : public zypp::externalprogram::ExternalDataSource
39 * Define symbols for different policies on the handling
42 enum Stderr_Disposition {
50 * For passing additional environment variables to set
52 typedef std::map<std::string,std::string> Environment;
55 * Start the external program by using the shell <tt>/bin/sh<tt>
56 * with the option <tt>-c</tt>. You can use io direction symbols < and >.
57 * @param commandline a shell commandline that is appended to
58 * <tt>/bin/sh -c</tt>.
59 * @param default_locale whether to set LC_ALL=C before starting
60 * @param root directory to chroot into, / or empty to not chroot
62 ExternalProgram (std::string commandline,
63 Stderr_Disposition stderr_disp = Normal_Stderr,
64 bool use_pty = false, int stderr_fd = -1, bool default_locale = false,
65 const Pathname& root = "");
68 * Start an external program by giving the arguments as an arry of char *pointers.
69 * If environment is provided, varaiables will be added to the childs environment,
70 * overwriting existing ones.
72 ExternalProgram (const char *const *argv,
73 Stderr_Disposition stderr_disp = Normal_Stderr,
74 bool use_pty = false, int stderr_fd = -1, bool default_locale = false,
75 const Pathname& root = "");
77 ExternalProgram (const char *const *argv, const Environment & environment,
78 Stderr_Disposition stderr_disp = Normal_Stderr,
79 bool use_pty = false, int stderr_fd = -1, bool default_locale = false,
80 const Pathname& root = "");
82 ExternalProgram (const char *binpath, const char *const *argv_1,
83 bool use_pty = false);
86 ExternalProgram (const char *binpath, const char *const *argv_1, const Environment & environment,
87 bool use_pty = false);
100 * Return whether program is running
107 pid_t getpid() { return pid; }
110 * origfd will be accessible as newfd and closed (unless they were equal)
112 static void renumber_fd (int origfd, int newfd);
115 int checkStatus( int );
120 * Set to true, if a pair of ttys is used for communication
121 * instead of a pair of pipes.
128 void start_program (const char *const *argv, const Environment & environment,
129 Stderr_Disposition stderr_disp = Normal_Stderr,
130 int stderr_fd = -1, bool default_locale = false,
131 const char* root = NULL);
137 #endif // ZYPP_EXTERNALPROGRAM_H