]> err.no Git - util-linux/commitdiff
mkswap: when writing the signature page, handle EINTR returns
authorKarel Zak <kzak@redhat.com>
Mon, 14 Apr 2008 22:35:05 +0000 (00:35 +0200)
committerLaMont Jones <lamont@debian.org>
Tue, 15 Apr 2008 00:17:43 +0000 (18:17 -0600)
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>
disk-utils/mkswap.c

index 4b1becafbdace898d908ec264018f18af819f5b9..c1907fbdf8d419596c0a3e65b3438dd7a5f713d8 100644 (file)
@@ -488,6 +488,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;
@@ -730,9 +746,12 @@ 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