summaryrefslogtreecommitdiff
path: root/mysys/my_lock.c
diff options
context:
space:
mode:
authorthek@kpdesk.mysql.com <>2006-10-31 09:26:16 +0100
committerthek@kpdesk.mysql.com <>2006-10-31 09:26:16 +0100
commit12d8f2bf3122f23898e64d2eb37dd8dfc9a5f7b4 (patch)
treeb2d88349ef7e2524023ae7c58023a5574a064456 /mysys/my_lock.c
parent397f0df9ad2df62698d4c1824c965c4b884b990c (diff)
downloadmariadb-git-12d8f2bf3122f23898e64d2eb37dd8dfc9a5f7b4.tar.gz
Bug#22828 _my_b_read() ignores return values for my_seek() calls
- Because my_seek actually is capable of returning an error code we should exploit that in the best possible way. - There might be kernel errors or other errors we can't predict and capturing the return value of all system calls gives us better understanding of possible errors.
Diffstat (limited to 'mysys/my_lock.c')
-rw-r--r--mysys/my_lock.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/mysys/my_lock.c b/mysys/my_lock.c
index 8f915d6003a..c9641f46f5c 100644
--- a/mysys/my_lock.c
+++ b/mysys/my_lock.c
@@ -35,7 +35,14 @@
#include <nks/fsio.h>
#endif
- /* Lock a part of a file */
+/*
+ Lock a part of a file
+
+ RETURN VALUE
+ 0 Success
+ -1 An error has occured and 'my_errno' is set
+ to indicate the actual error code.
+*/
int my_lock(File fd, int locktype, my_off_t start, my_off_t length,
myf MyFlags)
@@ -104,10 +111,22 @@ int my_lock(File fd, int locktype, my_off_t start, my_off_t length,
#elif defined(HAVE_LOCKING)
/* Windows */
{
- my_bool error;
+ my_bool error= false;
pthread_mutex_lock(&my_file_info[fd].mutex);
- if (MyFlags & MY_SEEK_NOT_DONE)
- VOID(my_seek(fd,start,MY_SEEK_SET,MYF(MyFlags & ~MY_SEEK_NOT_DONE)));
+ if (MyFlags & MY_SEEK_NOT_DONE)
+ {
+ if( my_seek(fd,start,MY_SEEK_SET,MYF(MyFlags & ~MY_SEEK_NOT_DONE))
+ == MY_FILEPOS_ERROR )
+ {
+ /*
+ If my_seek fails my_errno will already contain an error code;
+ just unlock and return error code.
+ */
+ DBUG_PRINT("error",("my_errno: %d (%d)",my_errno,errno));
+ pthread_mutex_unlock(&my_file_info[fd].mutex);
+ DBUG_RETURN(-1);
+ }
+ }
error= locking(fd,locktype,(ulong) length) && errno != EINVAL;
pthread_mutex_unlock(&my_file_info[fd].mutex);
if (!error)
@@ -145,7 +164,17 @@ int my_lock(File fd, int locktype, my_off_t start, my_off_t length,
}
#else
if (MyFlags & MY_SEEK_NOT_DONE)
- VOID(my_seek(fd,start,MY_SEEK_SET,MYF(MyFlags & ~MY_SEEK_NOT_DONE)));
+ {
+ if (my_seek(fd,start,MY_SEEK_SET,MYF(MyFlags & ~MY_SEEK_NOT_DONE))
+ == MY_FILEPOS_ERROR)
+ {
+ /*
+ If an error has occured in my_seek then we will already
+ have an error code in my_errno; Just return error code.
+ */
+ DBUG_RETURN(-1);
+ }
+ }
if (lockf(fd,locktype,length) != -1)
DBUG_RETURN(0);
#endif /* HAVE_FCNTL */