aboutsummaryrefslogtreecommitdiff
path: root/archival/rpm2cpio.c
diff options
context:
space:
mode:
Diffstat (limited to 'archival/rpm2cpio.c')
-rw-r--r--archival/rpm2cpio.c73
1 files changed, 31 insertions, 42 deletions
diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c
index 28b43a181..7256aae6b 100644
--- a/archival/rpm2cpio.c
+++ b/archival/rpm2cpio.c
@@ -42,6 +42,26 @@ static unsigned skip_header(void)
42 return sizeof(header) + len; 42 return sizeof(header) + len;
43} 43}
44 44
45#if SEAMLESS_COMPRESSION
46static void handle_SIGCHLD(int signo UNUSED_PARAM)
47{
48 int status;
49
50 /* Wait for any child without blocking */
51 for (;;) {
52 if (wait_any_nohang(&status) < 0)
53 /* wait failed?! I'm confused... */
54 return;
55 if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
56 /* this child exited with 0 */
57 continue;
58 /* Cannot happen?
59 if (!WIFSIGNALED(status) && !WIFEXITED(status)) ???; */
60 bb_got_signal = 1;
61 }
62}
63#endif
64
45/* No getopt required */ 65/* No getopt required */
46int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 66int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
47int rpm2cpio_main(int argc UNUSED_PARAM, char **argv) 67int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
@@ -66,54 +86,23 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
66 /* Skip the main header */ 86 /* Skip the main header */
67 skip_header(); 87 skip_header();
68 88
69#if 0 89#if SEAMLESS_COMPRESSION
90 /* We need to know whether child (gzip/bzip/etc) exits abnormally */
91 signal(SIGCHLD, handle_SIGCHLD);
92#endif
93
70 /* This works, but doesn't report uncompress errors (they happen in child) */ 94 /* This works, but doesn't report uncompress errors (they happen in child) */
71 setup_unzip_on_fd(rpm_fd /*fail_if_not_detected: 1*/); 95 setup_unzip_on_fd(rpm_fd, /*fail_if_not_detected:*/ 1);
72 if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0) 96 if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
73 bb_error_msg_and_die("error unpacking"); 97 bb_error_msg_and_die("error unpacking");
74#else
75 /* BLOAT */
76 {
77 union {
78 uint8_t b[4];
79 uint16_t b16[2];
80 uint32_t b32[1];
81 } magic;
82 IF_DESKTOP(long long) int FAST_FUNC (*unpack)(int src_fd, int dst_fd);
83
84 xread(rpm_fd, magic.b16, sizeof(magic.b16[0]));
85 if (magic.b16[0] == GZIP_MAGIC) {
86 unpack = unpack_gz_stream;
87 } else
88 if (ENABLE_FEATURE_SEAMLESS_BZ2
89 && magic.b16[0] == BZIP2_MAGIC
90 ) {
91 unpack = unpack_bz2_stream;
92 } else
93 if (ENABLE_FEATURE_SEAMLESS_XZ
94 && magic.b16[0] == XZ_MAGIC1
95 ) {
96 xread(rpm_fd, magic.b32, sizeof(magic.b32[0]));
97 if (magic.b32[0] != XZ_MAGIC2)
98 goto no_magic;
99 /* unpack_xz_stream wants fd at position 6, no need to seek */
100 //xlseek(rpm_fd, -6, SEEK_CUR);
101 unpack = unpack_xz_stream;
102 } else {
103 no_magic:
104 bb_error_msg_and_die("no gzip"
105 IF_FEATURE_SEAMLESS_BZ2("/bzip2")
106 IF_FEATURE_SEAMLESS_XZ("/xz")
107 " magic");
108 }
109 if (unpack(rpm_fd, STDOUT_FILENO) < 0)
110 bb_error_msg_and_die("error unpacking");
111 }
112#endif
113 98
114 if (ENABLE_FEATURE_CLEAN_UP) { 99 if (ENABLE_FEATURE_CLEAN_UP) {
115 close(rpm_fd); 100 close(rpm_fd);
116 } 101 }
117 102
118 return 0; 103#if SEAMLESS_COMPRESSION
104 return bb_got_signal;
105#else
106 return EXIT_SUCCESS;
107#endif
119} 108}