From f8600b1755d1d8648bf677a159de8b0ff5f9f654 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Thu, 26 Oct 2023 18:12:09 +0200 Subject: [PATCH] MDEV-32567 Remove thr_alarm from server codebase Remove alarm() remnants - Replace thread-unsafe use of alarm() inside my_lock.c with a timed loop. - Remove configure time checks - Remove mysys my_alarm.c/my_alarm.h --- cmake/os/WindowsCache.cmake | 1 - config.h.cmake | 1 - configure.cmake | 1 - include/my_alarm.h | 69 ------------------------------------- mysys/CMakeLists.txt | 4 --- mysys/my_alarm.c | 33 ------------------ mysys/my_lock.c | 26 +++++++------- mysys/my_static.c | 5 --- 8 files changed, 12 insertions(+), 128 deletions(-) delete mode 100644 include/my_alarm.h delete mode 100644 mysys/my_alarm.c diff --git a/cmake/os/WindowsCache.cmake b/cmake/os/WindowsCache.cmake index 6cd19262a3c..e02c5b80a0c 100644 --- a/cmake/os/WindowsCache.cmake +++ b/cmake/os/WindowsCache.cmake @@ -22,7 +22,6 @@ IF(MSVC) SET(BFD_H_EXISTS 0 CACHE INTERNAL "") SET(HAVE_ACCESS 1 CACHE INTERNAL "") -SET(HAVE_ALARM CACHE INTERNAL "") SET(HAVE_ALLOCA_H CACHE INTERNAL "") SET(HAVE_ARPA_INET_H CACHE INTERNAL "") SET(HAVE_BACKTRACE CACHE INTERNAL "") diff --git a/config.h.cmake b/config.h.cmake index 460164b38a2..847dc7562e8 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -126,7 +126,6 @@ /* Functions we may want to use. */ #cmakedefine HAVE_ACCEPT4 1 #cmakedefine HAVE_ACCESS 1 -#cmakedefine HAVE_ALARM 1 #cmakedefine HAVE_ALLOCA 1 #cmakedefine HAVE_BFILL 1 #cmakedefine HAVE_INDEX 1 diff --git a/configure.cmake b/configure.cmake index 64d04ffe27a..ab44ff274fd 100644 --- a/configure.cmake +++ b/configure.cmake @@ -325,7 +325,6 @@ ENDIF() # CHECK_FUNCTION_EXISTS (accept4 HAVE_ACCEPT4) CHECK_FUNCTION_EXISTS (access HAVE_ACCESS) -CHECK_FUNCTION_EXISTS (alarm HAVE_ALARM) SET(HAVE_ALLOCA 1) CHECK_FUNCTION_EXISTS (backtrace HAVE_BACKTRACE) CHECK_FUNCTION_EXISTS (backtrace_symbols HAVE_BACKTRACE_SYMBOLS) diff --git a/include/my_alarm.h b/include/my_alarm.h deleted file mode 100644 index 652b460cba3..00000000000 --- a/include/my_alarm.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - Copyright (c) 2000, 2010, Oracle and/or its affiliates. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ - -/* - File to include when we want to use alarm or a loop_counter to display - some information when a program is running -*/ -#ifndef _my_alarm_h -#define _my_alarm_h -#ifdef __cplusplus -extern "C" { -#endif - -extern int volatile my_have_got_alarm; -extern ulong my_time_to_wait_for_lock; - -#if defined(HAVE_ALARM) && !defined(NO_ALARM_LOOP) -#include -#ifdef HAVE_SIGHANDLER_T -#define sig_return sighandler_t -#elif defined(SOLARIS) || defined(__sun) || defined(__APPLE__) || \ - defined(_AIX) || \ - defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ - defined(__DragonFly__) -typedef void (*sig_return)(int); /* Returns type from signal */ -#else -typedef void (*sig_return)(void); /* Returns type from signal */ -#endif -#define ALARM_VARIABLES uint alarm_old=0; \ - sig_return alarm_signal=0 -#define ALARM_INIT my_have_got_alarm=0 ; \ - alarm_old=(uint) alarm(MY_HOW_OFTEN_TO_ALARM); \ - alarm_signal=signal(SIGALRM,my_set_alarm_variable); -#define ALARM_END (void) signal(SIGALRM,alarm_signal); \ - (void) alarm(alarm_old); -#define ALARM_TEST my_have_got_alarm -#ifdef SIGNAL_HANDLER_RESET_ON_DELIVERY -#define ALARM_REINIT (void) alarm(MY_HOW_OFTEN_TO_ALARM); \ - (void) signal(SIGALRM,my_set_alarm_variable);\ - my_have_got_alarm=0; -#else -#define ALARM_REINIT (void) alarm((uint) MY_HOW_OFTEN_TO_ALARM); \ - my_have_got_alarm=0; -#endif /* SIGNAL_HANDLER_RESET_ON_DELIVERY */ -#else -#define ALARM_VARIABLES long alarm_pos=0,alarm_end_pos=MY_HOW_OFTEN_TO_WRITE-1 -#define ALARM_INIT -#define ALARM_END -#define ALARM_TEST (alarm_pos++ >= alarm_end_pos) -#define ALARM_REINIT (alarm_end_pos+=MY_HOW_OFTEN_TO_WRITE) -#endif /* HAVE_ALARM */ - -#ifdef __cplusplus -} -#endif -#endif diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index db1da49f84b..ad79480e710 100644 --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -158,10 +158,6 @@ IF(UNIX) SET (MYSYS_SOURCES ${MYSYS_SOURCES} my_addr_resolve.c my_setuser.c) ENDIF() -IF(HAVE_ALARM) - SET(MYSYS_SOURCES ${MYSYS_SOURCES} my_alarm.c) -ENDIF() - IF(HAVE_MLOCK) SET(MYSYS_SOURCES ${MYSYS_SOURCES} my_lockmem.c) ENDIF() diff --git a/mysys/my_alarm.c b/mysys/my_alarm.c deleted file mode 100644 index ee11dc9ce85..00000000000 --- a/mysys/my_alarm.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (C) 2000 MySQL AB - Use is subject to license terms - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ - -/* Function to set a varible when we got a alarm */ -/* Used by my_lock samt functions in m_alarm.h */ - - -#include "mysys_priv.h" -#include "my_alarm.h" - -#ifdef HAVE_ALARM - - /* ARGSUSED */ -sig_handler my_set_alarm_variable(int signo __attribute__((unused))) -{ - my_have_got_alarm=1; /* Tell program that time expired */ - return; -} - -#endif /* HAVE_ALARM */ diff --git a/mysys/my_lock.c b/mysys/my_lock.c index 7597436f381..35e159dd998 100644 --- a/mysys/my_lock.c +++ b/mysys/my_lock.c @@ -16,12 +16,8 @@ #include "mysys_priv.h" #include "mysys_err.h" #include -#undef MY_HOW_OFTEN_TO_ALARM -#define MY_HOW_OFTEN_TO_ALARM ((int) my_time_to_wait_for_lock) -#ifdef NO_ALARM_LOOP -#undef NO_ALARM_LOOP -#endif -#include +/* Wait timeout for short lock (2 seconds) */ +#define NANOSECONDS_TO_WAIT_FOR_LOCK 2000000000ULL #ifdef _WIN32 #define WIN_LOCK_INFINITE -1 @@ -139,7 +135,6 @@ int my_lock(File fd, int locktype, my_off_t start, my_off_t length, { #ifdef HAVE_FCNTL int value; - ALARM_VARIABLES; #endif DBUG_ENTER("my_lock"); @@ -171,6 +166,7 @@ int my_lock(File fd, int locktype, my_off_t start, my_off_t length, if (MyFlags & (MY_NO_WAIT | MY_SHORT_WAIT)) { + ulonglong end_time; if (fcntl(fd,F_SETLK,&lock) != -1) /* Check if we can lock */ DBUG_RETURN(0); /* Ok, file locked */ if (MyFlags & MY_NO_WAIT) @@ -179,14 +175,16 @@ int my_lock(File fd, int locktype, my_off_t start, my_off_t length, DBUG_RETURN(-1); } - DBUG_PRINT("info",("Was locked, trying with alarm")); - ALARM_INIT; - while ((value=fcntl(fd,F_SETLKW,&lock)) && ! ALARM_TEST && - errno == EINTR) - { /* Setup again so we don`t miss it */ - ALARM_REINIT; + DBUG_PRINT("info",("Was locked, trying with timeout")); + end_time= my_interval_timer() + NANOSECONDS_TO_WAIT_FOR_LOCK; + while ((value= fcntl(fd, F_SETLKW, &lock)) == -1) + { + if (errno != EACCES && errno != EAGAIN && errno != EINTR) + break; + if (my_interval_timer() > end_time) + break; + my_sleep(1000); } - ALARM_END; if (value != -1) DBUG_RETURN(0); if (errno == EINTR) diff --git a/mysys/my_static.c b/mysys/my_static.c index d0f20a5cc9c..35e67693e15 100644 --- a/mysys/my_static.c +++ b/mysys/my_static.c @@ -21,8 +21,6 @@ #include "mysys_priv.h" #include "my_static.h" -#include "my_alarm.h" - PSI_memory_key key_memory_DYNAMIC_STRING; PSI_memory_key key_memory_IO_CACHE; @@ -95,9 +93,6 @@ const char *soundex_map= "01230120022455012623010202"; USED_MEM* my_once_root_block=0; /* pointer to first block */ uint my_once_extra=ONCE_ALLOC_INIT; /* Memory to alloc / block */ - /* from my_alarm */ -int volatile my_have_got_alarm=0; /* declare variable to reset */ -ulong my_time_to_wait_for_lock=2; /* In seconds */ /* from errors.c */ #ifdef SHARED_LIBRARY