From b1e03c7786ad2eb0b3f677e08462f248f0921610 Mon Sep 17 00:00:00 2001 From: Wichert Akkerman Date: Sat, 9 Dec 2000 02:13:04 +0000 Subject: [PATCH] fd copy loop generalizations --- ChangeLog | 11 ++- include/dpkg-db.h | 3 +- include/dpkg.h.in | 11 ++- lib/mlib.c | 52 +++++------ lib/varbuf.c | 5 +- main/filesdb.c | 4 +- po/dpkg.pot | 225 ++++++++++++++++++++++++---------------------- 7 files changed, 164 insertions(+), 147 deletions(-) diff --git a/ChangeLog b/ChangeLog index 679809ac..96668ab3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,14 +1,17 @@ Sat Dec 9 01:51:51 CET 2000 Wichert Akkerman * archtable, scripts/dpkg-architecture.pl: add linux s/390 - -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 + * include/{dpkg-db.h,dpkg.h.in}, lib/mlib.c, lib/varbuf.c: generalize + fd copy loops + * main/filesdb.c: udpates to use read_fd_buf + +Tue 05 Dec 07:43:05 CET 2000 peter karlsson + + * po/sv.po: Updated Swedish translation. Mon Dec 4 14:42:01 CET 2000 Wichert Akkerman diff --git a/include/dpkg-db.h b/include/dpkg-db.h index 66931f6b..b800945f 100644 --- a/include/dpkg-db.h +++ b/include/dpkg-db.h @@ -229,7 +229,8 @@ void varbufinit(struct varbuf *v); void varbufreset(struct varbuf *v); void varbufextend(struct varbuf *v); void varbuffree(struct varbuf *v); -void varbufaddstr(struct varbuf *v, const char *s); +#define varbufaddstr(v, s) varbufaddbuf(v, s, strlen(s)) +extern void varbufaddbuf(struct varbuf *v, const void *s, const int l); /* varbufinit must be called exactly once before the use of each varbuf * (including before any call to varbuffree). diff --git a/include/dpkg.h.in b/include/dpkg.h.in index bb01a5df..b060b9c8 100644 --- a/include/dpkg.h.in +++ b/include/dpkg.h.in @@ -197,8 +197,15 @@ void m_pipe(int fds[2]); void checksubprocerr(int status, const char *description, int sigpipeok); void waitsubproc(pid_t pid, const char *description, int sigpipeok); -int do_fd_copy(int fd1, int fd2, int limit, char *desc, ...); -int read_fd_into_buf(int fd, char *buf, int limit, char *desc, ...); +#define FD_WRITE_BUF 0 +#define FD_WRITE_VBUF 1 +#define FD_WRITE_FD 2 + +typedef void (*do_fd_write_t)(char *, int, void *, char *); +#define do_fd_copy(fd1, fd2, limit, desc...) read_fd_combined(fd1, (void*)fd2, FD_WRITE_FD, limit, desc) +#define read_fd_buf(fd1, buf, limit, desc...) read_fd_combined(fd1, buf, FD_WRITE_BUF, limit, desc) +int read_fd_combined(int fd, void *buf, int type, int limit, char *desc, ...); +int do_fd_read(int fd1, int limit, do_fd_write_t write_proc, void *proc_data, char *desc); extern volatile int onerr_abort; diff --git a/lib/mlib.c b/lib/mlib.c index a78bf58c..d8a7d11e 100644 --- a/lib/mlib.c +++ b/lib/mlib.c @@ -124,43 +124,36 @@ void waitsubproc(pid_t pid, const char *description, int sigpipeok) { checksubprocerr(status,description,sigpipeok); } -typedef void (*do_fd_write_t)(char *, int, char *, void *data); typedef struct do_fd_copy_data { int fd; } do_fd_copy_data_t; typedef struct do_fd_buf_data { - char *buf; + void *buf; + int type; } do_fd_buf_data_t; -int do_fd_write_fd(char* buf, int length, void *proc_data, char *desc) { - do_fd_copy_data_t *data = (do_fd_copy_data_t *)proc_data; - if(write(data->fd, buf, length) < length) - ohshite(_("failed in do_fd_write_fd (%s)"), desc); -} - -int do_fd_copy(int fd1, int fd2, int limit, char *desc, ...) { - do_fd_copy_data_t data = { fd2 }; - va_list al; - struct varbuf v; - - varbufinit(&v); - - va_start(al,desc); - varbufvprintf(&v, desc, al); - va_end(al); - - do_fd_read(fd1, limit, do_fd_write_fd, &data, v.buf); - varbuffree(&v); -} - -int do_fd_write_buf(char *buf, int length, void *proc_data, char *desc) { +void do_fd_write_combined(char *buf, int length, void *proc_data, char *desc) { do_fd_buf_data_t *data = (do_fd_buf_data_t *)proc_data; - memcpy(data->buf, buf, length); - data->buf += length; + switch(data->type) { + case FD_WRITE_BUF: + memcpy(data->buf, buf, length); + data->buf += length; + break; + case FD_WRITE_VBUF: + varbufaddbuf((struct varbuf *)data->buf, buf, length); + data->buf += length; + break; + case FD_WRITE_FD: + if(write((int)data->buf, buf, length) < length) + ohshite(_("failed in do_fd_write_combined (%i, %s)"), FD_WRITE_FD, desc); + break; + default: + fprintf(stderr, _("unknown data type `%i' in do_fd_write_buf\n"), data->type); + } } -int read_fd_into_buf(int fd, char *buf, int limit, char *desc, ...) { - do_fd_buf_data_t data = { buf }; +int read_fd_combined(int fd, void *buf, int type, int limit, char *desc, ...) { + do_fd_buf_data_t data = { buf, type }; va_list al; struct varbuf v; @@ -170,10 +163,11 @@ int read_fd_into_buf(int fd, char *buf, int limit, char *desc, ...) { varbufvprintf(&v, desc, al); va_end(al); - do_fd_read(fd, limit, do_fd_write_buf, &data, v.buf); + do_fd_read(fd, limit, do_fd_write_combined, &data, v.buf); varbuffree(&v); } + int do_fd_read(int fd1, int limit, do_fd_write_t write_proc, void *proc_data, char *desc) { char *buf; int count, bufsize= 32768, bytesread= 0; diff --git a/lib/varbuf.c b/lib/varbuf.c index dabdbd00..a05ad7ab 100644 --- a/lib/varbuf.c +++ b/lib/varbuf.c @@ -65,9 +65,8 @@ void varbufvprintf(struct varbuf *v, char *fmt, va_list va) { } while (r >= v->size-ou-1); } -void varbufaddstr(struct varbuf *v, const char *s) { - int l, ou; - l= strlen(s); +void varbufaddbuf(struct varbuf *v, const void *s, const int l) { + int ou; ou= v->used; v->used += l; if (v->used >= v->size) varbufextend(v); diff --git a/main/filesdb.c b/main/filesdb.c index 8312f20b..02544c92 100644 --- a/main/filesdb.c +++ b/main/filesdb.c @@ -147,7 +147,7 @@ void ensure_packagefiles_available(struct pkginfo *pkg) { loaded_list = nfmalloc(stat_buf.st_size); loaded_list_end = loaded_list + stat_buf.st_size; - read_fd_into_buf(fileno(file), loaded_list, stat_buf.st_size, _("files list for package `%.250s'"), pkg->name); + read_fd_buf(fileno(file), loaded_list, stat_buf.st_size, _("files list for package `%.250s'"), pkg->name); lendp= &pkg->clientdata->files; thisline = loaded_list; @@ -346,7 +346,7 @@ void ensure_statoverrides(void) { loaded_list = nfmalloc(stab2.st_size); loaded_list_end = loaded_list + stab2.st_size; - read_fd_into_buf(fileno(file), loaded_list, stab2.st_size, _("statoverride file `%.250s'"), vb.buf); + read_fd_buf(fileno(file), loaded_list, stab2.st_size, _("statoverride file `%.250s'"), vb.buf); thisline = loaded_list; while (thisline\n" "Language-Team: LANGUAGE \n" @@ -452,21 +452,17 @@ msgstr "" msgid "wait for %s failed" msgstr "" -#: lib/mlib.c:137 +#: lib/mlib.c:138 #, c-format msgid "failed in do_fd_write_fd (%s)" msgstr "" -#: lib/mlib.c:142 -msgid "failed in do_fd_write_fd" -msgstr "" - -#: lib/mlib.c:195 +#: lib/mlib.c:183 #, c-format msgid "failed to allocate buffer in do_fd_read (%s)" msgstr "" -#: lib/mlib.c:215 +#: lib/mlib.c:202 #, c-format msgid "failed in do_fd_read on read (%s)" msgstr "" @@ -2631,116 +2627,141 @@ msgstr "" msgid "--forget-old-unavail takes no arguments" msgstr "" -#: dpkg-deb/build.c:63 +#: dpkg-deb/build.c:66 #, c-format msgid "dpkg-deb - error: %s (`%s') doesn't contain any digits\n" msgstr "" +#: dpkg-deb/build.c:164 +#, c-format +msgid "%s: no compression copy loop" +msgstr "" + +#: dpkg-deb/build.c:173 +#, c-format +msgid "%s: internal gzip error: read: `%s'" +msgstr "" + +#: dpkg-deb/build.c:183 +#, c-format +msgid "%s: internal gzip error: write: `%s'" +msgstr "" + +#: dpkg-deb/build.c:186 +#, c-format +msgid "%s: internal gzip error: read(%i) != write(%i)" +msgstr "" + +#: dpkg-deb/build.c:191 +#, c-format +msgid "%s: failed to exec gzip %s" +msgstr "" + #. Decode our arguments -#: dpkg-deb/build.c:168 +#: dpkg-deb/build.c:220 msgid "--build needs a directory argument" msgstr "" -#: dpkg-deb/build.c:177 +#: dpkg-deb/build.c:229 msgid "--build takes at most two arguments" msgstr "" -#: dpkg-deb/build.c:181 +#: dpkg-deb/build.c:233 #, c-format msgid "unable to check for existence of archive `%.250s'" msgstr "" -#: dpkg-deb/build.c:196 +#: dpkg-deb/build.c:248 msgid "target is directory - cannot skip control file check" msgstr "" -#: dpkg-deb/build.c:197 +#: dpkg-deb/build.c:249 #, c-format msgid "" "dpkg-deb: warning, not checking contents of control area.\n" "dpkg-deb: building an unknown package in `%s'.\n" msgstr "" -#: dpkg-deb/build.c:215 +#: dpkg-deb/build.c:267 msgid "package name has characters that aren't lowercase alphanums or `-+.'" msgstr "" -#: dpkg-deb/build.c:217 +#: dpkg-deb/build.c:269 #, c-format msgid "warning, `%s' contains user-defined Priority value `%s'\n" msgstr "" -#: dpkg-deb/build.c:222 +#: dpkg-deb/build.c:274 #, c-format msgid "warning, `%s' contains user-defined field `%s'\n" msgstr "" -#: dpkg-deb/build.c:228 +#: dpkg-deb/build.c:280 #, c-format msgid "%d errors in control file" msgstr "" -#: dpkg-deb/build.c:239 +#: dpkg-deb/build.c:291 #, c-format msgid "dpkg-deb: building package `%s' in `%s'.\n" msgstr "" -#: dpkg-deb/build.c:247 +#: dpkg-deb/build.c:299 #, c-format msgid "control directory has bad permissions %03lo (must be >=0755 and <=0775)" msgstr "" -#: dpkg-deb/build.c:258 +#: dpkg-deb/build.c:310 #, c-format msgid "maintainer script `%.50s' is not a plain file or symlink" msgstr "" -#: dpkg-deb/build.c:260 +#: dpkg-deb/build.c:312 #, c-format msgid "" "maintainer script `%.50s' has bad permissions %03lo (must be >=0555 and " "<=0775)" msgstr "" -#: dpkg-deb/build.c:264 +#: dpkg-deb/build.c:316 #, c-format msgid "maintainer script `%.50s' is not stattable" msgstr "" -#: dpkg-deb/build.c:274 +#: dpkg-deb/build.c:326 msgid "empty string from fgets reading conffiles" msgstr "" -#: dpkg-deb/build.c:276 +#: dpkg-deb/build.c:328 #, c-format msgid "" "warning, conffile name `%.50s...' is too long, or missing final newline\n" msgstr "" -#: dpkg-deb/build.c:288 +#: dpkg-deb/build.c:340 #, c-format msgid "conffile `%.250s' does not appear in package" msgstr "" -#: dpkg-deb/build.c:290 +#: dpkg-deb/build.c:342 #, c-format msgid "conffile `%.250s' is not stattable" msgstr "" -#: dpkg-deb/build.c:292 +#: dpkg-deb/build.c:344 #, c-format msgid "warning, conffile `%s' is not a plain file\n" msgstr "" -#: dpkg-deb/build.c:297 +#: dpkg-deb/build.c:349 msgid "error reading conffiles file" msgstr "" -#: dpkg-deb/build.c:300 +#: dpkg-deb/build.c:352 msgid "error opening conffiles file" msgstr "" -#: dpkg-deb/build.c:303 +#: dpkg-deb/build.c:355 #, c-format msgid "dpkg-deb: ignoring %d warnings about the control file(s)\n" msgstr "" @@ -2748,298 +2769,290 @@ msgstr "" #. Now that we have verified everything its time to actually #. * build something. Lets start by making the ar-wrapper. #. -#: dpkg-deb/build.c:312 +#: dpkg-deb/build.c:364 #, c-format msgid "unable to create `%.255s'" msgstr "" -#: dpkg-deb/build.c:313 +#: dpkg-deb/build.c:365 #, c-format msgid "unable to unbuffer `%.255s'" msgstr "" -#: dpkg-deb/build.c:318 dpkg-deb/build.c:390 dpkg-deb/build.c:410 +#: dpkg-deb/build.c:370 dpkg-deb/build.c:443 dpkg-deb/build.c:465 #, c-format msgid "failed to chdir to `%.255s'" msgstr "" -#: dpkg-deb/build.c:319 +#: dpkg-deb/build.c:371 msgid "failed to chdir to .../DEBIAN" msgstr "" -#: dpkg-deb/build.c:320 dpkg-deb/build.c:412 +#: dpkg-deb/build.c:372 dpkg-deb/build.c:445 msgid "failed to exec tar -cf" msgstr "" #. Create a temporary file to store the control data in. Immediately unlink #. * our temporary file so others can't mess with it. #. -#: dpkg-deb/build.c:326 +#: dpkg-deb/build.c:378 msgid "failed to make tmpfile (control)" msgstr "" -#: dpkg-deb/build.c:327 +#: dpkg-deb/build.c:379 #, c-format msgid "failed to open tmpfile (control), %s" msgstr "" #. make sure it's gone, the fd will remain until we close it -#: dpkg-deb/build.c:330 +#: dpkg-deb/build.c:382 #, c-format msgid "failed to unlink tmpfile (control), %s" msgstr "" -#: dpkg-deb/build.c:338 -msgid "failed to exec gzip -9c" +#: dpkg-deb/build.c:390 dpkg-deb/build.c:419 dpkg-deb/build.c:455 +msgid "control" msgstr "" -#: dpkg-deb/build.c:343 +#: dpkg-deb/build.c:395 msgid "failed to fstat tmpfile (control)" msgstr "" -#: dpkg-deb/build.c:366 +#: dpkg-deb/build.c:418 msgid "failed to rewind tmpfile (control)" msgstr "" -#: dpkg-deb/build.c:367 -msgid "control" -msgstr "" - -#: dpkg-deb/build.c:374 +#: dpkg-deb/build.c:426 msgid "failed to make tmpfile (data)" msgstr "" -#: dpkg-deb/build.c:375 +#: dpkg-deb/build.c:427 #, c-format msgid "failed to open tmpfile (data), %s" msgstr "" #. make sure it's gone, the fd will remain until we close it -#: dpkg-deb/build.c:378 +#: dpkg-deb/build.c:430 #, c-format msgid "failed to unlink tmpfile (data), %s" msgstr "" -#: dpkg-deb/build.c:392 +#: dpkg-deb/build.c:467 msgid "failed to exec find" msgstr "" -#: dpkg-deb/build.c:425 -msgid "no compression copy loop" -msgstr "" - -#: dpkg-deb/build.c:431 -#, c-format -msgid "failed to exec gzip %s from tar -cf" -msgstr "" - -#: dpkg-deb/build.c:437 dpkg-deb/build.c:440 +#: dpkg-deb/build.c:478 dpkg-deb/build.c:485 msgid "failed to write filename to tar pipe (data)" msgstr "" -#: dpkg-deb/build.c:458 +#: dpkg-deb/build.c:502 msgid "failed to rewind tmpfile (data)" msgstr "" -#: dpkg-deb/build.c:459 +#: dpkg-deb/build.c:503 msgid "cat (data)" msgstr "" -#: dpkg-deb/extract.c:48 +#: dpkg-deb/extract.c:51 msgid "failed to exec sh -c mv foo/* &c" msgstr "" -#: dpkg-deb/extract.c:55 +#: dpkg-deb/extract.c:58 #, c-format msgid "error reading %s from %.255s" msgstr "" -#: dpkg-deb/extract.c:57 +#: dpkg-deb/extract.c:60 #, c-format msgid "unexpected end of file in %s in %.255s" msgstr "" -#: dpkg-deb/extract.c:68 split/info.c:52 +#: dpkg-deb/extract.c:71 split/info.c:52 #, c-format msgid "file `%.250s' is corrupt - %.250s length contains nulls" msgstr "" -#: dpkg-deb/extract.c:75 split/info.c:43 +#: dpkg-deb/extract.c:78 split/info.c:43 #, c-format msgid "file `%.250s' is corrupt - bad digit (code %d) in %s" msgstr "" -#: dpkg-deb/extract.c:84 +#: dpkg-deb/extract.c:87 msgid "skipped member data" msgstr "" -#: dpkg-deb/extract.c:109 +#: dpkg-deb/extract.c:118 #, c-format msgid "failed to read archive `%.255s'" msgstr "" -#: dpkg-deb/extract.c:110 +#: dpkg-deb/extract.c:119 msgid "failed to fstat archive" msgstr "" -#: dpkg-deb/extract.c:111 +#: dpkg-deb/extract.c:120 msgid "version number" msgstr "" -#: dpkg-deb/extract.c:120 +#: dpkg-deb/extract.c:129 msgid "between members" msgstr "" -#: dpkg-deb/extract.c:122 split/info.c:94 +#: dpkg-deb/extract.c:131 split/info.c:94 #, c-format msgid "file `%.250s' is corrupt - bad magic at end of first header" msgstr "" -#: dpkg-deb/extract.c:126 +#: dpkg-deb/extract.c:135 #, c-format msgid "file `%.250s' is corrupt - negative member length %ld" msgstr "" -#: dpkg-deb/extract.c:130 +#: dpkg-deb/extract.c:139 #, c-format msgid "file `%.250s' is not a debian binary archive (try dpkg-split?)" msgstr "" -#: dpkg-deb/extract.c:133 +#: dpkg-deb/extract.c:142 msgid "header info member" msgstr "" -#: dpkg-deb/extract.c:136 +#: dpkg-deb/extract.c:145 msgid "archive has no newlines in header" msgstr "" -#: dpkg-deb/extract.c:139 +#: dpkg-deb/extract.c:148 msgid "archive has no dot in version number" msgstr "" -#: dpkg-deb/extract.c:142 +#: dpkg-deb/extract.c:151 #, c-format msgid "archive version %.250s not understood, get newer dpkg-deb" msgstr "" -#: dpkg-deb/extract.c:160 +#: dpkg-deb/extract.c:169 #, c-format msgid "file `%.250s' contains ununderstood data member %.*s, giving up" msgstr "" -#: dpkg-deb/extract.c:165 +#: dpkg-deb/extract.c:174 #, c-format msgid "file `%.250s' contains two control members, giving up" msgstr "" -#: dpkg-deb/extract.c:177 +#: dpkg-deb/extract.c:186 #, c-format msgid "" " new debian package, version %s.\n" " size %ld bytes: control archive= %ld bytes.\n" msgstr "" -#: dpkg-deb/extract.c:189 +#: dpkg-deb/extract.c:198 msgid "ctrl information length" msgstr "" -#: dpkg-deb/extract.c:191 +#: dpkg-deb/extract.c:200 #, c-format msgid "archive has malformatted ctrl len `%s'" msgstr "" -#: dpkg-deb/extract.c:194 +#: dpkg-deb/extract.c:203 #, c-format msgid "" " old debian package, version %s.\n" " size %ld bytes: control archive= %ld, main archive= %ld.\n" msgstr "" -#: dpkg-deb/extract.c:203 +#: dpkg-deb/extract.c:212 msgid "ctrlarea" msgstr "" -#: dpkg-deb/extract.c:209 +#: dpkg-deb/extract.c:218 msgid "" "dpkg-deb: file looks like it might be an archive which has been\n" "dpkg-deb: corrupted by being downloaded in ASCII mode\n" msgstr "" -#: dpkg-deb/extract.c:214 +#: dpkg-deb/extract.c:223 #, c-format msgid "`%.255s' is not a debian format archive" msgstr "" -#: dpkg-deb/extract.c:219 +#: dpkg-deb/extract.c:228 msgid "fgetpos failed" msgstr "" -#: dpkg-deb/extract.c:223 +#: dpkg-deb/extract.c:232 msgid "fsetpos failed" msgstr "" -#: dpkg-deb/extract.c:230 +#: dpkg-deb/extract.c:239 msgid "failed to fdopen p1 in paste" msgstr "" -#: dpkg-deb/extract.c:232 +#: dpkg-deb/extract.c:241 msgid "failed to write to gzip -dc" msgstr "" -#: dpkg-deb/extract.c:233 +#: dpkg-deb/extract.c:242 msgid "failed to close gzip -dc" msgstr "" -#: dpkg-deb/extract.c:240 +#: dpkg-deb/extract.c:249 msgid "failed to syscall lseek to files archive portion" msgstr "" -#: dpkg-deb/extract.c:248 +#: dpkg-deb/extract.c:257 msgid "failed to write to pipe in copy" msgstr "" -#: dpkg-deb/extract.c:249 +#: dpkg-deb/extract.c:258 msgid "failed to close pipe in copy" msgstr "" -#: dpkg-deb/extract.c:262 +#: dpkg-deb/extract.c:281 +#, c-format +msgid "internal gzip error: `%s'" +msgstr "" + +#: dpkg-deb/extract.c:287 msgid "failed to exec gzip -dc" msgstr "" -#: dpkg-deb/extract.c:270 +#: dpkg-deb/extract.c:296 msgid "failed to create directory" msgstr "" -#: dpkg-deb/extract.c:271 +#: dpkg-deb/extract.c:297 msgid "failed to chdir to directory after creating it" msgstr "" -#: dpkg-deb/extract.c:273 +#: dpkg-deb/extract.c:299 msgid "failed to chdir to directory" msgstr "" -#: dpkg-deb/extract.c:287 +#: dpkg-deb/extract.c:313 msgid "failed to exec tar" msgstr "" -#: dpkg-deb/extract.c:310 dpkg-deb/extract.c:325 dpkg-deb/info.c:66 +#: dpkg-deb/extract.c:336 dpkg-deb/extract.c:351 dpkg-deb/info.c:66 #, c-format msgid "--%s needs a .deb filename argument" msgstr "" -#: dpkg-deb/extract.c:313 +#: dpkg-deb/extract.c:339 #, c-format msgid "" "--%s needs a target directory.\n" "Perhaps you should be using dpkg --install ?" msgstr "" -#: dpkg-deb/extract.c:316 +#: dpkg-deb/extract.c:342 #, c-format msgid "--%s takes at most two arguments (.deb and directory)" msgstr "" -#: dpkg-deb/extract.c:327 +#: dpkg-deb/extract.c:353 #, c-format msgid "--%s takes only one argument (.deb filename)" msgstr "" -- 2.39.5