From 7bf6e0be806edfcd6accef52cb98cda61c347fd4 Mon Sep 17 00:00:00 2001 From: Wichert Akkerman Date: Sat, 9 Dec 2000 01:51:21 +0000 Subject: [PATCH] add support for using libz --- ChangeLog | 5 +- Makefile.conf.in | 9 ++-- configure.in | 18 +++++++ debian/changelog | 1 + debian/rules | 1 + dpkg-deb/Makefile.in | 4 +- dpkg-deb/build.c | 126 +++++++++++++++++++++++++++++-------------- dpkg-deb/extract.c | 26 +++++++++ 8 files changed, 144 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 76d103ef..679809ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,10 @@ Sat Dec 9 01:51:51 CET 2000 Wichert Akkerman Tue 05 Dec 07:43:05 CET 2000 peter karlsson * po/sv.po: Updated Swedish translation. + * Makefile.conf.in, configure.in: add new option to use libz + * dpkg-deb/Makefile.in, dpkg-deb/build.c, dpkg-deb/extract.c: use libz + if so desired + * debian/rules: default to using static libz Mon Dec 4 14:42:01 CET 2000 Wichert Akkerman @@ -33,7 +37,6 @@ Mon Dec 4 01:34:57 CET 2000 Wichert Akkerman + lib/parse.c: use memset to initialize fieldencountered + main/filesdb.c: use new read_fd_into_buf ->>>>>>> 1.231 Sun Dec 3 22:11:22 CET 2000 Wichert Akkerman * dpkg-deb/extract.c: apply one of Adams do_fd_copy patches diff --git a/Makefile.conf.in b/Makefile.conf.in index 651c8ad2..edfbbbec 100644 --- a/Makefile.conf.in +++ b/Makefile.conf.in @@ -54,15 +54,18 @@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ -SSD_LIBS = @SSD_LIBS@ - DEFS = @DEFS@ INCLUDE_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir) -I$(srcdir) -I../include -I.. -I. NLS_CFLAGS = -DLOCALEDIR=\"$(localedir)\" -I$(top_srcdir)/intl -I../intl NLS_LIBS = @INTLLIBS@ -ALL_CFLAGS = $(CFLAGS) $(DEFS) $(NLS_CFLAGS) $(INCLUDE_CFLAGS) +SSD_LIBS = @SSD_LIBS@ + +ZLIB_CFLAGS = @ZLIBCFLAGS@ +ZLIB_LIBS = @ZLIBLIBS@ + +ALL_CFLAGS = $(CFLAGS) $(DEFS) $(NLS_CFLAGS) $(INCLUDE_CFLAGS) $(ZLIB_CFLAGS) ALL_CXXFLAGS = $(ALL_CFLAGS) $(CXXFLAGS) .c.o: diff --git a/configure.in b/configure.in index 3fdce460..54d309b2 100644 --- a/configure.in +++ b/configure.in @@ -129,6 +129,24 @@ AC_CHECK_LIB(ps, proc_stat_list_create, SSD_LIBS="-lps $SSD_LIBS") AC_CHECK_LIB(shouldbeinlibc, fmt_past_time, SSD_LIBS="-lshouldbeinlibc $SSD_LIBS") AC_SUBST(SSD_LIBS) +AC_ARG_WITH(zlib, +[ --with-zlib use zlib for decompression of some gzip files], + [use_zlib=$withval], + [uze_zlib=no]) +if [ "$use_zlib" = "no" ] ; then + ZLIB_CFLAGS= + ZLIB_LIBS= +else + ZLIB_CFLAGS=-DUSE_ZLIB + if [ "$use_zlib" = "static" ] ; then + ZLIB_LIBS=-Wl,-Bstatic -lz -Wl,-Bdynamic + else + ZLIB_LIBS=-lz + fi +fi +AC_SUBST(ZLIB_CFLAGS) +AC_SUBST(ZLIB_LIBS) + AC_HAVE_SYSINFO AC_MEMINFO_IN_SYSINFO diff --git a/debian/changelog b/debian/changelog index 5810fd6e..51653673 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,6 +9,7 @@ dpkg (1.8.0) unstable; urgency=low * Speedups patches by Adam Heath * statoverride fixes by Robert Luberda, Closes: Bug#78436 * Add Linux S/390 support. Closes: Bug#79063 + * Using libz to decompress data instead of calling gzip -- Wichert Akkerman UNRELEASED diff --git a/debian/rules b/debian/rules index c438c2d0..017a772c 100755 --- a/debian/rules +++ b/debian/rules @@ -33,6 +33,7 @@ $(BUILD)/config.status: --sharedstatedir=/var/lib \ --localstatedir=/var/lib \ --with-admindir=/var/lib/dpkg \ + --with-zlib=static \ $(config_arg) clean: diff --git a/dpkg-deb/Makefile.in b/dpkg-deb/Makefile.in index 12fc0393..1d8e880a 100644 --- a/dpkg-deb/Makefile.in +++ b/dpkg-deb/Makefile.in @@ -4,8 +4,10 @@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ top_builddir = .. + include ../Makefile.conf + SOURCES = build.c extract.c info.c main.c OBJECTS = $(patsubst %.c, %.o, $(SOURCES)) @@ -39,5 +41,5 @@ install-doc: $(INSTALL_DATA) $(srcdir)/dpkg-deb.1 $(DESTDIR)$(man1dir) dpkg-deb: $(OBJECTS) ../lib/libdpkg.a - $(CC) $(LDFLAGS) -L../lib -o $@ $(OBJECTS) $(LIBS) $(NLS_LIBS) -ldpkg + $(CC) $(LDFLAGS) -L../lib -o $@ $(OBJECTS) $(LIBS) $(NLS_LIBS) $(ZLIB_LIBS) -ldpkg diff --git a/dpkg-deb/build.c b/dpkg-deb/build.c index 6e4add37..63f59418 100644 --- a/dpkg-deb/build.c +++ b/dpkg-deb/build.c @@ -34,6 +34,9 @@ #include #include #include +#ifdef USE_ZLIB +#include +#endif #include #include @@ -139,6 +142,55 @@ static void free_filist(struct _finfo* fi) { } } +int internalGzip(int fd1, int fd2, const char *compression, char *desc, ...) { + va_list al; + struct varbuf v; +#ifdef USE_ZLIB + gzFile gzfile; + char gzbuffer[4096]; + int gzactualwrite, actualread; + char combuf[6]; +#endif + + varbufinit(&v); + + va_start(al,desc); + varbufvprintf(&v, desc, al); + va_end(al); + + + if(compression != NULL) + if(*compression == '0') { + do_fd_copy(0, 1, -1, _("%s: no compression copy loop"), v.buf); + exit(0); + } +#ifdef USE_ZLIB + snprintf(combuf, sizeof(combuf), "w%c", *compression); + gzfile = gzdopen(1, combuf); + while((actualread = read(0,gzbuffer,sizeof(gzbuffer))) > 0) { + if (actualread < 0 ) { + if (errno == EINTR) continue; + ohshite(_("%s: internal gzip error: read: `%s'"), v.buf, strerror(errno)); + } + gzactualwrite= gzwrite(gzfile,gzbuffer,actualread); + if (gzactualwrite < 0 ) { + int gzerr = 0; + const char *errmsg = gzerror(gzfile, &gzerr); + if (gzerr == Z_ERRNO) { + if (errno == EINTR) continue; + errmsg= strerror(errno); + } + ohshite(_("%s: internal gzip error: write: `%s'"), v.buf, errmsg); + } + if (gzactualwrite != actualread) + ohshite(_("%s: internal gzip error: read(%i) != write(%i)"), v.buf, actualread, gzactualwrite); + } + exit(0); +#else + snprintf(combuf, sizeof(combuf), "-%cc", *compression); + execlp(GZIP,"gzip",combuf,(char*)0); ohshit(_("%s: failed to exec gzip %s"), v.buf, combuf); +#endif +} /* Overly complex function that builds a .deb file */ @@ -153,8 +205,8 @@ void do_build(const char *const *argv) { struct pkginfo *checkedinfo; struct arbitraryfield *field; FILE *ar, *gz, *cf; - int p1[2],p2[2], warns, errs, n, c, subdir, gzfd; - pid_t c1,c2,c3,c4,c5; + int p1[2],p2[2],p3[2], warns, errs, n, c, subdir, gzfd; + pid_t c1,c2,c3; struct stat controlstab, datastab, mscriptstab, debarstab; char conffilename[MAXCONFFILENAME+1]; time_t thetime= 0; @@ -335,7 +387,7 @@ void do_build(const char *const *argv) { /* And run gzip to compress our control archive */ if (!(c2= m_fork())) { m_dup2(p1[0],0); m_dup2(gzfd,1); close(p1[0]); close(gzfd); - execlp(GZIP,"gzip","-9c",(char*)0); ohshite(_("failed to exec gzip -9c")); + internalGzip(0, 1, "9", _("control")); } close(p1[0]); waitsubproc(c2,"gzip -9c",0); @@ -381,30 +433,11 @@ void do_build(const char *const *argv) { strcpy(tfbuf,envbuf); strcat(tfbuf,"/dpkg.XXXXXX"); } - /* We need to reorder the files so we can make sure that symlinks - * will not appear before their target. - */ - m_pipe(p2); - if (!(c4= m_fork())) { - m_dup2(p2[1],1); close(p2[0]); close(p2[1]); - if (chdir(directory)) ohshite(_("failed to chdir to `%.255s'"),directory); - execlp(FIND,"find",".","-path","./" BUILDCONTROLDIR,"-prune","-o","-print0",(char*)0); - ohshite(_("failed to exec find")); - } - close(p2[1]); - while ((fi=getfi(directory, p2[0]))!=NULL) - if (S_ISLNK(fi->st.st_mode)) - add_to_filist(fi,&symlist,&symlist_end); - else - add_to_filist(fi,&nosymlist,&nosymlist_end); - close(p2[0]); - waitsubproc(c4,"find",0); - /* Fork off a tar. We will feed it a list of filenames on stdin later. */ m_pipe(p1); m_pipe(p2); - if (!(c4= m_fork())) { + if (!(c1= m_fork())) { m_dup2(p1[0],0); close(p1[0]); close(p1[1]); m_dup2(p2[1],1); close(p2[0]); close(p2[1]); if (chdir(directory)) ohshite(_("failed to chdir to `%.255s'"),directory); @@ -414,36 +447,47 @@ void do_build(const char *const *argv) { close(p1[0]); close(p2[1]); /* Of course we should not forget to compress the archive as well.. */ - if (!(c5= m_fork())) { + if (!(c2= m_fork())) { char *combuf; close(p1[1]); m_dup2(p2[0],0); close(p2[0]); m_dup2(oldformatflag ? fileno(ar) : gzfd,1); - combuf = strdup("-9c"); - if(compression != NULL) { - if(*compression == '0') { - do_fd_copy(0, 1, -1, _("no compression copy loop")); - exit(0); - } - combuf[1] = *compression; - } - execlp(GZIP,"gzip",combuf,(char*)0); - ohshite(_("failed to exec gzip %s from tar -cf"), combuf); + internalGzip(0, 1, compression, _("control")); } close(p2[0]); - /* All the pipes are set, lets feed tar its filenames */ - for (fi= nosymlist;fi;fi= fi->next) - if (write(p1[1], fi->fn, strlen(fi->fn)+1) ==- 1) - ohshite(_("failed to write filename to tar pipe (data)")); + /* All the pipes are set, now lets run find, and start feeding + * filenames to tar. + */ + + m_pipe(p3); + if (!(c3= m_fork())) { + m_dup2(p3[1],1); close(p3[0]); close(p3[1]); + if (chdir(directory)) ohshite(_("failed to chdir to `%.255s'"),directory); + execlp(FIND,"find",".","-path","./" BUILDCONTROLDIR,"-prune","-o","-print0",(char*)0); + ohshite(_("failed to exec find")); + } + close(p3[1]); + /* We need to reorder the files so we can make sure that symlinks + * will not appear before their target. + */ + while ((fi=getfi(directory, p3[0]))!=NULL) + if (S_ISLNK(fi->st.st_mode)) + add_to_filist(fi,&symlist,&symlist_end); + else { + if (write(p1[1], fi->fn, strlen(fi->fn)+1) ==- 1) + ohshite(_("failed to write filename to tar pipe (data)")); + } + close(p3[0]); + waitsubproc(c3,"find",0); + for (fi= symlist;fi;fi= fi->next) if (write(p1[1], fi->fn, strlen(fi->fn)+1) == -1) ohshite(_("failed to write filename to tar pipe (data)")); /* All done, clean up wait for tar and gzip to finish their job */ close(p1[1]); - free_filist(nosymlist); free_filist(symlist); - waitsubproc(c5,"gzip -9c from tar -cf",0); - waitsubproc(c4,"tar -cf",0); + waitsubproc(c2,"gzip -9c from tar -cf",0); + waitsubproc(c1,"tar -cf",0); /* Okay, we have data.tar.gz as well now, add it to the ar wrapper */ if (!oldformatflag) { if (fstat(gzfd,&datastab)) ohshite("_(failed to fstat tmpfile (data))"); diff --git a/dpkg-deb/extract.c b/dpkg-deb/extract.c index dc4e072c..58d6416a 100644 --- a/dpkg-deb/extract.c +++ b/dpkg-deb/extract.c @@ -33,6 +33,9 @@ #include #include #include +#ifdef USE_ZLIB +#include +#endif #include #include @@ -105,6 +108,12 @@ void extracthalf(const char *debar, const char *directory, #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ > 0) fpos_t fpos; #endif +#ifdef USE_ZLIB + z_streamp gzstream = NULL; + gzFile gzfile; + char gzbuffer[4096]; + int gzactualread; +#endif ar= fopen(debar,"r"); if (!ar) ohshite(_("failed to read archive `%.255s'"),debar); if (fstat(fileno(ar),&stab)) ohshite(_("failed to fstat archive")); @@ -259,7 +268,24 @@ void extracthalf(const char *debar, const char *directory, m_dup2(readfromfd,0); if (admininfo) close(p1[0]); if (taroption) { m_dup2(p2[1],1); close(p2[0]); close(p2[1]); } +#ifdef USE_ZLIB + gzfile = gzdopen(0, "r"); + while ((gzactualread= gzread(gzfile,gzbuffer,sizeof(gzbuffer))) > 0) { + if (gzactualread < 0 ) { + int gzerr = 0; + const char *errmsg = gzerror(gzfile, &gzerr); + if (gzerr == Z_ERRNO) { + if (errno == EINTR) continue; + errmsg= strerror(errno); + } + ohshite(_("internal gzip error: `%s'"), errmsg); + } + write(1,gzbuffer,gzactualread); + } + exit(0); +#else execlp(GZIP,"gzip","-dc",(char*)0); ohshite(_("failed to exec gzip -dc")); +#endif } if (readfromfd != fileno(ar)) close(readfromfd); if (taroption) close(p2[1]); -- 2.39.5