|
|
2ff057 |
#include "system.h"
|
|
|
2ff057 |
#if HAVE_MCHECK_H
|
|
|
2ff057 |
#include <mcheck.h>
|
|
|
2ff057 |
#endif
|
|
|
2ff057 |
#include <errno.h>
|
|
|
2ff057 |
#include <sys/wait.h>
|
|
|
2ff057 |
|
|
|
2ff057 |
#include <rpm/rpmlog.h>
|
|
|
2ff057 |
#include <rpm/rpmlib.h>
|
|
|
2ff057 |
#include <rpm/rpmfileutil.h>
|
|
|
2ff057 |
#include <rpm/rpmmacro.h>
|
|
|
2ff057 |
#include <rpm/rpmcli.h>
|
|
|
2ff057 |
#include "cliutils.h"
|
|
|
2ff057 |
#include "debug.h"
|
|
|
2ff057 |
|
|
|
2ff057 |
static pid_t pipeChild = 0;
|
|
|
2ff057 |
|
|
|
2ff057 |
RPM_GNUC_NORETURN
|
|
|
2ff057 |
void argerror(const char * desc)
|
|
|
2ff057 |
{
|
|
|
2ff057 |
fprintf(stderr, _("%s: %s\n"), xgetprogname(), desc);
|
|
|
2ff057 |
exit(EXIT_FAILURE);
|
|
|
2ff057 |
}
|
|
|
2ff057 |
|
|
|
2ff057 |
static void printVersion(FILE * fp)
|
|
|
2ff057 |
{
|
|
|
2ff057 |
fprintf(fp, _("RPM version %s\n"), rpmEVR);
|
|
|
2ff057 |
}
|
|
|
2ff057 |
|
|
|
2ff057 |
static void printBanner(FILE * fp)
|
|
|
2ff057 |
{
|
|
|
2ff057 |
fprintf(fp, _("Copyright (C) 1998-2002 - Red Hat, Inc.\n"));
|
|
|
2ff057 |
fprintf(fp, _("This program may be freely redistributed under the terms of the GNU GPL\n"));
|
|
|
2ff057 |
}
|
|
|
2ff057 |
|
|
|
2ff057 |
void printUsage(poptContext con, FILE * fp, int flags)
|
|
|
2ff057 |
{
|
|
|
2ff057 |
printVersion(fp);
|
|
|
2ff057 |
printBanner(fp);
|
|
|
2ff057 |
fprintf(fp, "\n");
|
|
|
2ff057 |
|
|
|
2ff057 |
if (rpmIsVerbose())
|
|
|
2ff057 |
poptPrintHelp(con, fp, flags);
|
|
|
2ff057 |
else
|
|
|
2ff057 |
poptPrintUsage(con, fp, flags);
|
|
|
2ff057 |
}
|
|
|
2ff057 |
|
|
|
2ff057 |
int initPipe(void)
|
|
|
2ff057 |
{
|
|
|
2ff057 |
int p[2];
|
|
|
2ff057 |
|
|
|
2ff057 |
if (pipe(p) < 0) {
|
|
|
2ff057 |
fprintf(stderr, _("creating a pipe for --pipe failed: %m\n"));
|
|
|
2ff057 |
return -1;
|
|
|
2ff057 |
}
|
|
|
2ff057 |
|
|
|
2ff057 |
if (!(pipeChild = fork())) {
|
|
|
2ff057 |
(void) close(p[1]);
|
|
|
2ff057 |
(void) dup2(p[0], STDIN_FILENO);
|
|
|
2ff057 |
(void) close(p[0]);
|
|
|
2ff057 |
(void) execl("/bin/sh", "/bin/sh", "-c", rpmcliPipeOutput, NULL);
|
|
|
2ff057 |
fprintf(stderr, _("exec failed\n"));
|
|
|
2ff057 |
exit(EXIT_FAILURE);
|
|
|
2ff057 |
}
|
|
|
2ff057 |
|
|
|
2ff057 |
(void) close(p[0]);
|
|
|
2ff057 |
(void) dup2(p[1], STDOUT_FILENO);
|
|
|
2ff057 |
(void) close(p[1]);
|
|
|
2ff057 |
return 0;
|
|
|
2ff057 |
}
|
|
|
2ff057 |
|
|
|
2ff057 |
int finishPipe(void)
|
|
|
2ff057 |
{
|
|
|
2ff057 |
int rc = 0;
|
|
|
2ff057 |
if (pipeChild) {
|
|
|
2ff057 |
int status;
|
|
|
2ff057 |
pid_t reaped;
|
|
|
2ff057 |
|
|
|
2ff057 |
(void) fclose(stdout);
|
|
|
2ff057 |
do {
|
|
|
2ff057 |
reaped = waitpid(pipeChild, &status, 0);
|
|
|
2ff057 |
} while (reaped == -1 && errno == EINTR);
|
|
|
2ff057 |
|
|
|
2ff057 |
if (reaped == -1 || !WIFEXITED(status) || WEXITSTATUS(status))
|
|
|
2ff057 |
rc = 1;
|
|
|
2ff057 |
}
|
|
|
2ff057 |
return rc;
|
|
|
2ff057 |
}
|