The following commit has been merged in the master branch: commit 269bbee973c46e1be0aaef82cb7e19bbc9a95aa7 Author: Guillem Jover <guil...@debian.org> Date: Sat May 7 11:27:06 2011 +0200
libdpkg: Switch the compression filter functions to always return This makes the compression and decompression functions be closer to the buffer api, which always return. For non-blocking I/O, the caller has to setup a child process. When using external binaries, we make the filter functions setup that child process transparently so that the API is uniform. diff --git a/dpkg-deb/build.c b/dpkg-deb/build.c index 60318db..a88cb0e 100644 --- a/dpkg-deb/build.c +++ b/dpkg-deb/build.c @@ -475,6 +475,7 @@ do_build(const char *const *argv) c2 = subproc_fork(); if (!c2) { compress_filter(&compressor_gzip, p1[0], gzfd, 9, _("control member")); + exit(0); } close(p1[0]); subproc_wait_check(c2, "gzip -9c", 0); @@ -543,6 +544,7 @@ do_build(const char *const *argv) if (!c2) { close(p1[1]); compress_filter(compressor, p2[0], gzfd, compress_level, _("data member")); + exit(0); } close(p2[0]); diff --git a/dpkg-deb/extract.c b/dpkg-deb/extract.c index 5992bc8..b458c1f 100644 --- a/dpkg-deb/extract.c +++ b/dpkg-deb/extract.c @@ -282,6 +282,7 @@ extracthalf(const char *debar, const char *dir, const char *taroption, if (taroption) close(p2[0]); decompress_filter(decompressor, p1[0], p2_out, _("data")); + exit(0); } close(p1[0]); close(arfd); diff --git a/lib/dpkg/compress.c b/lib/dpkg/compress.c index 59c40df..2bf53c5 100644 --- a/lib/dpkg/compress.c +++ b/lib/dpkg/compress.c @@ -42,47 +42,51 @@ #include <dpkg/buffer.h> #include <dpkg/command.h> #include <dpkg/compress.h> +#include <dpkg/subproc.h> -static void DPKG_ATTR_NORET DPKG_ATTR_SENTINEL +static void DPKG_ATTR_SENTINEL fd_fd_filter(int fd_in, int fd_out, const char *desc, const char *file, ...) { va_list args; struct command cmd; + pid_t pid; - if (fd_in != 0) { - m_dup2(fd_in, 0); - close(fd_in); - } - if (fd_out != 1) { - m_dup2(fd_out, 1); - close(fd_out); - } + pid = subproc_fork(); + if (pid != 0) { + if (fd_in != 0) { + m_dup2(fd_in, 0); + close(fd_in); + } + if (fd_out != 1) { + m_dup2(fd_out, 1); + close(fd_out); + } - command_init(&cmd, file, desc); - command_add_arg(&cmd, file); - va_start(args, file); - command_add_argv(&cmd, args); - va_end(args); + command_init(&cmd, file, desc); + command_add_arg(&cmd, file); + va_start(args, file); + command_add_argv(&cmd, args); + va_end(args); - command_exec(&cmd); + command_exec(&cmd); + } + subproc_wait_check(pid, desc, 0); } /* * No compressor (pass-through). */ -static void DPKG_ATTR_NORET +static void decompress_none(int fd_in, int fd_out, const char *desc) { fd_fd_copy(fd_in, fd_out, -1, _("%s: decompression"), desc); - exit(0); } -static void DPKG_ATTR_NORET +static void compress_none(int fd_in, int fd_out, int compress_level, const char *desc) { fd_fd_copy(fd_in, fd_out, -1, _("%s: compression"), desc); - exit(0); } struct compressor compressor_none = { @@ -98,7 +102,7 @@ struct compressor compressor_none = { */ #ifdef WITH_ZLIB -static void DPKG_ATTR_NORET +static void decompress_gzip(int fd_in, int fd_out, const char *desc) { char buffer[4096]; @@ -130,11 +134,9 @@ decompress_gzip(int fd_in, int fd_out, const char *desc) if (close(fd_out)) ohshite(_("%s: internal gzip write error"), desc); - - exit(0); } -static void DPKG_ATTR_NORET +static void compress_gzip(int fd_in, int fd_out, int compress_level, const char *desc) { char buffer[4096]; @@ -177,17 +179,15 @@ compress_gzip(int fd_in, int fd_out, int compress_level, const char *desc) errmsg = zError(err); ohshit(_("%s: internal gzip write error: %s"), desc, errmsg); } - - exit(0); } #else -static void DPKG_ATTR_NORET +static void decompress_gzip(int fd_in, int fd_out, const char *desc) { fd_fd_filter(fd_in, fd_out, desc, GZIP, "-dc", NULL); } -static void DPKG_ATTR_NORET +static void compress_gzip(int fd_in, int fd_out, int compress_level, const char *desc) { char combuf[6]; @@ -210,7 +210,7 @@ struct compressor compressor_gzip = { */ #ifdef WITH_BZ2 -static void DPKG_ATTR_NORET +static void decompress_bzip2(int fd_in, int fd_out, const char *desc) { char buffer[4096]; @@ -242,11 +242,9 @@ decompress_bzip2(int fd_in, int fd_out, const char *desc) if (close(fd_out)) ohshite(_("%s: internal bzip2 write error"), desc); - - exit(0); } -static void DPKG_ATTR_NORET +static void compress_bzip2(int fd_in, int fd_out, int compress_level, const char *desc) { char buffer[4096]; @@ -294,17 +292,15 @@ compress_bzip2(int fd_in, int fd_out, int compress_level, const char *desc) * be safeā¢. */ if (close(fd_out)) ohshite(_("%s: internal bzip2 write error"), desc); - - exit(0); } #else -static void DPKG_ATTR_NORET +static void decompress_bzip2(int fd_in, int fd_out, const char *desc) { fd_fd_filter(fd_in, fd_out, desc, BZIP2, "-dc", NULL); } -static void DPKG_ATTR_NORET +static void compress_bzip2(int fd_in, int fd_out, int compress_level, const char *desc) { char combuf[6]; @@ -326,13 +322,13 @@ struct compressor compressor_bzip2 = { * Xz compressor. */ -static void DPKG_ATTR_NORET +static void decompress_xz(int fd_in, int fd_out, const char *desc) { fd_fd_filter(fd_in, fd_out, desc, XZ, "-dc", NULL); } -static void DPKG_ATTR_NORET +static void compress_xz(int fd_in, int fd_out, int compress_level, const char *desc) { char combuf[6]; @@ -353,13 +349,13 @@ struct compressor compressor_xz = { * Lzma compressor. */ -static void DPKG_ATTR_NORET +static void decompress_lzma(int fd_in, int fd_out, const char *desc) { fd_fd_filter(fd_in, fd_out, desc, XZ, "-dc", "--format=lzma", NULL); } -static void DPKG_ATTR_NORET +static void compress_lzma(int fd_in, int fd_out, int compress_level, const char *desc) { char combuf[6]; @@ -427,8 +423,6 @@ decompress_filter(struct compressor *compressor, int fd_in, int fd_out, va_end(args); compressor->decompress(fd_in, fd_out, desc.buf); - - exit(0); } void @@ -451,6 +445,4 @@ compress_filter(struct compressor *compressor, int fd_in, int fd_out, compressor = &compressor_none; compressor->compress(fd_in, fd_out, compress_level, desc.buf); - - exit(0); } diff --git a/lib/dpkg/compress.h b/lib/dpkg/compress.h index e1a266f..18f6573 100644 --- a/lib/dpkg/compress.h +++ b/lib/dpkg/compress.h @@ -34,10 +34,8 @@ struct compressor { const char *name; const char *extension; int default_level; - void (*compress)(int fd_in, int fd_out, int level, const char *desc) - DPKG_ATTR_NORET; - void (*decompress)(int fd_in, int fd_out, const char *desc) - DPKG_ATTR_NORET; + void (*compress)(int fd_in, int fd_out, int level, const char *desc); + void (*decompress)(int fd_in, int fd_out, const char *desc); }; struct compressor compressor_none; @@ -50,11 +48,11 @@ struct compressor *compressor_find_by_name(const char *name); struct compressor *compressor_find_by_extension(const char *name); void decompress_filter(struct compressor *comp, int fd_in, int fd_out, - const char *desc, ...) DPKG_ATTR_NORET + const char *desc, ...) DPKG_ATTR_PRINTF(4); void compress_filter(struct compressor *comp, int fd_in, int fd_out, int compress_level, const char *desc, ...) - DPKG_ATTR_NORET DPKG_ATTR_PRINTF(5); + DPKG_ATTR_PRINTF(5); DPKG_END_DECLS -- dpkg's main repository -- To UNSUBSCRIBE, email to debian-dpkg-cvs-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org