mkswap: when writing the signature page, handle EINTR returns

If the signature page write bumps into EINTR, it should finish the
write, instead of dying.

Addresses-Ubuntu-Bug: 206113
Signed-off-by: LaMont Jones <lamont@canonical.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2008-04-15 00:35:05 +02:00
parent 00077d4d53
commit db83e35c6a
1 changed files with 22 additions and 3 deletions

View File

@ -465,6 +465,22 @@ check_mount(void) {
return 1;
}
static int
write_all(int fd, const void *buf, size_t count) {
while(count) {
ssize_t tmp = write(fd, buf, count);
if (tmp > 0) {
count -= tmp;
if (count)
buf += tmp;
} else if (errno != EINTR && errno != EAGAIN)
return -1;
}
return 0;
}
int
main(int argc, char ** argv) {
struct stat statbuf;
@ -711,9 +727,12 @@ use the -f option to force it.\n"),
offset = ((version == 0) ? 0 : 1024);
if (lseek(DEV, offset, SEEK_SET) != offset)
die(_("unable to rewind swap-device"));
if (write(DEV,(char*)signature_page+offset, pagesize-offset)
!= pagesize-offset)
die(_("unable to write signature page"));
if (write_all(DEV, (char *) signature_page + offset,
pagesize - offset) == -1) {
fprintf(stderr, _("%s: %s: unable to write signature page: %s"),
program_name, device_name, strerror(errno));
exit(1);
}
/*
* A subsequent swapon() will fail if the signature