rpm 4.9.1.3

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

cliutils.c
Go to the documentation of this file.

    00001 #include "system.h"
    00002 #if HAVE_MCHECK_H
    00003 #include <mcheck.h>
    00004 #endif
    00005 #include <sys/wait.h>
    00006
    00007 #include <rpm/rpmlog.h>
    00008 #include <rpm/rpmlib.h>
    00009 #include <rpm/rpmfileutil.h>
    00010 #include <rpm/rpmmacro.h>
    00011 #include <rpm/rpmcli.h>
    00012 #include "cliutils.h"
    00013 #include "debug.h"
    00014
    00015 static pid_t pipeChild = 0;
    00016
    00017 RPM_GNUC_NORETURN
    00018 void argerror(const char * desc)
    00019 {
    00020     fprintf(stderr, _("%s: %s\n"), __progname, desc);
    00021     exit(EXIT_FAILURE);
    00022 }
    00023
    00024 static void printVersion(FILE * fp)
    00025 {
    00026     fprintf(fp, _("RPM version %s\n"), rpmEVR);
    00027 }
    00028
    00029 static void printBanner(FILE * fp)
    00030 {
    00031     fprintf(fp, _("Copyright (C) 1998-2002 - Red Hat, Inc.\n"));
    00032     fprintf(fp, _("This program may be freely redistributed under the terms of the GNU GPL\n"));
    00033 }
    00034
    00035 void printUsage(poptContext con, FILE * fp, int flags)
    00036 {
    00037     printVersion(fp);
    00038     printBanner(fp);
    00039     fprintf(fp, "\n");
    00040
    00041     if (rpmIsVerbose())
    00042         poptPrintHelp(con, fp, flags);
    00043     else
    00044         poptPrintUsage(con, fp, flags);
    00045 }
    00046
    00047 int initPipe(void)
    00048 {
    00049     int p[2];
    00050
    00051     if (pipe(p) < 0) {
    00052         fprintf(stderr, _("creating a pipe for --pipe failed: %m\n"));
    00053         return -1;
    00054     }
    00055
    00056     if (!(pipeChild = fork())) {
    00057         (void) signal(SIGPIPE, SIG_DFL);
    00058         (void) close(p[1]);
    00059         (void) dup2(p[0], STDIN_FILENO);
    00060         (void) close(p[0]);
    00061         (void) execl("/bin/sh", "/bin/sh", "-c", rpmcliPipeOutput, NULL);
    00062         fprintf(stderr, _("exec failed\n"));
    00063         exit(EXIT_FAILURE);
    00064     }
    00065
    00066     (void) close(p[0]);
    00067     (void) dup2(p[1], STDOUT_FILENO);
    00068     (void) close(p[1]);
    00069     return 0;
    00070 }
    00071
    00072 void finishPipe(void)
    00073 {
    00074     int status;
    00075     if (pipeChild) {
    00076         (void) fclose(stdout);
    00077         (void) waitpid(pipeChild, &status, 0);
    00078     }
    00079 }