]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2fsck: Fix warn_unused_result warnings from gcc
authorTheodore Ts'o <tytso@mit.edu>
Wed, 22 Apr 2009 19:09:41 +0000 (15:09 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 22 Apr 2009 19:09:41 +0000 (15:09 -0400)
Fixed a potential bug where by partial returns from the write(2)
system call could lost characters to be sent to external progress bar
display program.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2fsck/e2fsck.h
e2fsck/unix.c
e2fsck/util.c

index a159f2a9305b1754c183748627ef3e82fb38726e..9a95cb0a3caa0d838c59defe5b961537f1b8c82c 100644 (file)
@@ -509,6 +509,7 @@ extern void mtrace_print(char *mesg);
 extern blk_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs,
                           const char *name, io_manager manager);
 extern int ext2_file_type(unsigned int mode);
+extern int write_all(int fd, char *buf, size_t count);
 
 /* unix.c */
 extern void e2fsck_clear_progbar(e2fsck_t ctx);
index 76baab7a02f2a632b76aa7e8c39024437523daa6..e39afdd7e30c7ab6b8e6ffd89c82f07c3eeb60b4 100644 (file)
@@ -488,7 +488,7 @@ static int e2fsck_update_progress(e2fsck_t ctx, int pass,
        if (ctx->progress_fd) {
                snprintf(buf, sizeof(buf), "%d %lu %lu %s\n",
                         pass, cur, max, ctx->device_name);
-               write(ctx->progress_fd, buf, strlen(buf));
+               write_all(ctx->progress_fd, buf, strlen(buf));
        } else {
                percent = calc_percent(&e2fsck_tbl, pass, cur, max);
                e2fsck_simple_progress(ctx, ctx->device_name,
index 6101d3c09d19d8ebdeaffa3508250737005de064..78c053cc52ffb724f21a718e3a754f2804deb39f 100644 (file)
@@ -680,3 +680,26 @@ int check_for_modules(const char *fs_name)
 #endif /* __linux__ */
        return (0);
 }
+
+/*
+ * Helper function that does the right thing if write returns a
+ * partial write, or an EGAIN/EINTR error.
+ */
+int write_all(int fd, char *buf, size_t count)
+{
+       ssize_t ret;
+       int c = 0;
+
+       while (count > 0) {
+               ret = write(fd, buf, count);
+               if (ret < 0) {
+                       if ((errno == EAGAIN) || (errno == EINTR))
+                               continue;
+                       return -1;
+               }
+               count -= ret;
+               buf += ret;
+               c += ret;
+       }
+       return c;
+}