summaryrefslogtreecommitdiff
path: root/ioshark
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-04-19 09:12:15 -0700
committerElliott Hughes <enh@google.com>2019-04-19 09:12:15 -0700
commitc7c12932942faf1432d7309b517f1186c50ea7e6 (patch)
tree94dd72a40bce9f791849e230d77f56398b6fa679 /ioshark
parente751360ca4335cd79b76dcb546c4e4b9b3cd6706 (diff)
downloadextras-c7c12932942faf1432d7309b517f1186c50ea7e6.tar.gz
ioshark: fix posix_fadvise error checking.
posix_ and pthread_ routines [almost all] return errno values on failure. Also stop reporting errno when we can give a message instead. (This code should probably use error(3) instead, but that's a bigger cleanup and I'm not sure this isn't all dead code anyway.) Test: builds Change-Id: I11e5927e4d797cd213f574fe414c021829625483
Diffstat (limited to 'ioshark')
-rw-r--r--ioshark/ioshark_bench_subr.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/ioshark/ioshark_bench_subr.c b/ioshark/ioshark_bench_subr.c
index 8bc702ee..1f740616 100644
--- a/ioshark/ioshark_bench_subr.c
+++ b/ioshark/ioshark_bench_subr.c
@@ -22,7 +22,7 @@
#include <signal.h>
#include <string.h>
#include <sys/stat.h>
-#include <sys/errno.h>
+#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>
@@ -121,10 +121,9 @@ files_db_fsync_discard_files(void *handle)
openflags);
if (fd < 0) {
fprintf(stderr,
- "%s: open(%s %x) error %d\n",
+ "%s: open(%s %x): %m\n",
progname, db_node->filename,
- openflags,
- errno);
+ openflags);
exit(EXIT_FAILURE);
}
db_node->fd = fd;
@@ -207,9 +206,8 @@ files_db_unlink_files(void *handle)
db_node->fd = -1;
if (is_readonly_mount(db_node->filename, db_node->size) == 0) {
if (unlink(db_node->filename) < 0) {
- fprintf(stderr, "%s: Cannot unlink %s:%s\n",
- __func__, db_node->filename,
- strerror(errno));
+ fprintf(stderr, "%s: Cannot unlink %s: %m\n",
+ __func__, db_node->filename);
exit(EXIT_FAILURE);
}
}
@@ -278,8 +276,7 @@ create_file(char *path, size_t size, struct rw_bytes_s *rw_bytes)
fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644);
if (fd < 0) {
- fprintf(stderr, "%s Cannot create file %s, error = %d\n",
- progname, path, errno);
+ fprintf(stderr, "%s Cannot create file %s: %m\n", progname, path);
exit(EXIT_FAILURE);
}
while (size > 0) {
@@ -287,8 +284,7 @@ create_file(char *path, size_t size, struct rw_bytes_s *rw_bytes)
buf = get_buf(&buf, &buflen, n, 1);
if (write(fd, buf, n) < n) {
fprintf(stderr,
- "%s Cannot write file %s, error = %d\n",
- progname, path, errno);
+ "%s Cannot write file %s: %m\n", progname, path);
free(buf);
exit(EXIT_FAILURE);
}
@@ -297,14 +293,12 @@ create_file(char *path, size_t size, struct rw_bytes_s *rw_bytes)
}
free(buf);
if (fsync(fd) < 0) {
- fprintf(stderr, "%s Cannot fsync file %s, error = %d\n",
- progname, path, errno);
+ fprintf(stderr, "%s Cannot fsync file %s: %m\n", progname, path);
exit(EXIT_FAILURE);
}
- if (posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED) < 0) {
+ if ((errno = posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED)) != 0) {
fprintf(stderr,
- "%s Cannot fadvise(DONTNEED) file %s, error = %d\n",
- progname, path, errno);
+ "%s Cannot fadvise(DONTNEED) file %s: %m\n", progname, path);
exit(EXIT_FAILURE);
}
close(fd);
@@ -608,8 +602,7 @@ init_filename_cache(void)
MAP_SHARED | MAP_LOCKED | MAP_POPULATE,
fd, 0);
if (filename_cache == MAP_FAILED) {
- fprintf(stderr, "%s Can't fstat ioshark_filenames file: %s\n",
- progname, strerror(errno));
+ fprintf(stderr, "%s Can't fstat ioshark_filenames file: %m\n", progname);
exit(EXIT_FAILURE);
}
close(fd);