Skip to content
Browse files

Handle EINTR in write calls:

  * In low-level writers, just retry after EINTR
  * In archive_write, handle short writes by generating additional writes for the remainder of the block.

In particular, this fixes a problem with bsdtar failing if you try to use the SIGINT handler.

SVN-Revision: 2431
  • Loading branch information...
1 parent 571f1fb commit 55aec9a7b8f5a2b32a8dd6faa3cb2d24f10ce05c @kientzle kientzle committed May 31, 2010
View
20 libarchive/archive_write.c
@@ -361,11 +361,21 @@ archive_write_client_write(struct archive_write_filter *f,
remaining -= to_copy;
/* ... if it's full, write it out. */
if (state->avail == 0) {
- bytes_written = (a->client_writer)(&a->archive,
- a->client_data, state->buffer, state->buffer_size);
- if (bytes_written <= 0)
- return (ARCHIVE_FATAL);
- /* XXX TODO: if bytes_written < state->buffer_size */
+ char *p = state->buffer;
+ size_t to_write = state->buffer_size;
+ while (to_write > 0) {
+ bytes_written = (a->client_writer)(&a->archive,
+ a->client_data, p, to_write);
+ if (bytes_written <= 0)
+ return (ARCHIVE_FATAL);
+ if (bytes_written > to_write) {
+ archive_set_error(&(a->archive),
+ -1, "write overrun");
+ return (ARCHIVE_FATAL);
+ }
+ p += bytes_written;
+ to_write -= bytes_written;
+ }
state->next = state->buffer;
state->avail = state->buffer_size;
}
View
15 libarchive/archive_write_open_fd.c
@@ -51,7 +51,6 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_open_fd.c 201093 2009-12-2
#include "archive.h"
struct write_fd_data {
- off_t offset;
int fd;
};
@@ -122,12 +121,16 @@ file_write(struct archive *a, void *client_data, const void *buff, size_t length
ssize_t bytesWritten;
mine = (struct write_fd_data *)client_data;
- bytesWritten = write(mine->fd, buff, length);
- if (bytesWritten <= 0) {
- archive_set_error(a, errno, "Write error");
- return (-1);
+ for (;;) {
+ bytesWritten = write(mine->fd, buff, length);
+ if (bytesWritten <= 0) {
+ if (errno == EINTR)
+ continue;
+ archive_set_error(a, errno, "Write error");
+ return (-1);
+ }
+ return (bytesWritten);
}
- return (bytesWritten);
}
static int
View
14 libarchive/archive_write_open_file.c
@@ -86,12 +86,16 @@ file_write(struct archive *a, void *client_data, const void *buff, size_t length
size_t bytesWritten;
mine = client_data;
- bytesWritten = fwrite(buff, 1, length, mine->f);
- if (bytesWritten < length) {
- archive_set_error(a, errno, "Write error");
- return (-1);
+ for (;;) {
+ bytesWritten = fwrite(buff, 1, length, mine->f);
+ if (bytesWritten <= 0) {
+ if (errno == EINTR)
+ continue;
+ archive_set_error(a, errno, "Write error");
+ return (-1);
+ }
+ return (bytesWritten);
}
- return (bytesWritten);
}
static int
View
14 libarchive/archive_write_open_filename.c
@@ -142,12 +142,16 @@ file_write(struct archive *a, void *client_data, const void *buff, size_t length
ssize_t bytesWritten;
mine = (struct write_file_data *)client_data;
- bytesWritten = write(mine->fd, buff, length);
- if (bytesWritten <= 0) {
- archive_set_error(a, errno, "Write error");
- return (-1);
+ for (;;) {
+ bytesWritten = write(mine->fd, buff, length);
+ if (bytesWritten <= 0) {
+ if (errno == EINTR)
+ continue;
+ archive_set_error(a, errno, "Write error");
+ return (-1);
+ }
+ return (bytesWritten);
}
- return (bytesWritten);
}
static int

0 comments on commit 55aec9a

Please sign in to comment.
Something went wrong with that request. Please try again.