1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
From 00de90b131fb6b6d92c91ff23e5dae45d1b66cd2 Mon Sep 17 00:00:00 2001
From: Stewart Smith <stewart@flamingspork.com>
Date: Tue, 7 Feb 2017 15:43:51 +1100
Subject: [PATCH] Correctly return EBADF in the case of EBADF
This was causing an issue with the MySQL 5.7.17 unit tests.
Namely, the overridden libc functions weren't checking file descriptor
validity, and if a caller *expected* to fail with EBADF rather than return
success, the caller would be rather disappointed.
Reported-by: Yura Sorokin
Fixes: https://github.com/stewartsmith/libeatmydata/issues/1
Signed-off-by: Stewart Smith <stewart@flamingspork.com>
Bug-Debian: https://bugs.debian.org/667965
---
libeatmydata/libeatmydata.c | 9 +++++++++
libeatmydata/test/eatmydatatest.c | 6 +++---
2 files changed, 12 insertions(+), 3 deletions(-)
--- a/libeatmydata/libeatmydata.c
+++ b/libeatmydata/libeatmydata.c
@@ -116,6 +116,9 @@
if (eatmydata_is_hungry()) {
if (pthread_testcancel)
pthread_testcancel();
+ if (fcntl(fd, F_GETFD) == -1) {
+ return -1;
+ }
errno= 0;
return 0;
}
@@ -192,6 +195,9 @@
if (eatmydata_is_hungry()) {
if (pthread_testcancel)
pthread_testcancel();
+ if (fcntl(fd, F_GETFD) == -1) {
+ return -1;
+ }
errno= 0;
return 0;
}
@@ -217,6 +223,9 @@
if (eatmydata_is_hungry()) {
if (pthread_testcancel)
pthread_testcancel();
+ if (fcntl(fd, F_GETFD) == -1) {
+ return -1;
+ }
errno= 0;
return 0;
}
--- a/libeatmydata/test/eatmydatatest.c
+++ b/libeatmydata/test/eatmydatatest.c
@@ -67,9 +67,6 @@
fd = open(DATAFILENAME, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR);
if (fd == -1)
perror("unable to open " DATAFILENAME);
- if (close(fd) == -1)
- perror("unable to close " DATAFILENAME " file descriptor");
- unlink(DATAFILENAME);
// Now test fsync and friends by feeding them an invalid file descriptor.
// System implementation should fail with EBADF while libeatmydata
@@ -82,6 +79,9 @@
fprintf(stderr, "%d test cases failed\n", failed_tests);
return 2;
}
+ if (close(fd) == -1)
+ perror("unable to close " DATAFILENAME " file descriptor");
+ unlink(DATAFILENAME);
return 0;
}
|