1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00

MDEV-11111: wire the launcher into mysql_server_init()

Glue (embedded_glue.c) registers the launcher with libmariadb through
mariadb_set_embedded_hooks(), so that the plain client API is enough:
mysql_server_init(argc, argv) starts the server, connecting to localhost
reaches it, mysql_server_end() stops it. launcher_test now uses only that.

Points libmariadb at the MDEV-11111-embedded-hooks branch (57875d2c).
That commit exists only locally and must be pushed to the libmariadb
repository before this one can be.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Vladislav Vaintroub
2026-09-30 16:38:08 +02:00
parent e2188b96f9
commit 2f732df8dd
4 changed files with 75 additions and 25 deletions

View File

@@ -0,0 +1,58 @@
/* Copyright (c) 2026, MariaDB plc
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 */
/*
MDEV-11111: connect the launcher to libmariadb.
After mariadb_embedded_register(), the ordinary client API is enough:
mysql_server_init(argc, argv, groups) starts the server, mysql_real_connect()
to the local host (no host, "localhost", "." on Windows) reaches it, and
mysql_server_end() stops it.
A shared libmariadbd is built with MARIADB_EMBEDDED_AUTOREGISTER, so
merely loading it registers the hooks; a static build calls
mariadb_embedded_register() explicitly.
*/
#include <stdio.h>
#include <mysql.h>
#include "embedded_launcher.h"
static int init_hook(int argc, char **argv, char **groups)
{
if (mariadb_embedded_start(argc, argv, groups))
{
fprintf(stderr, "mysql_server_init: %s\n", mariadb_embedded_error());
return 1;
}
return 0;
}
static void end_hook(void)
{
mariadb_embedded_stop();
}
void mariadb_embedded_register(void)
{
mariadb_set_embedded_hooks(init_hook, end_hook, mariadb_embedded_socket);
}
#if defined(MARIADB_EMBEDDED_AUTOREGISTER) && defined(__GNUC__)
__attribute__((constructor)) static void autoregister(void)
{
mariadb_embedded_register();
}
#endif

View File

@@ -56,6 +56,10 @@ const char *mariadb_embedded_socket(void);
/* Last error message */
const char *mariadb_embedded_error(void);
/* Register the launcher with libmariadb (embedded_glue.c), so that
mysql_server_init()/mysql_server_end() start and stop the server */
void mariadb_embedded_register(void);
#ifdef __cplusplus
}
#endif

View File

@@ -1,20 +1,20 @@
/*
MDEV-11111: smoke test for the embedded launcher.
MDEV-11111: smoke test for the embedded server.
Usage: launcher_test [server options...]
Starts the server, runs a query through the normal client library over the
private socket, stops the server.
Uses only the ordinary client API: mysql_server_init() starts the server,
a connection to "localhost" reaches it, mysql_server_end() stops it.
*/
#include <stdio.h>
#include <stdlib.h>
#include <mysql.h>
#include "embedded_launcher.h"
#ifdef _WIN32
#include <windows.h>
#define Sleep_or_pause() Sleep(1000)
#define pause_1s() Sleep(1000)
#else
#include <unistd.h>
#define Sleep_or_pause() sleep(1)
#define pause_1s() sleep(1)
#endif
#include <mysql.h>
#include "embedded_launcher.h"
int main(int argc, char **argv)
{
@@ -23,23 +23,12 @@ int main(int argc, char **argv)
MYSQL_ROW row;
int rc= 1;
if (mariadb_embedded_start(argc, argv, NULL))
{
fprintf(stderr, "start failed: %s\n", mariadb_embedded_error());
mariadb_embedded_register(); /* not needed with a shared libmariadbd */
if (mysql_server_init(argc, argv, NULL))
return 1;
}
printf("socket: %s\n", mariadb_embedded_socket());
mysql_library_init(0, NULL, NULL); /* reads MARIADB_UNIX_PORT */
m= mysql_init(NULL);
#ifdef _WIN32
/* libmariadb ignores MARIADB_UNIX_PORT for named pipes, pass it explicitly */
const char *host= ".";
#else
const char *host= "localhost"; /* default socket: $MARIADB_UNIX_PORT */
#endif
if (!mysql_real_connect(m, host, "root", NULL, NULL, 0,
mariadb_embedded_socket(), 0))
if (!mysql_real_connect(m, "localhost", "root", NULL, NULL, 0, NULL, 0))
fprintf(stderr, "connect failed: %s\n", mysql_error(m));
else if (mysql_query(m, "SELECT @@version, 1+1") ||
!(res= mysql_store_result(m)))
@@ -53,10 +42,9 @@ int main(int argc, char **argv)
}
if (getenv("LAUNCHER_TEST_HANG")) /* to kill us and watch the server */
for (;;)
Sleep_or_pause();
pause_1s();
mysql_close(m);
mysql_library_end();
mariadb_embedded_stop();
mysql_server_end();
puts(rc ? "FAIL" : "OK");
return rc;
}