From 52e1b24975fe8f22d64e76521896c45142700673 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Tue, 1 Mar 2016 21:04:22 +0200 Subject: [PATCH] Rename and export MaxScaleUptime() MaxScaleUptime() renamed to maxscale_uptime() and moved from gateway.c (MaxScale main) to misc.c, which is included in the maxscale_common library. That way the symbol will be available at link-time and will thus not prevent the use of the linker flags -Wl,-z,defs (resolve all symbols at link-time) when linking a module that uses maxscale_uptime(). --- server/core/CMakeLists.txt | 2 +- server/core/gateway.c | 11 ++-------- server/core/misc.c | 41 ++++++++++++++++++++++++++++++++++++++ server/include/maxscale.h | 4 ++++ 4 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 server/core/misc.c diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index a183d6d00..fb6538619 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(maxscale-common SHARED adminusers.c atomic.c buffer.c config.c dbusers.c dcb.c filter.c externcmd.c gwbitmask.c gwdirs.c gw_utils.c hashtable.c hint.c housekeeper.c load_utils.c log_manager.cc maxscale_pcre2.c memlog.c mlist.c modutil.c monitor.c query_classifier.c poll.c random_jkiss.c resultset.c secrets.c server.c service.c session.c slist.c spinlock.c thread.c users.c utils.c ${CMAKE_SOURCE_DIR}/utils/skygw_utils.cc statistics.c) +add_library(maxscale-common SHARED adminusers.c atomic.c buffer.c config.c dbusers.c dcb.c filter.c externcmd.c gwbitmask.c gwdirs.c gw_utils.c hashtable.c hint.c housekeeper.c load_utils.c log_manager.cc maxscale_pcre2.c memlog.c misc.c mlist.c modutil.c monitor.c query_classifier.c poll.c random_jkiss.c resultset.c secrets.c server.c service.c session.c slist.c spinlock.c thread.c users.c utils.c ${CMAKE_SOURCE_DIR}/utils/skygw_utils.cc statistics.c) target_link_libraries(maxscale-common ${MARIADB_CONNECTOR_LIBRARIES} ${LZMA_LINK_FLAGS} ${PCRE2_LIBRARIES} ${CURL_LIBRARIES} ssl aio pthread crypt dl crypto inih z rt m stdc++) diff --git a/server/core/gateway.c b/server/core/gateway.c index d98f654c7..7fa193936 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -99,8 +99,6 @@ # define _GNU_SOURCE #endif -time_t MaxScaleStarted; - extern char *program_invocation_name; extern char *program_invocation_short_name; @@ -1293,6 +1291,8 @@ int main(int argc, char **argv) *maxlog_enabled = 1; *log_to_shm = 0; + maxscale_reset_uptime(); + sigemptyset(&sigpipe_mask); sigaddset(&sigpipe_mask, SIGPIPE); progname = *argv; @@ -1967,7 +1967,6 @@ int main(int argc, char **argv) if (daemon_mode) write_child_exit_code(daemon_pipe[1], rc); - MaxScaleStarted = time(0); /*< * Serve clients. */ @@ -2298,12 +2297,6 @@ static int write_pid_file() { return 0; } -int -MaxScaleUptime() -{ - return time(0) - MaxScaleStarted; -} - bool handle_path_arg(char** dest, char* path, char* arg, bool rd, bool wr) { char pathbuffer[PATH_MAX+2]; diff --git a/server/core/misc.c b/server/core/misc.c new file mode 100644 index 000000000..9cf681f59 --- /dev/null +++ b/server/core/misc.c @@ -0,0 +1,41 @@ +/* + * This file is distributed as part of the MariaDB Corporation MaxScale. It 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. + * + * 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-1301 USA. + * + * Copyright MariaDB Corporation Ab 2016 + * + */ + +#include +#include + +static time_t maxscale_started; + +/** + * Reset the start time from which the uptime is calculated. + */ +void maxscale_reset_uptime(void) +{ + maxscale_started = time(0); +} + +/** + * Return the time MaxScale has been running. + * + * @return The uptime in seconds. + */ +int maxscale_uptime() +{ + return time(0) - maxscale_started; +} diff --git a/server/include/maxscale.h b/server/include/maxscale.h index b178c45a8..ad790cd00 100644 --- a/server/include/maxscale.h +++ b/server/include/maxscale.h @@ -40,4 +40,8 @@ #define MAXSCALE_ALREADYRUNNING 4 /* MaxScale is already runing */ #define MAXSCALE_BADARG 5 /* Bad command line argument */ #define MAXSCALE_INTERNALERROR 6 /* Internal error, see error log */ + +void maxscale_reset_uptime(void); +int maxscale_uptime(void); + #endif