Просмотр исходного кода

Handle EINTR on reading and writting in buffer_copy.

Adam Heath лет назад: 25
Родитель
Сommit
296b46032b
3 измененных файлов с 56 добавлено и 35 удалено
  1. 4 0
      ChangeLog
  2. 29 16
      lib/mlib.c
  3. 23 19
      po/dpkg.pot

+ 4 - 0
ChangeLog

@@ -1,3 +1,7 @@
+Thu Dec 21 01:22:22 CST 2000 Adam Heath <doogie@debian.org>
+
+  * lib/mlib.c: Handle EINTR on reading and writting in buffer_copy.
+
 Thu Dec 21 06:58:21 CET 2000 peter karlsson <peterk@debian.org>
 
   * po/sv.po: The "Merry Christmas" update of the Swedish translation.

+ 29 - 16
lib/mlib.c

@@ -135,7 +135,7 @@ long buffer_write(buffer_data_t data, void *buf, long length, char *desc) {
       varbufaddbuf((struct varbuf *)data->data, buf, length);
       break;
     case BUFFER_WRITE_FD:
-      if((ret= write((int)data->data, buf, length)) < 0)
+      if((ret= write((int)data->data, buf, length)) < 0 && errno != EINTR)
 	ohshite(_("failed in buffer_write(fd) (%i, ret=%i, %s)"), (int)data->data, ret, desc);
       break;
     case BUFFER_WRITE_NULL:
@@ -157,7 +157,7 @@ long buffer_read(buffer_data_t data, void *buf, long length, char *desc) {
   long ret= length;
   switch(data->type) {
     case BUFFER_READ_FD:
-      if((ret= read((int)data->data, buf, length)) < 0)
+      if((ret= read((int)data->data, buf, length)) < 0 && errno != EINTR)
 	ohshite(_("failed in buffer_read(fd): %s"), desc);
       break;
     case BUFFER_READ_STREAM:
@@ -200,32 +200,45 @@ long buffer_copy_setup(void *argIn, int typeIn, void *procIn,
 
 
 long buffer_copy(buffer_data_t read_data, buffer_data_t write_data, long limit, char *desc) {
-  char *buf;
-  int count, bufsize= 32768;
-  long bytesread= 0;
-
+  char *buf, *writebuf;
+  long bytesread= 0, byteswritten= 0;
+  int bufsize= 32768;
+  long totalread= 0;
+  long totalwritten= 0;
   if((limit != -1) && (limit < bufsize)) bufsize= limit;
-  buf= malloc(bufsize);
-  if(buf== NULL) ohshite(_("failed to allocate buffer in do_fd_read (%s)"), desc);
+  writebuf= buf= malloc(bufsize);
+  if(buf== NULL) ohshite(_("failed to allocate buffer in buffer_copy (%s)"), desc);
 
-  while(bufsize) {
-    count= read_data->proc(read_data, buf, bufsize, desc);
-    if (count<0) {
+  while(bytesread >= 0 && byteswritten >= 0) {
+    bytesread= read_data->proc(read_data, buf, bufsize, desc);
+    if (bytesread<0) {
       if (errno==EINTR) continue;
       break;
     }
-    if (count==0)
+    if (bytesread==0)
       break;
 
-    bytesread+= count;
-    write_data->proc(write_data, buf, count, desc);
+    totalread+= bytesread;
     if(limit!=-1) {
-      limit-= count;
+      limit-= bytesread;
       if(limit<bufsize)
 	bufsize=limit;
     }
+    writebuf= buf;
+    while(bytesread) {
+      byteswritten= write_data->proc(write_data, writebuf, bytesread, desc);
+      if(byteswritten == -1) {
+	if(errno == EINTR) continue;
+	break;
+      }
+      if(byteswritten==0)
+	break;
+      bytesread-= byteswritten;
+      totalwritten+= byteswritten;
+      writebuf+= byteswritten;
+    }
   }
-  if (count<0) ohshite(_("failed in do_fd_read on read (%s)"), desc);
+  if (bytesread<0 || byteswritten<0) ohshite(_("failed in buffer_copy (%s)"), desc);
 
   free(buf);
   return bytesread;

+ 23 - 19
po/dpkg.pot

@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
-"POT-Creation-Date: 2000-12-20 02:40-0600\n"
+"POT-Creation-Date: 2000-12-21 01:21-0600\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -492,14 +492,14 @@ msgstr ""
 msgid "unknown data type `%i' in buffer_read\n"
 msgstr ""
 
-#: lib/mlib.c:209
+#: lib/mlib.c:210
 #, c-format
-msgid "failed to allocate buffer in do_fd_read (%s)"
+msgid "failed to allocate buffer in buffer_copy (%s)"
 msgstr ""
 
-#: lib/mlib.c:228
+#: lib/mlib.c:241
 #, c-format
-msgid "failed in do_fd_read on read (%s)"
+msgid "failed in buffer_copy (%s)"
 msgstr ""
 
 #: lib/myopt.c:39
@@ -2209,7 +2209,7 @@ msgstr ""
 msgid "failed to exec dpkg-deb"
 msgstr ""
 
-#: dpkg-deb/main.c:155 main/main.c:418 split/main.c:163
+#: dpkg-deb/main.c:156 main/main.c:419 split/main.c:163
 msgid "need an action option"
 msgstr ""
 
@@ -2384,65 +2384,69 @@ msgstr ""
 msgid "corrupted filesystem tarfile - corrupted package archive"
 msgstr ""
 
-#: main/processarc.c:619
+#: main/processarc.c:528
+msgid "dpkg-deb: zap possible trailing zeros"
+msgstr ""
+
+#: main/processarc.c:620
 #, c-format
 msgid "dpkg: warning - unable to delete old file `%.250s': %s\n"
 msgstr ""
 
-#: main/processarc.c:641 main/processarc.c:876 main/remove.c:287
+#: main/processarc.c:642 main/processarc.c:877 main/remove.c:287
 msgid "cannot read info directory"
 msgstr ""
 
-#: main/processarc.c:654
+#: main/processarc.c:655
 #, c-format
 msgid "old version of package has overly-long info file name starting `%.250s'"
 msgstr ""
 
-#: main/processarc.c:666
+#: main/processarc.c:667
 #, c-format
 msgid "unable to remove obsolete info file `%.250s'"
 msgstr ""
 
-#: main/processarc.c:669
+#: main/processarc.c:670
 #, c-format
 msgid "unable to install (supposed) new info file `%.250s'"
 msgstr ""
 
-#: main/processarc.c:676
+#: main/processarc.c:677
 msgid "unable to open temp control directory"
 msgstr ""
 
-#: main/processarc.c:685
+#: main/processarc.c:686
 #, c-format
 msgid "package contains overly-long control info file name (starting `%.50s')"
 msgstr ""
 
-#: main/processarc.c:690
+#: main/processarc.c:691
 #, c-format
 msgid "package control info contained directory `%.250s'"
 msgstr ""
 
-#: main/processarc.c:692
+#: main/processarc.c:693
 #, c-format
 msgid "package control info rmdir of `%.250s' didn't say not a dir"
 msgstr ""
 
-#: main/processarc.c:698
+#: main/processarc.c:699
 #, c-format
 msgid "dpkg: warning - package %s contained list as info file"
 msgstr ""
 
-#: main/processarc.c:705
+#: main/processarc.c:706
 #, c-format
 msgid "unable to install new info file `%.250s' as `%.250s'"
 msgstr ""
 
-#: main/processarc.c:856
+#: main/processarc.c:857
 #, c-format
 msgid "(Noting disappearance of %s, which has been completely replaced.)\n"
 msgstr ""
 
-#: main/processarc.c:892
+#: main/processarc.c:893
 #, c-format
 msgid "unable to delete disappearing control info file `%.250s'"
 msgstr ""