1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ExternalProgram.h
13 #ifndef ZYPP_EXTERNALPROGRAM_H
14 #define ZYPP_EXTERNALPROGRAM_H
19 #include "zypp/base/ExternalDataSource.h"
20 #include "zypp/Pathname.h"
25 * @short Execute a program and give access to its io
26 * An object of this class encapsulates the execution of
27 * an external program. It starts the program using fork
28 * and some exec.. call, gives you access to the program's
29 * stdio and closes the program after use.
31 class ExternalProgram : public zypp::externalprogram::ExternalDataSource
36 * Define symbols for different policies on the handling
39 enum Stderr_Disposition {
47 * For passing additional environment variables to set
49 typedef std::map<std::string,std::string> Environment;
52 * Start the external program by using the shell <tt>/bin/sh<tt>
53 * with the option <tt>-c</tt>. You can use io direction symbols < and >.
54 * @param commandline a shell commandline that is appended to
55 * <tt>/bin/sh -c</tt>.
56 * @param default_locale whether to set LC_ALL=C before starting
57 * @param root directory to chroot into, / or empty to not chroot
59 ExternalProgram (std::string commandline,
60 Stderr_Disposition stderr_disp = Normal_Stderr,
61 bool use_pty = false, int stderr_fd = -1, bool default_locale = false,
62 const Pathname& root = "");
65 * Start an external program by giving the arguments as an arry of char *pointers.
66 * If environment is provided, varaiables will be added to the childs environment,
67 * 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