diff options
Diffstat (limited to 'innobase/os/os0file.c')
-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 92e7f1e4fc3..ff5b30bec0d 100644 --- a/innobase/os/os0file.c +++ b/innobase/os/os0file.c @@ -312,7 +312,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; @@ -369,6 +369,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) */ + /******************************************************************** Does error handling when a file operation fails. */ static @@ -781,7 +807,7 @@ try_again: } return(file); -#else +#else /* __WIN__ */ os_file_t file; int create_flag; ibool retry; @@ -826,12 +852,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__ */ } /******************************************************************** @@ -902,7 +933,7 @@ os_file_create_simple_no_error_handling( } return(file); -#else +#else /* __WIN__ */ os_file_t file; int create_flag; @@ -930,12 +961,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__ */ } /******************************************************************** @@ -1056,7 +1092,7 @@ try_again: } return(file); -#else +#else /* __WIN__ */ os_file_t file; int create_flag; ibool retry; @@ -1136,12 +1172,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__ */ } /*************************************************************************** |