Re: [PATCH] mkswap: when writing the signature page, handle EINTR returns. | |
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] | |
On Fri, Apr 11, 2008 at 09:03:22AM -0600, LaMont Jones wrote:
> 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@xxxxxxxxxxxxx>
> ---
> disk-utils/mkswap.c | 25 +++++++++++++++++++++++--
> 1 files changed, 23 insertions(+), 2 deletions(-)
Thanks. I have committed a little different version.
Karel
>From db83e35c6a8189496a19b5868237c59ff34f8947 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@xxxxxxxxxx>
Date: Tue, 15 Apr 2008 00:35:05 +0200
Subject: [PATCH] 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@xxxxxxxxxxxxx>
Signed-off-by: Karel Zak <kzak@xxxxxxxxxx>
---
disk-utils/mkswap.c | 25 ++++++++++++++++++++++---
1 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c
index 12d9a16..dc3a3d3 100644
--- a/disk-utils/mkswap.c
+++ b/disk-utils/mkswap.c
@@ -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
--
1.5.4.1
--
Karel Zak <kzak@xxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
[Site Home] [Netdev] [Ethernet Bridging] [Linux Wireless] [Kernel Newbies] [Memory] [Security] [Linux for Hams] [Netfilter] [Bugtraq] [Rubini] [Photo] [Yosemite] [Yosemite News] [MIPS Linux] [ARM Linux] [Linux RAID] [Linux Admin] [Samba] [Video 4 Linux] [Linux Resources]