Loading adb_install.cpp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -42,7 +42,7 @@ set_usb_driver(bool enabled) { ui->Print("failed to open driver control: %s\n", strerror(errno)); ui->Print("failed to open driver control: %s\n", strerror(errno)); return; return; } } if (write(fd, enabled ? "1" : "0", 1) < 0) { if (TEMP_FAILURE_RETRY(write(fd, enabled ? "1" : "0", 1)) == -1) { ui->Print("failed to set driver control: %s\n", strerror(errno)); ui->Print("failed to set driver control: %s\n", strerror(errno)); } } if (close(fd) < 0) { if (close(fd) < 0) { Loading applypatch/applypatch.c +27 −24 Original line number Original line Diff line number Diff line Loading @@ -422,21 +422,20 @@ int WriteToPartition(unsigned char* data, size_t len, int attempt; int attempt; for (attempt = 0; attempt < 2; ++attempt) { for (attempt = 0; attempt < 2; ++attempt) { lseek(fd, start, SEEK_SET); if (TEMP_FAILURE_RETRY(lseek(fd, start, SEEK_SET)) == -1) { printf("failed seek on %s: %s\n", partition, strerror(errno)); return -1; } while (start < len) { while (start < len) { size_t to_write = len - start; size_t to_write = len - start; if (to_write > 1<<20) to_write = 1<<20; if (to_write > 1<<20) to_write = 1<<20; ssize_t written = write(fd, data+start, to_write); ssize_t written = TEMP_FAILURE_RETRY(write(fd, data+start, to_write)); if (written < 0) { if (written == -1) { if (errno == EINTR) { printf("failed write writing to %s: %s\n", partition, strerror(errno)); written = 0; } else { printf("failed write writing to %s (%s)\n", partition, strerror(errno)); return -1; return -1; } } } start += written; start += written; } } if (fsync(fd) != 0) { if (fsync(fd) != 0) { Loading @@ -460,13 +459,20 @@ int WriteToPartition(unsigned char* data, size_t len, // won't just be reading the cache. // won't just be reading the cache. sync(); sync(); int dc = open("/proc/sys/vm/drop_caches", O_WRONLY); int dc = open("/proc/sys/vm/drop_caches", O_WRONLY); write(dc, "3\n", 2); if (TEMP_FAILURE_RETRY(write(dc, "3\n", 2)) == -1) { printf("write to /proc/sys/vm/drop_caches failed: %s\n", strerror(errno)); } else { printf(" caches dropped\n"); } close(dc); close(dc); sleep(1); sleep(1); printf(" caches dropped\n"); // verify // verify lseek(fd, 0, SEEK_SET); if (TEMP_FAILURE_RETRY(lseek(fd, 0, SEEK_SET)) == -1) { printf("failed to seek back to beginning of %s: %s\n", partition, strerror(errno)); return -1; } unsigned char buffer[4096]; unsigned char buffer[4096]; start = len; start = len; size_t p; size_t p; Loading @@ -476,16 +482,13 @@ int WriteToPartition(unsigned char* data, size_t len, size_t so_far = 0; size_t so_far = 0; while (so_far < to_read) { while (so_far < to_read) { ssize_t read_count = read(fd, buffer+so_far, to_read-so_far); ssize_t read_count = if (read_count < 0) { TEMP_FAILURE_RETRY(read(fd, buffer+so_far, to_read-so_far)); if (errno == EINTR) { if (read_count == -1) { read_count = 0; } else { printf("verify read error %s at %zu: %s\n", printf("verify read error %s at %zu: %s\n", partition, p, strerror(errno)); partition, p, strerror(errno)); return -1; return -1; } } } if ((size_t)read_count < to_read) { if ((size_t)read_count < to_read) { printf("short verify read %s at %zu: %zd %zu %s\n", printf("short verify read %s at %zu: %zd %zu %s\n", partition, p, read_count, to_read, strerror(errno)); partition, p, read_count, to_read, strerror(errno)); Loading Loading @@ -625,8 +628,8 @@ ssize_t FileSink(const unsigned char* data, ssize_t len, void* token) { ssize_t done = 0; ssize_t done = 0; ssize_t wrote; ssize_t wrote; while (done < (ssize_t) len) { while (done < (ssize_t) len) { wrote = write(fd, data+done, len-done); wrote = TEMP_FAILURE_RETRY(write(fd, data+done, len-done)); if (wrote <= 0) { if (wrote == -1) { printf("error writing %d bytes: %s\n", (int)(len-done), strerror(errno)); printf("error writing %d bytes: %s\n", (int)(len-done), strerror(errno)); return done; return done; } } Loading fuse_sdcard_provider.c +7 −9 Original line number Original line Diff line number Diff line Loading @@ -36,20 +36,18 @@ struct file_data { static int read_block_file(void* cookie, uint32_t block, uint8_t* buffer, uint32_t fetch_size) { static int read_block_file(void* cookie, uint32_t block, uint8_t* buffer, uint32_t fetch_size) { struct file_data* fd = (struct file_data*)cookie; struct file_data* fd = (struct file_data*)cookie; if (lseek(fd->fd, block * fd->block_size, SEEK_SET) < 0) { off64_t offset = ((off64_t) block) * fd->block_size; printf("seek on sdcard failed: %s\n", strerror(errno)); if (TEMP_FAILURE_RETRY(lseek64(fd->fd, offset, SEEK_SET)) == -1) { fprintf(stderr, "seek on sdcard failed: %s\n", strerror(errno)); return -EIO; return -EIO; } } while (fetch_size > 0) { while (fetch_size > 0) { ssize_t r = read(fd->fd, buffer, fetch_size); ssize_t r = TEMP_FAILURE_RETRY(read(fd->fd, buffer, fetch_size)); if (r < 0) { if (r == -1) { if (r != -EINTR) { fprintf(stderr, "read on sdcard failed: %s\n", strerror(errno)); printf("read on sdcard failed: %s\n", strerror(errno)); return -EIO; return -EIO; } } r = 0; } fetch_size -= r; fetch_size -= r; buffer += r; buffer += r; } } Loading fuse_sideload.c +7 −9 Original line number Original line Diff line number Diff line Loading @@ -442,15 +442,13 @@ int run_fuse_sideload(struct provider_vtab* vtab, void* cookie, } } uint8_t request_buffer[sizeof(struct fuse_in_header) + PATH_MAX*8]; uint8_t request_buffer[sizeof(struct fuse_in_header) + PATH_MAX*8]; for (;;) { for (;;) { ssize_t len = read(fd.ffd, request_buffer, sizeof(request_buffer)); ssize_t len = TEMP_FAILURE_RETRY(read(fd.ffd, request_buffer, sizeof(request_buffer))); if (len < 0) { if (len == -1) { if (errno != EINTR) { perror("read request"); perror("read request"); if (errno == ENODEV) { if (errno == ENODEV) { result = -1; result = -1; break; break; } } } continue; continue; } } Loading Loading @@ -508,7 +506,7 @@ int run_fuse_sideload(struct provider_vtab* vtab, void* cookie, outhdr.len = sizeof(outhdr); outhdr.len = sizeof(outhdr); outhdr.error = result; outhdr.error = result; outhdr.unique = hdr->unique; outhdr.unique = hdr->unique; write(fd.ffd, &outhdr, sizeof(outhdr)); TEMP_FAILURE_RETRY(write(fd.ffd, &outhdr, sizeof(outhdr))); } } } } Loading minui/events.cpp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ */ #include <dirent.h> #include <dirent.h> #include <errno.h> #include <fcntl.h> #include <fcntl.h> #include <stdio.h> #include <stdio.h> #include <stdlib.h> #include <stdlib.h> Loading Loading @@ -165,7 +166,7 @@ void ev_dispatch(void) { int ev_get_input(int fd, uint32_t epevents, input_event* ev) { int ev_get_input(int fd, uint32_t epevents, input_event* ev) { if (epevents & EPOLLIN) { if (epevents & EPOLLIN) { ssize_t r = read(fd, ev, sizeof(*ev)); ssize_t r = TEMP_FAILURE_RETRY(read(fd, ev, sizeof(*ev))); if (r == sizeof(*ev)) { if (r == sizeof(*ev)) { return 0; return 0; } } Loading Loading
adb_install.cpp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -42,7 +42,7 @@ set_usb_driver(bool enabled) { ui->Print("failed to open driver control: %s\n", strerror(errno)); ui->Print("failed to open driver control: %s\n", strerror(errno)); return; return; } } if (write(fd, enabled ? "1" : "0", 1) < 0) { if (TEMP_FAILURE_RETRY(write(fd, enabled ? "1" : "0", 1)) == -1) { ui->Print("failed to set driver control: %s\n", strerror(errno)); ui->Print("failed to set driver control: %s\n", strerror(errno)); } } if (close(fd) < 0) { if (close(fd) < 0) { Loading
applypatch/applypatch.c +27 −24 Original line number Original line Diff line number Diff line Loading @@ -422,21 +422,20 @@ int WriteToPartition(unsigned char* data, size_t len, int attempt; int attempt; for (attempt = 0; attempt < 2; ++attempt) { for (attempt = 0; attempt < 2; ++attempt) { lseek(fd, start, SEEK_SET); if (TEMP_FAILURE_RETRY(lseek(fd, start, SEEK_SET)) == -1) { printf("failed seek on %s: %s\n", partition, strerror(errno)); return -1; } while (start < len) { while (start < len) { size_t to_write = len - start; size_t to_write = len - start; if (to_write > 1<<20) to_write = 1<<20; if (to_write > 1<<20) to_write = 1<<20; ssize_t written = write(fd, data+start, to_write); ssize_t written = TEMP_FAILURE_RETRY(write(fd, data+start, to_write)); if (written < 0) { if (written == -1) { if (errno == EINTR) { printf("failed write writing to %s: %s\n", partition, strerror(errno)); written = 0; } else { printf("failed write writing to %s (%s)\n", partition, strerror(errno)); return -1; return -1; } } } start += written; start += written; } } if (fsync(fd) != 0) { if (fsync(fd) != 0) { Loading @@ -460,13 +459,20 @@ int WriteToPartition(unsigned char* data, size_t len, // won't just be reading the cache. // won't just be reading the cache. sync(); sync(); int dc = open("/proc/sys/vm/drop_caches", O_WRONLY); int dc = open("/proc/sys/vm/drop_caches", O_WRONLY); write(dc, "3\n", 2); if (TEMP_FAILURE_RETRY(write(dc, "3\n", 2)) == -1) { printf("write to /proc/sys/vm/drop_caches failed: %s\n", strerror(errno)); } else { printf(" caches dropped\n"); } close(dc); close(dc); sleep(1); sleep(1); printf(" caches dropped\n"); // verify // verify lseek(fd, 0, SEEK_SET); if (TEMP_FAILURE_RETRY(lseek(fd, 0, SEEK_SET)) == -1) { printf("failed to seek back to beginning of %s: %s\n", partition, strerror(errno)); return -1; } unsigned char buffer[4096]; unsigned char buffer[4096]; start = len; start = len; size_t p; size_t p; Loading @@ -476,16 +482,13 @@ int WriteToPartition(unsigned char* data, size_t len, size_t so_far = 0; size_t so_far = 0; while (so_far < to_read) { while (so_far < to_read) { ssize_t read_count = read(fd, buffer+so_far, to_read-so_far); ssize_t read_count = if (read_count < 0) { TEMP_FAILURE_RETRY(read(fd, buffer+so_far, to_read-so_far)); if (errno == EINTR) { if (read_count == -1) { read_count = 0; } else { printf("verify read error %s at %zu: %s\n", printf("verify read error %s at %zu: %s\n", partition, p, strerror(errno)); partition, p, strerror(errno)); return -1; return -1; } } } if ((size_t)read_count < to_read) { if ((size_t)read_count < to_read) { printf("short verify read %s at %zu: %zd %zu %s\n", printf("short verify read %s at %zu: %zd %zu %s\n", partition, p, read_count, to_read, strerror(errno)); partition, p, read_count, to_read, strerror(errno)); Loading Loading @@ -625,8 +628,8 @@ ssize_t FileSink(const unsigned char* data, ssize_t len, void* token) { ssize_t done = 0; ssize_t done = 0; ssize_t wrote; ssize_t wrote; while (done < (ssize_t) len) { while (done < (ssize_t) len) { wrote = write(fd, data+done, len-done); wrote = TEMP_FAILURE_RETRY(write(fd, data+done, len-done)); if (wrote <= 0) { if (wrote == -1) { printf("error writing %d bytes: %s\n", (int)(len-done), strerror(errno)); printf("error writing %d bytes: %s\n", (int)(len-done), strerror(errno)); return done; return done; } } Loading
fuse_sdcard_provider.c +7 −9 Original line number Original line Diff line number Diff line Loading @@ -36,20 +36,18 @@ struct file_data { static int read_block_file(void* cookie, uint32_t block, uint8_t* buffer, uint32_t fetch_size) { static int read_block_file(void* cookie, uint32_t block, uint8_t* buffer, uint32_t fetch_size) { struct file_data* fd = (struct file_data*)cookie; struct file_data* fd = (struct file_data*)cookie; if (lseek(fd->fd, block * fd->block_size, SEEK_SET) < 0) { off64_t offset = ((off64_t) block) * fd->block_size; printf("seek on sdcard failed: %s\n", strerror(errno)); if (TEMP_FAILURE_RETRY(lseek64(fd->fd, offset, SEEK_SET)) == -1) { fprintf(stderr, "seek on sdcard failed: %s\n", strerror(errno)); return -EIO; return -EIO; } } while (fetch_size > 0) { while (fetch_size > 0) { ssize_t r = read(fd->fd, buffer, fetch_size); ssize_t r = TEMP_FAILURE_RETRY(read(fd->fd, buffer, fetch_size)); if (r < 0) { if (r == -1) { if (r != -EINTR) { fprintf(stderr, "read on sdcard failed: %s\n", strerror(errno)); printf("read on sdcard failed: %s\n", strerror(errno)); return -EIO; return -EIO; } } r = 0; } fetch_size -= r; fetch_size -= r; buffer += r; buffer += r; } } Loading
fuse_sideload.c +7 −9 Original line number Original line Diff line number Diff line Loading @@ -442,15 +442,13 @@ int run_fuse_sideload(struct provider_vtab* vtab, void* cookie, } } uint8_t request_buffer[sizeof(struct fuse_in_header) + PATH_MAX*8]; uint8_t request_buffer[sizeof(struct fuse_in_header) + PATH_MAX*8]; for (;;) { for (;;) { ssize_t len = read(fd.ffd, request_buffer, sizeof(request_buffer)); ssize_t len = TEMP_FAILURE_RETRY(read(fd.ffd, request_buffer, sizeof(request_buffer))); if (len < 0) { if (len == -1) { if (errno != EINTR) { perror("read request"); perror("read request"); if (errno == ENODEV) { if (errno == ENODEV) { result = -1; result = -1; break; break; } } } continue; continue; } } Loading Loading @@ -508,7 +506,7 @@ int run_fuse_sideload(struct provider_vtab* vtab, void* cookie, outhdr.len = sizeof(outhdr); outhdr.len = sizeof(outhdr); outhdr.error = result; outhdr.error = result; outhdr.unique = hdr->unique; outhdr.unique = hdr->unique; write(fd.ffd, &outhdr, sizeof(outhdr)); TEMP_FAILURE_RETRY(write(fd.ffd, &outhdr, sizeof(outhdr))); } } } } Loading
minui/events.cpp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ */ #include <dirent.h> #include <dirent.h> #include <errno.h> #include <fcntl.h> #include <fcntl.h> #include <stdio.h> #include <stdio.h> #include <stdlib.h> #include <stdlib.h> Loading Loading @@ -165,7 +166,7 @@ void ev_dispatch(void) { int ev_get_input(int fd, uint32_t epevents, input_event* ev) { int ev_get_input(int fd, uint32_t epevents, input_event* ev) { if (epevents & EPOLLIN) { if (epevents & EPOLLIN) { ssize_t r = read(fd, ev, sizeof(*ev)); ssize_t r = TEMP_FAILURE_RETRY(read(fd, ev, sizeof(*ev))); if (r == sizeof(*ev)) { if (r == sizeof(*ev)) { return 0; return 0; } } Loading