Remove timeout logic to wait for shared lock in db3.c file
[platform/upstream/rpm.git] / rpm2cpio.c
index 6c29cab..8bee3c7 100644 (file)
@@ -1,7 +1,6 @@
 /* rpmarchive: spit out the main archive portion of a package */
 
 #include "system.h"
-const char *__progname;
 
 #include <rpm/rpmlib.h>                /* rpmReadPackageFile .. */
 #include <rpm/rpmtag.h>
@@ -9,6 +8,7 @@ const char *__progname;
 #include <rpm/rpmpgp.h>
 
 #include <rpm/rpmts.h>
+#include <unistd.h>
 
 #include "debug.h"
 
@@ -17,10 +17,13 @@ int main(int argc, char *argv[])
     FD_t fdi, fdo;
     Header h;
     char * rpmio_flags = NULL;
-    rpmRC rc;
+    int rc;
+    off_t payload_size;
     FD_t gzdi;
     
-    setprogname(argv[0]);      /* Retrofit glibc __progname */
+    xsetprogname(argv[0]); /* Portability call -- see system.h */
+
+    rpmReadConfigFiles(NULL, NULL);
     if (argc == 1)
        fdi = fdDup(STDIN_FILENO);
     else {
@@ -36,8 +39,11 @@ int main(int argc, char *argv[])
                (argc == 1 ? "<stdin>" : argv[1]), Fstrerror(fdi));
        exit(EXIT_FAILURE);
     }
+    if (isatty(STDOUT_FILENO)) {
+       fprintf(stderr, "Error: refusing to output cpio data to a terminal.\n");
+       exit(EXIT_FAILURE);
+    }
     fdo = fdDup(STDOUT_FILENO);
-    rpmReadConfigFiles(NULL, NULL);
 
     {  rpmts ts = rpmtsCreate();
        rpmVSFlags vsflags = 0;
@@ -69,9 +75,10 @@ int main(int argc, char *argv[])
        break;
     }
 
-    /* Retrieve type of payload compression. */
+    /* Retrieve payload size and compression type. */
     {  const char *compr = headerGetString(h, RPMTAG_PAYLOADCOMPRESSOR);
        rpmio_flags = rstrscat(NULL, "r.", compr ? compr : "gzip", NULL);
+       payload_size = headerGetNumber(h, RPMTAG_LONGARCHIVESIZE);
     }
 
     gzdi = Fdopen(fdi, rpmio_flags);   /* XXX gzdi == fdi */
@@ -82,8 +89,8 @@ int main(int argc, char *argv[])
        exit(EXIT_FAILURE);
     }
 
-    rc = ufdCopy(gzdi, fdo);
-    rc = (rc <= 0) ? EXIT_FAILURE : EXIT_SUCCESS;
+    rc = (ufdCopy(gzdi, fdo) == payload_size) ? EXIT_SUCCESS : EXIT_FAILURE;
+
     Fclose(fdo);
 
     Fclose(gzdi);      /* XXX gzdi == fdi */