Skip to content

Commit

Permalink
Merge pull request #4502 from sysown/v2.6.x-freebsd_fixes_2
Browse files Browse the repository at this point in the history
Use of function pointer for SIGUSR1 handler
  • Loading branch information
renecannao authored Apr 11, 2024
2 parents 9ac7634 + 42178f8 commit c6c370d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
3 changes: 1 addition & 2 deletions include/proxysql_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,6 @@ class ProxySQL_Admin {
friend void admin_session_handler(MySQL_Session *sess, void *_pa, PtrSize_t *pkt);

// FLUSH LOGS
void install_signal_handler();
bool flush_logs();
void flush_logs();
};
#endif /* __CLASS_PROXYSQL_ADMIN_H */
19 changes: 8 additions & 11 deletions lib/ProxySQL_Admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ extern MySQL_Logger *GloMyLogger;
extern MySQL_STMT_Manager_v14 *GloMyStmt;
extern MySQL_Monitor *GloMyMon;

extern void (*flush_logs_function)();

extern Web_Interface *GloWebInterface;

extern ProxySQL_Cluster *GloProxyCluster;
Expand Down Expand Up @@ -1552,19 +1554,11 @@ bool admin_handler_command_kill_connection(char *query_no_space, unsigned int qu
return false;
}

static void flush_logs_handler(int sig) {
proxy_info("Received SIGUSR1 signal: flushing logs...\n");
/*
Support system logging facilities sending SIGUSR1 to do log rotation
*/
static void flush_logs_handler() {
GloAdmin->flush_logs();
}

void ProxySQL_Admin::install_signal_handler() {
signal(SIGUSR1, flush_logs_handler);
}

bool ProxySQL_Admin::flush_logs() {
void ProxySQL_Admin::flush_logs() {
if (GloMyLogger) {
GloMyLogger->flush_log();
}
Expand All @@ -1581,7 +1575,6 @@ bool ProxySQL_Admin::flush_logs() {
}
free(ssl_keylog_file);
}
return false;
}

/*
Expand Down Expand Up @@ -6397,6 +6390,10 @@ int check_if_user_config(SQLite3DB* admindb, const char* query) {
bool ProxySQL_Admin::init(const bootstrap_info_t& bootstrap_info) {
cpu_timer cpt;

if (flush_logs_function == NULL) {
flush_logs_function = flush_logs_handler;
}

Admin_HTTP_Server = NULL;
AdminHTTPServer = new ProxySQL_HTTP_Server();
AdminHTTPServer->init();
Expand Down
13 changes: 13 additions & 0 deletions lib/ProxySQL_GloVars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@

extern MySQL_LDAP_Authentication* GloMyLdapAuth;

void (*flush_logs_function)() = NULL;

/*
Support system logging facilities sending SIGUSR1 to do log rotation
*/
static void log_handler(int sig) {
proxy_info("Received SIGUSR1 signal: flushing logs...\n");
if (flush_logs_function != NULL) {
flush_logs_function();
}
}

static void term_handler(int sig) {
proxy_warning("Received TERM signal: shutdown in progress...\n");
/*
Expand Down Expand Up @@ -299,6 +311,7 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() :
};

void ProxySQL_GlobalVariables::install_signal_handler() {
signal(SIGUSR1, log_handler);
signal(SIGTERM, term_handler);
signal(SIGSEGV, crash_handler);
signal(SIGABRT, crash_handler);
Expand Down
4 changes: 0 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ ProxySQL_Cluster *GloProxyCluster = NULL;

ProxySQL_Statistics *GloProxyStats = NULL;


void * mysql_worker_thread_func(void *arg) {

// __thr_sfp=l_mem_init();
Expand Down Expand Up @@ -1898,7 +1897,6 @@ void handleProcessRestart() {
parent_open_error_log();
GloVars.global.start_time=monotonic_time();
GloVars.install_signal_handler();
GloAdmin->install_signal_handler();
}
} while (pid > 0);
}
Expand Down Expand Up @@ -2306,7 +2304,6 @@ int main(int argc, const char * argv[]) {
cpu_timer t;
GloVars.global.start_time=monotonic_time();
GloVars.install_signal_handler();
GloAdmin->install_signal_handler();
if (ProxySQL_daemonize_phase2()==false) {
goto finish;
}
Expand All @@ -2323,7 +2320,6 @@ int main(int argc, const char * argv[]) {
} else {
GloAdmin->flush_error_log();
GloVars.install_signal_handler();
GloAdmin->install_signal_handler();
}

__start_label:
Expand Down

0 comments on commit c6c370d

Please sign in to comment.