diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2010-08-20 13:47:05 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2010-08-20 13:52:47 +0300 |
commit | 2c2faa299e6c1f2a9b6f8220c75cf878d4e005b0 (patch) | |
tree | 0c8aaf9202d523a61de95b3f623b76e1ad1adf84 /cliutils.c | |
parent | d391d5ec60c9fadb10236b8af236ac4b130cd2bd (diff) | |
download | librpm-tizen-2c2faa299e6c1f2a9b6f8220c75cf878d4e005b0.tar.gz librpm-tizen-2c2faa299e6c1f2a9b6f8220c75cf878d4e005b0.tar.bz2 librpm-tizen-2c2faa299e6c1f2a9b6f8220c75cf878d4e005b0.zip |
Move --pipe handling to cliutils helpers
Diffstat (limited to 'cliutils.c')
-rw-r--r-- | cliutils.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/cliutils.c b/cliutils.c index f022803dd..23c632372 100644 --- a/cliutils.c +++ b/cliutils.c @@ -2,6 +2,8 @@ #if HAVE_MCHECK_H #include <mcheck.h> #endif +#include <sys/wait.h> + #include <rpm/rpmlog.h> #include <rpm/rpmlib.h> #include <rpm/rpmfileutil.h> @@ -10,6 +12,8 @@ #include "cliutils.h" #include "debug.h" +static pid_t pipeChild = 0; + RPM_GNUC_NORETURN void argerror(const char * desc) { @@ -110,3 +114,37 @@ int finishCli(poptContext optCon, int rc) /* XXX Avoid exit status overflow. Status 255 is special to xargs(1) */ return (rc > 254) ? 254 : rc; } + +int initPipe(void) +{ + int p[2]; + + if (pipe(p) < 0) { + fprintf(stderr, _("creating a pipe for --pipe failed: %m\n")); + return -1; + } + + if (!(pipeChild = fork())) { + (void) signal(SIGPIPE, SIG_DFL); + (void) close(p[1]); + (void) dup2(p[0], STDIN_FILENO); + (void) close(p[0]); + (void) execl("/bin/sh", "/bin/sh", "-c", rpmcliPipeOutput, NULL); + fprintf(stderr, _("exec failed\n")); + exit(EXIT_FAILURE); + } + + (void) close(p[0]); + (void) dup2(p[1], STDOUT_FILENO); + (void) close(p[1]); + return 0; +} + +void finishPipe(void) +{ + int status; + if (pipeChild) { + (void) fclose(stdout); + (void) waitpid(pipeChild, &status, 0); + } +} |