Merge "Always use strerror to report errno in recovery."
diff --git a/fuse_sideload.c b/fuse_sideload.c
index 4e11e01..1dd84e9 100644
--- a/fuse_sideload.c
+++ b/fuse_sideload.c
@@ -106,12 +106,12 @@
vec[0].iov_base = &hdr;
vec[0].iov_len = sizeof(hdr);
- vec[1].iov_base = data;
+ vec[1].iov_base = /* const_cast */(void*)(data);
vec[1].iov_len = len;
res = writev(fd->ffd, vec, 2);
if (res < 0) {
- printf("*** REPLY FAILED *** %d\n", errno);
+ printf("*** REPLY FAILED *** %s\n", strerror(errno));
}
}
@@ -430,7 +430,7 @@
char opts[256];
snprintf(opts, sizeof(opts),
- ("fd=%d,user_id=%d,group_id=%d,max_read=%zu,"
+ ("fd=%d,user_id=%d,group_id=%d,max_read=%u,"
"allow_other,rootmode=040000"),
fd.ffd, fd.uid, fd.gid, block_size);
diff --git a/mtdutils/mtdutils.c b/mtdutils/mtdutils.c
index d04b26e..9a17e38 100644
--- a/mtdutils/mtdutils.c
+++ b/mtdutils/mtdutils.c
@@ -313,8 +313,8 @@
memcpy(&before, &after, sizeof(struct mtd_ecc_stats));
} else if ((mgbb = ioctl(fd, MEMGETBADBLOCK, &pos))) {
fprintf(stderr,
- "mtd: MEMGETBADBLOCK returned %d at 0x%08llx (errno=%d)\n",
- mgbb, pos, errno);
+ "mtd: MEMGETBADBLOCK returned %d at 0x%08llx: %s\n",
+ mgbb, pos, strerror(errno));
} else {
return 0; // Success!
}
@@ -419,8 +419,8 @@
if (ret != 0 && !(ret == -1 && errno == EOPNOTSUPP)) {
add_bad_block_offset(ctx, pos);
fprintf(stderr,
- "mtd: not writing bad block at 0x%08lx (ret %d errno %d)\n",
- pos, ret, errno);
+ "mtd: not writing bad block at 0x%08lx (ret %d): %s\n",
+ pos, ret, strerror(errno));
pos += partition->erase_size;
continue; // Don't try to erase known factory-bad blocks.
}
diff --git a/updater/blockimg.c b/updater/blockimg.c
index 9c39634..90b55b2 100644
--- a/updater/blockimg.c
+++ b/updater/blockimg.c
@@ -464,7 +464,7 @@
if (directory == NULL) {
if (errno != ENOENT) {
- fprintf(stderr, "failed to opendir %s (errno %d)\n", dirname, errno);
+ fprintf(stderr, "opendir \"%s\" failed: %s\n", dirname, strerror(errno));
}
return;
}
@@ -495,7 +495,7 @@
}
if (closedir(directory) == -1) {
- fprintf(stderr, "failed to closedir %s (errno %d)\n", dirname, errno);
+ fprintf(stderr, "closedir \"%s\" failed: %s\n", dirname, strerror(errno));
}
}
@@ -508,7 +508,7 @@
}
if (stat(fn, &st) == -1) {
- fprintf(stderr, "failed to stat %s (errno %d)\n", fn, errno);
+ fprintf(stderr, "stat \"%s\" failed: %s\n", fn, strerror(errno));
return;
}
@@ -524,7 +524,7 @@
fprintf(stderr, "deleting %s\n", fn);
if (unlink(fn) == -1 && errno != ENOENT) {
- fprintf(stderr, "failed to unlink %s (errno %d)\n", fn, errno);
+ fprintf(stderr, "unlink \"%s\" failed: %s\n", fn, strerror(errno));
}
}
}
@@ -553,7 +553,7 @@
if (rmdir(dirname) == -1) {
if (errno != ENOENT && errno != ENOTDIR) {
- fprintf(stderr, "failed to rmdir %s (errno %d)\n", dirname, errno);
+ fprintf(stderr, "rmdir \"%s\" failed: %s\n", dirname, strerror(errno));
}
}
@@ -587,7 +587,7 @@
if (res == -1) {
if (errno != ENOENT || printnoent) {
- fprintf(stderr, "failed to stat %s (errno %d)\n", fn, errno);
+ fprintf(stderr, "stat \"%s\" failed: %s\n", fn, strerror(errno));
}
goto lsout;
}
@@ -602,7 +602,7 @@
fd = TEMP_FAILURE_RETRY(open(fn, O_RDONLY));
if (fd == -1) {
- fprintf(stderr, "failed to open %s (errno %d)\n", fn, errno);
+ fprintf(stderr, "open \"%s\" failed: %s\n", fn, strerror(errno));
goto lsout;
}
@@ -663,7 +663,7 @@
fd = TEMP_FAILURE_RETRY(open(fn, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC, STASH_FILE_MODE));
if (fd == -1) {
- fprintf(stderr, "failed to create %s (errno %d)\n", fn, errno);
+ fprintf(stderr, "failed to create \"%s\": %s\n", fn, strerror(errno));
goto wsout;
}
@@ -672,12 +672,12 @@
}
if (fsync(fd) == -1) {
- fprintf(stderr, "failed to fsync %s (errno %d)\n", fn, errno);
+ fprintf(stderr, "fsync \"%s\" failed: %s\n", fn, strerror(errno));
goto wsout;
}
if (rename(fn, cn) == -1) {
- fprintf(stderr, "failed to rename %s to %s (errno %d)\n", fn, cn, errno);
+ fprintf(stderr, "rename(\"%s\", \"%s\") failed: %s\n", fn, cn, strerror(errno));
goto wsout;
}
@@ -737,14 +737,14 @@
res = stat(dirname, &st);
if (res == -1 && errno != ENOENT) {
- ErrorAbort(state, "failed to stat %s (errno %d)\n", dirname, errno);
+ ErrorAbort(state, "stat \"%s\" failed: %s\n", dirname, strerror(errno));
goto csout;
} else if (res != 0) {
fprintf(stderr, "creating stash %s\n", dirname);
res = mkdir(dirname, STASH_DIRECTORY_MODE);
if (res != 0) {
- ErrorAbort(state, "failed to create %s (errno %d)\n", dirname, errno);
+ ErrorAbort(state, "mkdir \"%s\" failed: %s\n", dirname, strerror(errno));
goto csout;
}
@@ -1408,7 +1408,7 @@
}
if (fstat(params->fd, &st) == -1) {
- fprintf(stderr, "failed to fstat device to erase (errno %d)\n", errno);
+ fprintf(stderr, "failed to fstat device to erase: %s\n", strerror(errno));
goto pceout;
}
@@ -1437,7 +1437,7 @@
blocks[1] = (tgt->pos[i * 2 + 1] - tgt->pos[i * 2]) * (uint64_t) BLOCKSIZE;
if (ioctl(params->fd, BLKDISCARD, &blocks) == -1) {
- fprintf(stderr, "failed to blkdiscard (errno %d)\n", errno);
+ fprintf(stderr, "BLKDISCARD ioctl failed: %s\n", strerror(errno));
// Continue anyway, nothing we can do
}
}
@@ -1574,7 +1574,7 @@
params.fd = TEMP_FAILURE_RETRY(open(blockdev_filename->data, O_RDWR));
if (params.fd == -1) {
- fprintf(stderr, "failed to open %s: %s", blockdev_filename->data, strerror(errno));
+ fprintf(stderr, "open \"%s\" failed: %s\n", blockdev_filename->data, strerror(errno));
goto pbiudone;
}
@@ -1587,8 +1587,9 @@
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
- if (pthread_create(¶ms.thread, &attr, unzip_new_data, ¶ms.nti) != 0) {
- fprintf(stderr, "failed to create a thread (errno %d)\n", errno);
+ int error = pthread_create(¶ms.thread, &attr, unzip_new_data, ¶ms.nti);
+ if (error != 0) {
+ fprintf(stderr, "pthread_create failed: %s\n", strerror(error));
goto pbiudone;
}
}
@@ -1719,7 +1720,7 @@
pbiudone:
if (params.fd != -1) {
if (fsync(params.fd) == -1) {
- fprintf(stderr, "failed to fsync device (errno %d)\n", errno);
+ fprintf(stderr, "fsync failed: %s\n", strerror(errno));
}
TEMP_FAILURE_RETRY(close(params.fd));
}
@@ -1875,7 +1876,7 @@
int fd = open(blockdev_filename->data, O_RDWR);
if (fd < 0) {
- ErrorAbort(state, "failed to open %s: %s", blockdev_filename->data, strerror(errno));
+ ErrorAbort(state, "open \"%s\" failed: %s", blockdev_filename->data, strerror(errno));
goto done;
}