diff options
author | unknown <marko@hundin.mysql.fi> | 2004-05-05 11:40:17 +0300 |
---|---|---|
committer | unknown <marko@hundin.mysql.fi> | 2004-05-05 11:40:17 +0300 |
commit | f44fb5fd894180a8ed28f921bfd62f6cf87dbf90 (patch) | |
tree | f19cae3b561813e45707ad48b3e0028d4a728380 /innobase | |
parent | aee9a548864ee3cb9a2949f4df4a60fe6429ef15 (diff) | |
download | mariadb-git-f44fb5fd894180a8ed28f921bfd62f6cf87dbf90.tar.gz |
InnoDB: os0file.c: Lock files exclusively (Bug #3608)
innobase/os/os0file.c:
Lock files unless #defined __WIN__ or UNIV_HOTBACKUP (Bug #3608)
Diffstat (limited to 'innobase')
-rw-r--r-- | innobase/os/os0file.c | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/innobase/os/os0file.c b/innobase/os/os0file.c index 50c15bcbd41..904ddf13c8f 100644 --- a/innobase/os/os0file.c +++ b/innobase/os/os0file.c @@ -302,7 +302,7 @@ os_file_handle_error( /* out: TRUE if we should retry the operation */ os_file_t file, /* in: file pointer */ - char* name, /* in: name of a file or NULL */ + const char* name, /* in: name of a file or NULL */ const char* operation)/* in: operation */ { ulint err; @@ -358,6 +358,32 @@ os_file_handle_error( return(FALSE); } +#if !defined(__WIN__) && !defined(UNIV_HOTBACKUP) +/******************************************************************** +Obtain an exclusive lock on a file. */ +static +int +os_file_lock( +/*=========*/ + /* out: 0 on success */ + int fd, /* in: file descriptor */ + const char* name) /* in: file name */ +{ + struct flock lk; + lk.l_type = F_WRLCK; + lk.l_whence = SEEK_SET; + lk.l_start = lk.l_len = 0; + if (fcntl(fd, F_SETLK, &lk) == -1) { + fprintf(stderr, + "InnoDB: Unable to lock %s", name); + perror (": fcntl"); + close(fd); + return(-1); + } + return 0; +} +#endif /* !defined(__WIN__) && !defined(UNIV_HOTBACKUP) */ + /******************************************************************** Creates the seek mutexes used in positioned reads and writes. */ @@ -441,7 +467,7 @@ try_again: } return(file); -#else +#else /* __WIN__ */ os_file_t file; int create_flag; ibool retry; @@ -478,12 +504,17 @@ try_again: if (retry) { goto try_again; } +#ifndef UNIV_HOTBACKUP + } else if (os_file_lock(file, name)) { + *success = FALSE; + file = -1; +#endif } else { *success = TRUE; } return(file); -#endif +#endif /* __WIN__ */ } /******************************************************************** @@ -544,7 +575,7 @@ os_file_create_simple_no_error_handling( } return(file); -#else +#else /* __WIN__ */ os_file_t file; int create_flag; @@ -572,12 +603,17 @@ os_file_create_simple_no_error_handling( if (file == -1) { *success = FALSE; +#ifndef UNIV_HOTBACKUP + } else if (os_file_lock(file, name)) { + *success = FALSE; + file = -1; +#endif } else { *success = TRUE; } return(file); -#endif +#endif /* __WIN__ */ } /******************************************************************** @@ -689,7 +725,7 @@ try_again: } return(file); -#else +#else /* __WIN__ */ os_file_t file; int create_flag; ibool retry; @@ -772,12 +808,17 @@ try_again: if (retry) { goto try_again; } +#ifndef UNIV_HOTBACKUP + } else if (os_file_lock(file, name)) { + *success = FALSE; + file = -1; +#endif } else { *success = TRUE; } return(file); -#endif +#endif /* __WIN__ */ } /*************************************************************************** |