diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c133c311..d58980f51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,10 +15,11 @@ check_dirs() set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/modules) -configure_file(${CMAKE_SOURCE_DIR}/server/include/version.h.in ${CMAKE_SOURCE_DIR}/server/include/version.h) -configure_file(${CMAKE_SOURCE_DIR}/maxscale.conf.in ${CMAKE_SOURCE_DIR}/maxscale.conf.prep @ONLY) -configure_file(${CMAKE_SOURCE_DIR}/etc/init.d/maxscale.in ${CMAKE_SOURCE_DIR}/etc/init.d/maxscale.prep @ONLY) -configure_file(${CMAKE_SOURCE_DIR}/etc/ubuntu/init.d/maxscale.in ${CMAKE_SOURCE_DIR}/etc/ubuntu/init.d/maxscale.prep @ONLY) +file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/server/include) +configure_file(${CMAKE_SOURCE_DIR}/server/include/version.h.in ${CMAKE_BINARY_DIR}/server/include/version.h) +configure_file(${CMAKE_SOURCE_DIR}/maxscale.conf.in ${CMAKE_BINARY_DIR}/maxscale.conf.prep @ONLY) +configure_file(${CMAKE_SOURCE_DIR}/etc/init.d/maxscale.in ${CMAKE_BINARY_DIR}/etc/init.d/maxscale.prep @ONLY) +configure_file(${CMAKE_SOURCE_DIR}/etc/ubuntu/init.d/maxscale.in ${CMAKE_BINARY_DIR}/etc/ubuntu/init.d/maxscale.prep @ONLY) set(CMAKE_C_FLAGS "-Wall -fPIC") @@ -71,6 +72,7 @@ include_directories(query_classifier) include_directories(server/include) include_directories(server/inih) include_directories(server/modules/include) +include_directories(${CMAKE_BINARY_DIR}/server/include) add_subdirectory(utils) add_subdirectory(log_manager) @@ -82,11 +84,11 @@ add_subdirectory(client) # Install startup scripts and ldconfig files if( NOT ( (DEFINED INSTALL_SYSTEM_FILES) AND ( NOT ( INSTALL_SYSTEM_FILES ) ) ) ) - install(FILES maxscale.conf.prep RENAME maxscale.conf DESTINATION /etc/ld.so.conf.d/ PERMISSIONS WORLD_EXECUTE WORLD_READ) + install(FILES ${CMAKE_BINARY_DIR}/maxscale.conf.prep RENAME maxscale.conf DESTINATION /etc/ld.so.conf.d/ PERMISSIONS WORLD_EXECUTE WORLD_READ) if(DEB_BASED) - install(FILES etc/ubuntu/init.d/maxscale.prep RENAME maxscale DESTINATION /etc/init.d/ PERMISSIONS WORLD_EXECUTE) + install(FILES ${CMAKE_BINARY_DIR}/etc/ubuntu/init.d/maxscale.prep RENAME maxscale DESTINATION /etc/init.d/ PERMISSIONS WORLD_EXECUTE) else() - install(FILES etc/init.d/maxscale.prep RENAME maxscale DESTINATION /etc/init.d/ PERMISSIONS WORLD_EXECUTE) + install(FILES ${CMAKE_BINARY_DIR}/etc/init.d/maxscale.prep RENAME maxscale DESTINATION /etc/init.d/ PERMISSIONS WORLD_EXECUTE) endif() message(STATUS "Installing maxscale.conf to: /etc/ld.so.conf.d") message(STATUS "Installing startup scripts to: /etc/init.d") @@ -148,4 +150,14 @@ add_custom_target(testall COMMAND /bin/sh -c "${CMAKE_BINARY_DIR}/bin/maxscale -c ${CMAKE_BINARY_DIR} &>/dev/null" COMMAND /bin/sh -c "make test || echo \"Test results written to: ${CMAKE_BINARY_DIR}/Testing/Temporary/\"" COMMAND killall maxscale - COMMENT "Running full test suite..." VERBATIM) \ No newline at end of file + COMMENT "Running full test suite..." VERBATIM) + +# uninstall target +# see http://www.cmake.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + +add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) \ No newline at end of file diff --git a/cmake_uninstall.cmake.in b/cmake_uninstall.cmake.in new file mode 100644 index 000000000..7740ff850 --- /dev/null +++ b/cmake_uninstall.cmake.in @@ -0,0 +1,24 @@ +# "make uninstall" helper +# see http://www.cmake.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F + +if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") +endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + +file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +foreach(file ${files}) + message(STATUS "Uninstalling $ENV{DESTDIR}${file}") + if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + exec_program( + "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") + endif(NOT "${rm_retval}" STREQUAL 0) + else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + message(STATUS "File $ENV{DESTDIR}${file} does not exist.") + endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") +endforeach(file) diff --git a/server/core/atomic.c b/server/core/atomic.c index b14e1ccb1..c1bd5b244 100644 --- a/server/core/atomic.c +++ b/server/core/atomic.c @@ -29,23 +29,32 @@ */ /** - * Implementation of an atomic add operation for the X86 processor. + * Implementation of an atomic add operation for the GCC environment, or the + * X86 processor. If we are working within GNU C then we can use the GCC + * atomic add built in function, which is portable across platforms that + * implement GCC. Otherwise, this function currently supports only X86 + * architecture (without further development). + * * Adds a value to the contents of a location pointed to by the first parameter. - * The add operation is atomic and the return value is the value stored in the location - * prior to the operation. The number that is added may be signed, therefore atomic_subtract - * is merely an atomic add with a negative value. + * The add operation is atomic and the return value is the value stored in the + * location prior to the operation. The number that is added may be signed, + * therefore atomic_subtract is merely an atomic add with a negative value. * * @param variable Pointer the the variable to add to * @param value Value to be added - * @return Pointer to the value of variable before the add occured + * @return The value of variable before the add occurred */ int atomic_add(int *variable, int value) { +#ifdef __GNUC__ + return (int) __sync_fetch_and_add (variable, value); +#else asm volatile( "lock; xaddl %%eax, %2;" :"=a" (value) : "a" (value), "m" (*variable) : "memory" ); return value; +#endif } diff --git a/server/core/server.c b/server/core/server.c index 167ae4f23..3fabd2b34 100644 --- a/server/core/server.c +++ b/server/core/server.c @@ -162,7 +162,7 @@ SERVER *server; server = allServers; while (server) { - if (strcmp(server->unique_name, name) == 0) + if (server->unique_name && strcmp(server->unique_name, name) == 0) break; server = server->next; } diff --git a/server/core/test/testserver.c b/server/core/test/testserver.c index 3b05188ab..b1065ace0 100644 --- a/server/core/test/testserver.c +++ b/server/core/test/testserver.c @@ -63,13 +63,14 @@ char *status; ss_info_dassert(server == server_find_by_unique_name("uniquename"), "Should find by unique name."); ss_dfprintf(stderr, "\t..done\nTesting Status Setting for Server."); status = server_status(server); - ss_info_dassert(0 == strcmp("Down", status), "Status of Server should be Down prior to being set."); + ss_info_dassert(0 == strcmp("Running", status), "Status of Server should be Running by default."); if (NULL != status) free(status); server_set_status(server, SERVER_MASTER); status = server_status(server); - ss_info_dassert(0 == strcmp("Master, Down", status), "Should find correct status."); + ss_info_dassert(0 == strcmp("Master, Running", status), "Should find correct status."); server_clear_status(server, SERVER_MASTER); - ss_info_dassert(0 == strcmp("Down", status), "Status of Server should be Down after status cleared."); + status = server_status(server); + ss_info_dassert(0 == strcmp("Running", status), "Status of Server should be Running after master status cleared."); if (NULL != status) free(status); ss_dfprintf(stderr, "\t..done\nRun Prints for Server and all Servers."); printServer(server); diff --git a/server/core/test/testusers.c b/server/core/test/testusers.c index 3f13cad9b..c2b2c9f15 100644 --- a/server/core/test/testusers.c +++ b/server/core/test/testusers.c @@ -41,7 +41,8 @@ static int test1() { -USERS *users; +USERS *users; +char *authdata; int result, count; /* Poll tests */ @@ -52,13 +53,17 @@ int result, count; ss_dfprintf(stderr, "\t..done\nAdd a user"); count = users_add(users, "username", "authorisation"); ss_info_dassert(1 == count, "Should add one user"); - ss_info_dassert(strcmp("authorisation", users_fetch(users, "username")), "User authorisation should be correct"); + authdata = users_fetch(users, "username"); + ss_info_dassert(NULL != authdata, "Fetch valid user must not return NULL"); + ss_info_dassert(0 == strcmp("authorisation", authdata), "User authorisation should be correct"); ss_dfprintf(stderr, "\t..done\nPrint users"); usersPrint(users); ss_dfprintf(stderr, "\t..done\nUpdate a user"); count = users_update(users, "username", "newauth"); ss_info_dassert(1 == count, "Should update just one user"); - ss_info_dassert(strcmp("newauth", users_fetch(users, "username")), "User authorisation should be correctly updated"); + authdata = users_fetch(users, "username"); + ss_info_dassert(NULL != authdata, "Fetch valid user must not return NULL"); + ss_info_dassert(0 == strcmp("newauth", authdata), "User authorisation should be correctly updated"); ss_dfprintf(stderr, "\t..done\nDelete a user."); count = users_delete(users, "username"); ss_info_dassert(1 == count, "Should delete just one user"); diff --git a/server/modules/protocol/mysql_common.c b/server/modules/protocol/mysql_common.c index da0e2ab93..ba453b166 100644 --- a/server/modules/protocol/mysql_common.c +++ b/server/modules/protocol/mysql_common.c @@ -1111,21 +1111,21 @@ int gw_send_change_user_to_backend( // add the user bytes += strlen(user); - // the NULL + // NULL byte for user string bytes++; // next will be + 1 (scramble_len) + 20 (fixed_scramble) + (dbname + NULL term) + 2 bytes charset - if (curr_passwd != NULL) { - bytes += GW_MYSQL_SCRAMBLE_SIZE; + if (curr_passwd != NULL) { + bytes += GW_MYSQL_SCRAMBLE_SIZE; } - // the NULL + // 1 byte for scramble_len bytes++; - if (curr_db != NULL) { - bytes += strlen(curr_db); + if (curr_db != NULL) { + bytes += strlen(curr_db); } - // the NULL + // NULL byte for dbname string bytes++; // the charset diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index 07820b076..5a239a5ef 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -2696,34 +2696,38 @@ static bool select_connect_backend_servers( switch(select_criteria) { case LEAST_GLOBAL_CONNECTIONS: LOGIF(LT, (skygw_log_write_flush(LOGFILE_TRACE, - "%s:%d MaxScale connections : %d", - b->backend_server->name, - b->backend_server->port, - b->backend_server->stats.n_current))); + "MaxScale connections : %d in \t%s:%d %s", + b->backend_server->stats.n_current, + b->backend_server->name, + b->backend_server->port, + STRSRVSTATUS(b->backend_server)))); break; case LEAST_ROUTER_CONNECTIONS: LOGIF(LT, (skygw_log_write_flush(LOGFILE_TRACE, - "%s:%d RWSplit connections : %d", - b->backend_server->name, - b->backend_server->port, - b->backend_conn_count))); + "RWSplit connections : %d in \t%s:%d %s", + b->backend_conn_count, + b->backend_server->name, + b->backend_server->port, + STRSRVSTATUS(b->backend_server)))); break; case LEAST_CURRENT_OPERATIONS: LOGIF(LT, (skygw_log_write_flush(LOGFILE_TRACE, - "%s:%d current operations : %d", - b->backend_server->name, - b->backend_server->port, - b->backend_server->stats.n_current_ops))); + "current operations : %d in \t%s:%d %s", + b->backend_server->stats.n_current_ops, + b->backend_server->name, + b->backend_server->port, + STRSRVSTATUS(b->backend_server)))); break; case LEAST_BEHIND_MASTER: LOGIF(LT, (skygw_log_write_flush(LOGFILE_TRACE, - "%s:%d replication lag : %d", - b->backend_server->name, - b->backend_server->port, - b->backend_server->rlag))); + "replication lag : %d in \t%s:%d %s", + b->backend_server->rlag, + b->backend_server->name, + b->backend_server->port, + STRSRVSTATUS(b->backend_server)))); default: break; }