mirror of https://github.com/yandex/odyssey.git
odissey: major logging rework
This commit is contained in:
parent
0d04fc7c87
commit
01cbf6fc76
138
src/od_auth.c
138
src/od_auth.c
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <machinarium.h>
|
||||
|
@ -56,8 +57,9 @@ od_auth_frontend_cleartext(od_client_t *client)
|
|||
return -1;
|
||||
rc = od_write(client->io, stream);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, client->io, "C (auth): write error: %s",
|
||||
machine_error(client->io));
|
||||
od_error_client(&instance->log, client->id,
|
||||
"auth", "write error: %s",
|
||||
machine_error(client->io));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -66,12 +68,14 @@ od_auth_frontend_cleartext(od_client_t *client)
|
|||
so_stream_reset(stream);
|
||||
rc = od_read(client->io, stream, UINT32_MAX);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, client->io, "C (auth): read error: %s",
|
||||
machine_error(client->io));
|
||||
od_error_client(&instance->log, client->id, "auth",
|
||||
"read error: %s",
|
||||
machine_error(client->io));
|
||||
return -1;
|
||||
}
|
||||
uint8_t type = *stream->s;
|
||||
od_debug(&instance->log, client->io, "C (auth): %c", *stream->s);
|
||||
od_debug_client(&instance->log,
|
||||
client->id, "auth", "%c", *stream->s);
|
||||
/* PasswordMessage */
|
||||
if (type == 'p')
|
||||
break;
|
||||
|
@ -83,8 +87,8 @@ od_auth_frontend_cleartext(od_client_t *client)
|
|||
rc = so_beread_password(&client_token, stream->s,
|
||||
so_stream_used(stream));
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, client->io,
|
||||
"C (auth): password read error");
|
||||
od_error_client(&instance->log, client->id, "auth",
|
||||
"password read error");
|
||||
so_password_free(&client_token);
|
||||
return -1;
|
||||
}
|
||||
|
@ -99,9 +103,9 @@ od_auth_frontend_cleartext(od_client_t *client)
|
|||
int check = so_password_compare(&client_password, &client_token);
|
||||
so_password_free(&client_token);
|
||||
if (! check) {
|
||||
od_log(&instance->log, client->io,
|
||||
"C (auth): user '%s' incorrect password",
|
||||
client->startup.user);
|
||||
od_log_client(&instance->log, client->id, "auth",
|
||||
"user '%s' incorrect password",
|
||||
client->startup.user);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -124,8 +128,9 @@ od_auth_frontend_md5(od_client_t *client)
|
|||
return -1;
|
||||
rc = od_write(client->io, stream);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, client->io, "C (auth): write error: %s",
|
||||
machine_error(client->io));
|
||||
od_error_client(&instance->log, client->id, "auth",
|
||||
"write error: %s",
|
||||
machine_error(client->io));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -135,12 +140,14 @@ od_auth_frontend_md5(od_client_t *client)
|
|||
so_stream_reset(stream);
|
||||
rc = od_read(client->io, stream, UINT32_MAX);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, client->io, "C (auth): read error: %s",
|
||||
machine_error(client->io));
|
||||
od_error_client(&instance->log, client->id, "auth",
|
||||
"read error: %s",
|
||||
machine_error(client->io));
|
||||
return -1;
|
||||
}
|
||||
uint8_t type = *stream->s;
|
||||
od_debug(&instance->log, client->io, "C (auth): %c", *stream->s);
|
||||
od_debug_client(&instance->log, client->id, "auth",
|
||||
"%c", *stream->s);
|
||||
/* PasswordMessage */
|
||||
if (type == 'p')
|
||||
break;
|
||||
|
@ -151,8 +158,8 @@ od_auth_frontend_md5(od_client_t *client)
|
|||
so_password_init(&client_token);
|
||||
rc = so_beread_password(&client_token, stream->s, so_stream_used(stream));
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, client->io,
|
||||
"C (auth): password read error");
|
||||
od_error_client(&instance->log, client->id, "auth",
|
||||
"password read error");
|
||||
so_password_free(&client_token);
|
||||
return -1;
|
||||
}
|
||||
|
@ -167,7 +174,8 @@ od_auth_frontend_md5(od_client_t *client)
|
|||
client->scheme->password_len,
|
||||
(uint8_t*)&salt);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, NULL, "memory allocation error");
|
||||
od_error_client(&instance->log, client->id, "auth",
|
||||
"memory allocation error");
|
||||
so_password_free(&client_password);
|
||||
so_password_free(&client_token);
|
||||
return -1;
|
||||
|
@ -178,9 +186,9 @@ od_auth_frontend_md5(od_client_t *client)
|
|||
so_password_free(&client_password);
|
||||
so_password_free(&client_token);
|
||||
if (! check) {
|
||||
od_log(&instance->log, client->io,
|
||||
"C (auth): user '%s' incorrect password",
|
||||
client->startup.user);
|
||||
od_log_client(&instance->log, client->id, "auth",
|
||||
"user '%s' incorrect password",
|
||||
client->startup.user);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -198,9 +206,9 @@ int od_auth_frontend(od_client_t *client)
|
|||
/* try to use default user */
|
||||
user_scheme = instance->scheme.users_default;
|
||||
if (user_scheme == NULL) {
|
||||
od_error(&instance->log, client->io,
|
||||
"C (auth): user '%s' not found",
|
||||
so_parameter_value(client->startup.user));
|
||||
od_error_client(&instance->log, client->id, "auth"
|
||||
"user '%s' not found",
|
||||
so_parameter_value(client->startup.user));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -208,9 +216,9 @@ int od_auth_frontend(od_client_t *client)
|
|||
|
||||
/* is user access denied */
|
||||
if (user_scheme->is_deny) {
|
||||
od_log(&instance->log, client->io,
|
||||
"C (auth): user '%s' access denied",
|
||||
so_parameter_value(client->startup.user));
|
||||
od_log_client(&instance->log, client->id, "auth",
|
||||
"user '%s' access denied",
|
||||
so_parameter_value(client->startup.user));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -242,8 +250,9 @@ int od_auth_frontend(od_client_t *client)
|
|||
return -1;
|
||||
rc = od_write(client->io, stream);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, client->io, "C (auth): write error: %s",
|
||||
machine_error(client->io));
|
||||
od_error_client(&instance->log, client->id, "auth",
|
||||
"write error: %s",
|
||||
machine_error(client->io));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -256,14 +265,14 @@ od_auth_backend_cleartext(od_server_t *server)
|
|||
od_route_t *route = server->route;
|
||||
assert(route != NULL);
|
||||
|
||||
od_debug(&instance->log, server->io,
|
||||
"S (auth): requested clear-text authentication");
|
||||
od_debug_server(&instance->log, server->id, "auth",
|
||||
"requested clear-text authentication");
|
||||
|
||||
/* validate route scheme */
|
||||
if (route->scheme->password == NULL) {
|
||||
od_error(&instance->log, server->io,
|
||||
"S (auth): password required for route '%s'",
|
||||
route->scheme->target);
|
||||
od_error_server(&instance->log, server->id, "auth"
|
||||
"password required for route '%s'",
|
||||
route->scheme->target);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -275,13 +284,15 @@ od_auth_backend_cleartext(od_server_t *server)
|
|||
route->scheme->password,
|
||||
route->scheme->password_len + 1);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, NULL, "memory allocation error");
|
||||
od_error_server(&instance->log, server->id, "auth",
|
||||
"memory allocation error");
|
||||
return -1;
|
||||
}
|
||||
rc = od_write(server->io, stream);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, server->io, "S (auth): write error: %s",
|
||||
machine_error(server->io));
|
||||
od_error_server(&instance->log, server->id, "auth",
|
||||
"write error: %s",
|
||||
machine_error(server->io));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -294,15 +305,15 @@ od_auth_backend_md5(od_server_t *server, uint8_t salt[4])
|
|||
od_route_t *route = server->route;
|
||||
assert(route != NULL);
|
||||
|
||||
od_debug(&instance->log, server->io,
|
||||
"S (auth): requested md5 authentication");
|
||||
od_debug_server(&instance->log, server->id, "auth",
|
||||
"requested md5 authentication");
|
||||
|
||||
/* validate route scheme */
|
||||
if (route->scheme->user == NULL ||
|
||||
route->scheme->password == NULL) {
|
||||
od_error(&instance->log, server->io,
|
||||
"S (auth): user and password required for route '%s'",
|
||||
route->scheme->target);
|
||||
od_error_server(&instance->log, server->id, "auth",
|
||||
"user and password required for route '%s'",
|
||||
route->scheme->target);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -317,7 +328,8 @@ od_auth_backend_md5(od_server_t *server, uint8_t salt[4])
|
|||
route->scheme->password_len,
|
||||
(uint8_t*)salt);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, NULL, "memory allocation error");
|
||||
od_error_server(&instance->log, server->id, "auth",
|
||||
"memory allocation error");
|
||||
so_password_free(&client_password);
|
||||
return -1;
|
||||
}
|
||||
|
@ -330,13 +342,15 @@ od_auth_backend_md5(od_server_t *server, uint8_t salt[4])
|
|||
client_password.password_len);
|
||||
so_password_free(&client_password);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, NULL, "memory allocation error");
|
||||
od_error_server(&instance->log, server->id, "auth",
|
||||
"memory allocation error");
|
||||
return -1;
|
||||
}
|
||||
rc = od_write(server->io, stream);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, server->io, "S (auth): write error: %s",
|
||||
machine_error(server->io));
|
||||
od_error_server(&instance->log, server->id, "auth",
|
||||
"write error: %s",
|
||||
machine_error(server->io));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -355,8 +369,8 @@ int od_auth_backend(od_server_t *server)
|
|||
rc = so_feread_auth(&auth_type, salt, stream->s,
|
||||
so_stream_used(stream));
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, server->io,
|
||||
"S (auth): failed to parse authentication message");
|
||||
od_error_server(&instance->log, server->id, "auth",
|
||||
"failed to parse authentication message");
|
||||
return -1;
|
||||
}
|
||||
switch (auth_type) {
|
||||
|
@ -377,8 +391,8 @@ int od_auth_backend(od_server_t *server)
|
|||
break;
|
||||
/* unsupported */
|
||||
default:
|
||||
od_error(&instance->log, server->io,
|
||||
"S (auth): unuspported authentication method");
|
||||
od_error_server(&instance->log, server->id, "auth",
|
||||
"unsupported authentication method");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -388,32 +402,32 @@ int od_auth_backend(od_server_t *server)
|
|||
so_stream_reset(stream);
|
||||
rc = od_read(server->io, &server->stream, UINT32_MAX);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, server->io, "S (auth): read error: %s",
|
||||
machine_error(server->io));
|
||||
od_error_server(&instance->log, server->id, "auth",
|
||||
"read error: %s",
|
||||
machine_error(server->io));
|
||||
return -1;
|
||||
}
|
||||
char type = *server->stream.s;
|
||||
od_debug(&instance->log, server->io, "S (auth): %c",
|
||||
type);
|
||||
od_debug_server(&instance->log, server->id, "auth",
|
||||
"%c", type);
|
||||
switch (type) {
|
||||
case 'R': {
|
||||
case 'R':
|
||||
rc = so_feread_auth(&auth_type, salt, stream->s,
|
||||
so_stream_used(stream));
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, server->io,
|
||||
"S (auth): failed to parse authentication message");
|
||||
od_error_server(&instance->log, server->id, "auth",
|
||||
"failed to parse authentication message");
|
||||
return -1;
|
||||
}
|
||||
if (auth_type != 0) {
|
||||
od_error(&instance->log, server->io,
|
||||
"S (auth): incorrect authentication flow");
|
||||
od_error_server(&instance->log, server->id, "auth",
|
||||
"incorrect authentication flow");
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
case 'E':
|
||||
od_error(&instance->log, server->io,
|
||||
"S (auth): authentication error");
|
||||
od_error_server(&instance->log, server->id, "auth",
|
||||
"authentication error");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <machinarium.h>
|
||||
|
@ -97,8 +98,9 @@ od_backend_startup(od_server_t *server)
|
|||
return -1;
|
||||
rc = od_write(server->io, stream);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, server->io, "S (startup): write error: %s",
|
||||
machine_error(server->io));
|
||||
od_error_server(&instance->log, server->id, "startup",
|
||||
"write error: %s",
|
||||
machine_error(server->io));
|
||||
return -1;
|
||||
}
|
||||
server->count_request++;
|
||||
|
@ -138,14 +140,15 @@ od_backend_ready_wait(od_server_t *server, char *procedure, int time_ms)
|
|||
rc = od_read(server->io, stream, time_ms);
|
||||
if (rc == -1) {
|
||||
if (! machine_timedout()) {
|
||||
od_error(&instance->log, server->io, "S (%s): read error: %s",
|
||||
procedure, machine_error(server->io));
|
||||
od_error_server(&instance->log, server->id, procedure,
|
||||
"read error: %s",
|
||||
machine_error(server->io));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
uint8_t type = stream->s[rc];
|
||||
od_debug(&instance->log, server->io, "S (%s): %c",
|
||||
procedure, type);
|
||||
od_debug_server(&instance->log, server->id, procedure,
|
||||
"%c", type);
|
||||
/* ReadyForQuery */
|
||||
if (type == 'Z') {
|
||||
od_backend_ready(server, stream->s + rc,
|
||||
|
@ -166,12 +169,15 @@ od_backend_setup(od_server_t *server)
|
|||
int rc;
|
||||
rc = od_read(server->io, &server->stream, UINT32_MAX);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, server->io, "S (setup): read error: %s",
|
||||
machine_error(server->io));
|
||||
od_error_server(&instance->log, server->id, "setup",
|
||||
"read error: %s",
|
||||
machine_error(server->io));
|
||||
return -1;
|
||||
}
|
||||
uint8_t type = *server->stream.s;
|
||||
od_debug(&instance->log, server->io, "S (setup): %c", type);
|
||||
od_debug_server(&instance->log, server->id, "setup",
|
||||
"%c", type);
|
||||
|
||||
switch (type) {
|
||||
/* ReadyForQuery */
|
||||
case 'Z':
|
||||
|
@ -188,8 +194,8 @@ od_backend_setup(od_server_t *server)
|
|||
rc = so_feread_key(&server->key,
|
||||
stream->s, so_stream_used(stream));
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, server->io,
|
||||
"S (setup): failed to parse BackendKeyData message");
|
||||
od_error_server(&instance->log, server->id, "setup",
|
||||
"failed to parse BackendKeyData message");
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
@ -203,8 +209,8 @@ od_backend_setup(od_server_t *server)
|
|||
case 'E':
|
||||
return -1;
|
||||
default:
|
||||
od_debug(&instance->log, server->io,
|
||||
"S (setup): unknown packet: %c", type);
|
||||
od_debug_server(&instance->log, server->id, "setup",
|
||||
"unknown packet: %c", type);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -225,9 +231,10 @@ od_backend_connect(od_server_t *server)
|
|||
int rc;
|
||||
rc = machine_getaddrinfo(server_scheme->host, port, NULL, &ai, 0);
|
||||
if (rc < 0) {
|
||||
od_error(&instance->log, NULL, "failed to resolve %s:%d",
|
||||
server_scheme->host,
|
||||
server_scheme->port);
|
||||
od_error_server(&instance->log, server->id, "connect",
|
||||
"failed to resolve %s:%d",
|
||||
server_scheme->host,
|
||||
server_scheme->port);
|
||||
return -1;
|
||||
}
|
||||
assert(ai != NULL);
|
||||
|
@ -236,9 +243,10 @@ od_backend_connect(od_server_t *server)
|
|||
rc = machine_connect(server->io, ai->ai_addr, UINT32_MAX);
|
||||
freeaddrinfo(ai);
|
||||
if (rc < 0) {
|
||||
od_error(&instance->log, NULL, "failed to connect to %s:%d",
|
||||
server_scheme->host,
|
||||
server_scheme->port);
|
||||
od_error_server(&instance->log, server->id, "connect",
|
||||
"failed to connect to %s:%d",
|
||||
server_scheme->host,
|
||||
server_scheme->port);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -254,7 +262,10 @@ od_backend_connect(od_server_t *server)
|
|||
}
|
||||
#endif
|
||||
|
||||
od_log(&instance->log, server->io, "S: new connection");
|
||||
od_log_server(&instance->log, server->id, NULL,
|
||||
"new server connection (%s:%d)",
|
||||
server_scheme->host,
|
||||
server_scheme->port);
|
||||
|
||||
/* startup */
|
||||
rc = od_backend_startup(server);
|
||||
|
@ -294,8 +305,9 @@ od_backend_new(od_router_t *router, od_route_t *route)
|
|||
int rc;
|
||||
rc = machine_set_readahead(server->io, instance->scheme.readahead);
|
||||
if (rc == -1) {
|
||||
od_error_server(&instance->log, server->id, NULL,
|
||||
"failed to set readahead");
|
||||
od_server_free(server);
|
||||
od_error(&instance->log, NULL, "failed to set readahead");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -332,8 +344,9 @@ od_backend_query(od_server_t *server, char *procedure, char *query, int len)
|
|||
return -1;
|
||||
rc = od_write(server->io, stream);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, server->io, "S (%s): write error: %s",
|
||||
procedure, machine_error(server->io));
|
||||
od_error_server(&instance->log, server->id, procedure,
|
||||
"write error: %s",
|
||||
machine_error(server->io));
|
||||
return -1;
|
||||
}
|
||||
server->count_request++;
|
||||
|
@ -365,8 +378,8 @@ int od_backend_configure(od_server_t *server, so_bestartup_t *startup)
|
|||
}
|
||||
if (size == 0)
|
||||
return 0;
|
||||
od_debug(&instance->log, server->io,
|
||||
"S (configure): %s", query_configure);
|
||||
od_debug_server(&instance->log, server->id, "configure",
|
||||
"%s", query_configure);
|
||||
int rc;
|
||||
rc = od_backend_query(server, "configure", query_configure,
|
||||
size + 1);
|
||||
|
@ -380,16 +393,16 @@ int od_backend_reset(od_server_t *server)
|
|||
|
||||
/* server left in copy mode */
|
||||
if (server->is_copy) {
|
||||
od_debug(&instance->log, server->io,
|
||||
"S (reset): in copy, closing");
|
||||
od_debug_server(&instance->log, server->id, "reset",
|
||||
"in copy, closing");
|
||||
goto drop;
|
||||
}
|
||||
|
||||
/* support route rollback off */
|
||||
if (! route->scheme->rollback) {
|
||||
if (server->is_transaction) {
|
||||
od_debug(&instance->log, server->io,
|
||||
"S (reset): in active transaction, closing");
|
||||
od_debug_server(&instance->log, server->id, "reset",
|
||||
"in active transaction, closing");
|
||||
goto drop;
|
||||
}
|
||||
}
|
||||
|
@ -397,8 +410,8 @@ int od_backend_reset(od_server_t *server)
|
|||
/* support route cancel off */
|
||||
if (! route->scheme->cancel) {
|
||||
if (! od_server_is_sync(server)) {
|
||||
od_debug(&instance->log, server->io,
|
||||
"S (reset): not synchronized, closing");
|
||||
od_debug_server(&instance->log, server->id, "reset",
|
||||
"not synchronized, closing");
|
||||
goto drop;
|
||||
}
|
||||
}
|
||||
|
@ -428,10 +441,10 @@ int od_backend_reset(od_server_t *server)
|
|||
int rc = 0;
|
||||
for (;;) {
|
||||
while (! od_server_is_sync(server)) {
|
||||
od_debug(&instance->log, server->io,
|
||||
"S (reset): not synchronized, wait for %d msec (#%d)",
|
||||
wait_timeout,
|
||||
wait_try);
|
||||
od_debug_server(&instance->log, server->id, "reset",
|
||||
"not synchronized, wait for %d msec (#%d)",
|
||||
wait_timeout,
|
||||
wait_try);
|
||||
wait_try++;
|
||||
rc = od_backend_ready_wait(server, "reset", wait_timeout);
|
||||
if (rc == -1)
|
||||
|
@ -441,13 +454,13 @@ int od_backend_reset(od_server_t *server)
|
|||
if (! machine_timedout())
|
||||
goto error;
|
||||
if (wait_try_cancel == wait_cancel_limit) {
|
||||
od_debug(&instance->log, server->io,
|
||||
"S (reset): server cancel limit reached, closing");
|
||||
od_debug_server(&instance->log, server->id, "reset",
|
||||
"server cancel limit reached, closing");
|
||||
goto error;
|
||||
}
|
||||
od_debug(&instance->log, server->io,
|
||||
"S (reset): not responded, cancel (#%d)",
|
||||
wait_try_cancel);
|
||||
od_debug_server(&instance->log, server->id, "reset",
|
||||
"not responded, cancel (#%d)",
|
||||
wait_try_cancel);
|
||||
wait_try_cancel++;
|
||||
rc = od_cancel(instance, route->scheme->server, &server->key);
|
||||
if (rc < 0)
|
||||
|
@ -457,7 +470,8 @@ int od_backend_reset(od_server_t *server)
|
|||
assert(od_server_is_sync(server));
|
||||
break;
|
||||
}
|
||||
od_debug(&instance->log, server->io, "S (reset): synchronized");
|
||||
od_debug_server(&instance->log, server->id, "reset",
|
||||
"synchronized");
|
||||
|
||||
/* send rollback in case server has an active
|
||||
* transaction running */
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <machinarium.h>
|
||||
|
@ -61,7 +62,7 @@ int od_cancel(od_instance_t *instance,
|
|||
int rc;
|
||||
rc = machine_getaddrinfo(server_scheme->host, port, NULL, &ai, 0);
|
||||
if (rc < 0) {
|
||||
od_error(&instance->log, NULL, "failed to resolve %s:%d",
|
||||
od_error(&instance->log, "(cancel) failed to resolve %s:%d",
|
||||
server_scheme->host,
|
||||
server_scheme->port);
|
||||
return -1;
|
||||
|
@ -74,7 +75,7 @@ int od_cancel(od_instance_t *instance,
|
|||
machine_set_keepalive(io, 1, instance->scheme.keepalive);
|
||||
rc = machine_set_readahead(io, instance->scheme.readahead);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, NULL, "(cancel) failed to set readahead");
|
||||
od_error(&instance->log, "(cancel) failed to set readahead");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -82,7 +83,7 @@ int od_cancel(od_instance_t *instance,
|
|||
rc = machine_connect(io, ai->ai_addr, UINT32_MAX);
|
||||
freeaddrinfo(ai);
|
||||
if (rc < 0) {
|
||||
od_error(&instance->log, NULL,
|
||||
od_error(&instance->log,
|
||||
"(cancel) failed to connect to %s:%d",
|
||||
server_scheme->host,
|
||||
server_scheme->port);
|
||||
|
@ -100,7 +101,7 @@ int od_cancel(od_instance_t *instance,
|
|||
if (server_scheme->tls_verify != OD_TDISABLE) {
|
||||
tls = od_tlsbe(pooler->env, server_scheme);
|
||||
if (tls == NULL) {
|
||||
od_error(&pooler->od->log, NULL,
|
||||
od_error(&pooler->od->log,
|
||||
"(cancel) failed to create tls context",
|
||||
server_scheme->host,
|
||||
server_scheme->port);
|
||||
|
@ -134,7 +135,7 @@ int od_cancel(od_instance_t *instance,
|
|||
}
|
||||
rc = od_write(io, &stream);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, io, "(cancel): write error: %s",
|
||||
od_error(&instance->log, "(cancel): write error: %s",
|
||||
machine_error(io));
|
||||
}
|
||||
machine_close(io);
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <machinarium.h>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
@ -99,28 +100,26 @@ od_config_open(od_config_t *config, char *file)
|
|||
struct stat st;
|
||||
int rc = lstat(file, &st);
|
||||
if (rc == -1) {
|
||||
od_error(config->log, NULL, "failed to open config file '%s'",
|
||||
od_error(config->log, "failed to open config file '%s'",
|
||||
file);
|
||||
return -1;
|
||||
}
|
||||
char *config_buf = malloc(st.st_size);
|
||||
if (config_buf == NULL) {
|
||||
od_error(config->log, NULL, "memory allocation error");
|
||||
od_error(config->log, "memory allocation error");
|
||||
return -1;
|
||||
}
|
||||
FILE *f = fopen(file, "r");
|
||||
if (f == NULL) {
|
||||
free(config_buf);
|
||||
od_error(config->log, NULL, "failed to open config file '%s'",
|
||||
file);
|
||||
od_error(config->log, "failed to open config file '%s'", file);
|
||||
return -1;
|
||||
}
|
||||
rc = fread(config_buf, st.st_size, 1, f);
|
||||
fclose(f);
|
||||
if (rc != 1) {
|
||||
free(config_buf);
|
||||
od_error(config->log, NULL, "failed to open config file '%s'",
|
||||
file);
|
||||
od_error(config->log, "failed to open config file '%s'", file);
|
||||
return -1;
|
||||
}
|
||||
od_lex_open(&config->lex, od_config_keywords, config_buf,
|
||||
|
@ -146,7 +145,7 @@ od_config_error(od_config_t *config, od_token_t *tk, char *fmt, ...)
|
|||
int line = config->lex.line;
|
||||
if (tk)
|
||||
line = tk->line;
|
||||
od_error(config->log, NULL, "%s:%d %s",
|
||||
od_error(config->log, "%s:%d %s",
|
||||
config->scheme->config_file, line, msg);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/fcntl.h>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <machinarium.h>
|
||||
|
@ -73,8 +74,8 @@ od_frontend_startup_read(od_client_t *client)
|
|||
if (to_read == 0)
|
||||
break;
|
||||
if (to_read == -1) {
|
||||
od_error(&instance->log, client->io,
|
||||
"C (startup): bad startup packet");
|
||||
od_error_client(&instance->log, client->id, "startup",
|
||||
"bad startup packet");
|
||||
return -1;
|
||||
}
|
||||
int rc = so_stream_ensure(stream, to_read);
|
||||
|
@ -82,9 +83,9 @@ od_frontend_startup_read(od_client_t *client)
|
|||
return -1;
|
||||
rc = machine_read(client->io, (char*)stream->p, to_read, UINT32_MAX);
|
||||
if (rc < 0) {
|
||||
od_error(&instance->log, client->io,
|
||||
"C (startup): read error: %s",
|
||||
machine_error(client->io));
|
||||
od_error_client(&instance->log, client->id, "startup",
|
||||
"read error: %s",
|
||||
machine_error(client->io));
|
||||
return -1;
|
||||
}
|
||||
so_stream_advance(stream, to_read);
|
||||
|
@ -157,8 +158,9 @@ od_frontend_setup(od_client_t *client)
|
|||
return -1;
|
||||
rc = od_write(client->io, stream);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, client->io, "C (setup): write error: %s",
|
||||
machine_error(client->io));
|
||||
od_error_client(&instance->log, client->id, "setup",
|
||||
"write error: %s",
|
||||
machine_error(client->io));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -177,8 +179,9 @@ od_frontend_ready(od_client_t *client)
|
|||
return -1;
|
||||
rc = od_write(client->io, stream);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, client->io, "C: write error: %s",
|
||||
machine_error(client->io));
|
||||
od_error_client(&instance->log, client->id,
|
||||
"write error: %s",
|
||||
machine_error(client->io));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -214,7 +217,8 @@ od_frontend_copy_in(od_client_t *client)
|
|||
if (rc == -1)
|
||||
return OD_RS_ECLIENT_READ;
|
||||
type = *stream->s;
|
||||
od_debug(&instance->log, client->io, "C (copy): %c", *stream->s);
|
||||
od_debug_client(&instance->log, client->id, "copy",
|
||||
"%c", *stream->s);
|
||||
|
||||
rc = od_write(server->io, stream);
|
||||
if (rc == -1)
|
||||
|
@ -240,8 +244,10 @@ od_frontend_session(od_client_t *client)
|
|||
if (status != OD_ROK)
|
||||
return OD_RS_EPOOL;
|
||||
|
||||
od_server_t *server;
|
||||
server = client->server;
|
||||
od_server_t *server = client->server;
|
||||
od_debug_client(&instance->log, client->id, NULL,
|
||||
"attached to S%" PRIu64,
|
||||
server->id);
|
||||
|
||||
/* assign client session key */
|
||||
server->key_client = client->key;
|
||||
|
@ -262,7 +268,7 @@ od_frontend_session(od_client_t *client)
|
|||
return OD_RS_ECLIENT_READ;
|
||||
int type;
|
||||
type = stream->s[rc];
|
||||
od_debug(&instance->log, client->io, "C: %c", type);
|
||||
od_debug_client(&instance->log, client->id, NULL, "%c", type);
|
||||
|
||||
/* client graceful shutdown */
|
||||
if (type == 'X')
|
||||
|
@ -289,12 +295,13 @@ od_frontend_session(od_client_t *client)
|
|||
return OD_RS_ESERVER_READ;
|
||||
if (machine_connected(client->io))
|
||||
continue;
|
||||
od_debug(&instance->log, server->io,
|
||||
"S (watchdog): client disconnected");
|
||||
od_debug_server(&instance->log, server->id, "watchdog",
|
||||
"client disconnected");
|
||||
return OD_RS_ECLIENT_READ;
|
||||
}
|
||||
type = stream->s[rc];
|
||||
od_debug(&instance->log, server->io, "S: %c", type);
|
||||
od_debug_server(&instance->log, server->id, NULL,
|
||||
"%c", type);
|
||||
|
||||
/* ReadyForQuery */
|
||||
if (type == 'Z') {
|
||||
|
@ -343,13 +350,18 @@ void od_frontend(void *arg)
|
|||
od_client_t *client = arg;
|
||||
od_instance_t *instance = client->system->instance;
|
||||
|
||||
od_log(&instance->log, client->io, "C: new connection");
|
||||
char peer[128];
|
||||
od_getpeername(client->io, peer, sizeof(peer));
|
||||
od_log_client(&instance->log, client->id, NULL,
|
||||
"new client connection (%s)",
|
||||
peer);
|
||||
|
||||
/* attach client io to relay machine event loop */
|
||||
int rc;
|
||||
rc = machine_io_attach(client->io);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, client->io, "failed to transfer client io");
|
||||
od_error_client(&instance->log, client->id, NULL,
|
||||
"failed to transfer client io");
|
||||
machine_close(client->io);
|
||||
od_client_free(client);
|
||||
return;
|
||||
|
@ -364,7 +376,8 @@ void od_frontend(void *arg)
|
|||
|
||||
/* client cancel request */
|
||||
if (client->startup.is_cancel) {
|
||||
od_debug(&instance->log, client->io, "C: cancel request");
|
||||
od_debug_client(&instance->log, client->id, NULL,
|
||||
"cancel request");
|
||||
od_router_cancel(client);
|
||||
od_frontend_close(client);
|
||||
return;
|
||||
|
@ -406,27 +419,27 @@ void od_frontend(void *arg)
|
|||
status = od_route(client);
|
||||
switch (status) {
|
||||
case OD_RERROR:
|
||||
od_error(&instance->log, client->io,
|
||||
"C: routing failed, closing");
|
||||
od_error_client(&instance->log, client->id, NULL,
|
||||
"routing failed, closing");
|
||||
od_frontend_close(client);
|
||||
return;
|
||||
case OD_RERROR_NOT_FOUND:
|
||||
od_error(&instance->log, client->io,
|
||||
"C: database route '%s' is not declared, closing",
|
||||
so_parameter_value(client->startup.database));
|
||||
od_error_client(&instance->log, client->id, NULL,
|
||||
"database route '%s' is not declared, closing",
|
||||
so_parameter_value(client->startup.database));
|
||||
od_frontend_close(client);
|
||||
return;
|
||||
case OD_RERROR_LIMIT:
|
||||
od_error(&instance->log, client->io,
|
||||
"C: route connection limit reached, closing");
|
||||
od_error_client(&instance->log, client->id, NULL,
|
||||
"route connection limit reached, closing");
|
||||
od_frontend_close(client);
|
||||
return;
|
||||
case OD_ROK:;
|
||||
od_route_t *route = client->route;
|
||||
od_debug(&instance->log, client->io,
|
||||
"C: route to '%s' (using '%s' server)",
|
||||
route->scheme->target,
|
||||
route->scheme->server->name);
|
||||
od_debug_client(&instance->log, client->id, NULL,
|
||||
"route to '%s' (using '%s' server)",
|
||||
route->scheme->target,
|
||||
route->scheme->server->name);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -445,12 +458,12 @@ void od_frontend(void *arg)
|
|||
* link in case of client errors and
|
||||
* graceful shutdown */
|
||||
if (rc == OD_RS_OK)
|
||||
od_log(&instance->log, client->io,
|
||||
"C: disconnected");
|
||||
od_log_client(&instance->log, client->id, NULL,
|
||||
"disconnected");
|
||||
else
|
||||
od_log(&instance->log, client->io,
|
||||
"C: disconnected (read/write error): %s",
|
||||
machine_error(client->io));
|
||||
od_log_client(&instance->log, client->id, NULL,
|
||||
"disconnected (read/write error): %s",
|
||||
machine_error(client->io));
|
||||
|
||||
rc = od_backend_reset(server);
|
||||
if (rc != 1) {
|
||||
|
@ -462,9 +475,9 @@ void od_frontend(void *arg)
|
|||
od_router_detach_and_unroute(client);
|
||||
break;
|
||||
case OD_RS_ESERVER_CONFIGURE:
|
||||
od_log(&instance->log, server->io,
|
||||
"S: disconnected (server configure error): %s",
|
||||
machine_error(server->io));
|
||||
od_log_server(&instance->log, server->id, NULL,
|
||||
"disconnected (server configure error): %s",
|
||||
machine_error(server->io));
|
||||
|
||||
/* close backend connection */
|
||||
od_router_close_and_unroute(client);
|
||||
|
@ -473,9 +486,9 @@ void od_frontend(void *arg)
|
|||
case OD_RS_ESERVER_WRITE:
|
||||
/* close client connection and close server
|
||||
* connection in case of server errors */
|
||||
od_log(&instance->log, server->io,
|
||||
"S: disconnected (read/write error): %s",
|
||||
machine_error(server->io));
|
||||
od_log_server(&instance->log, server->id, NULL,
|
||||
"disconnected (read/write error): %s",
|
||||
machine_error(server->io));
|
||||
|
||||
/* close backend connection */
|
||||
od_router_close_and_unroute(client);
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <machinarium.h>
|
||||
|
@ -67,10 +68,10 @@ void od_instance_free(od_instance_t *instance)
|
|||
static inline void
|
||||
od_usage(od_instance_t *instance, char *path)
|
||||
{
|
||||
od_log(&instance->log, NULL, "odissey (build: %s %s)",
|
||||
od_log(&instance->log, "odissey (build: %s %s)",
|
||||
OD_VERSION_GIT,
|
||||
OD_VERSION_BUILD);
|
||||
od_log(&instance->log, NULL, "usage: %s <config_file>", path);
|
||||
od_log(&instance->log, "usage: %s <config_file>", path);
|
||||
}
|
||||
|
||||
int od_instance_main(od_instance_t *instance, int argc, char **argv)
|
||||
|
@ -111,7 +112,7 @@ int od_instance_main(od_instance_t *instance, int argc, char **argv)
|
|||
if (instance->scheme.log_file) {
|
||||
rc = od_log_open(&instance->log, instance->scheme.log_file);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, NULL, "failed to open log file '%s'",
|
||||
od_error(&instance->log, "failed to open log file '%s'",
|
||||
instance->scheme.log_file);
|
||||
return 1;
|
||||
}
|
||||
|
@ -122,10 +123,10 @@ int od_instance_main(od_instance_t *instance, int argc, char **argv)
|
|||
instance->scheme.syslog_ident,
|
||||
instance->scheme.syslog_facility);
|
||||
}
|
||||
od_log(&instance->log, NULL, "odissey (build: %s %s)",
|
||||
od_log(&instance->log, "odissey (build: %s %s)",
|
||||
OD_VERSION_GIT,
|
||||
OD_VERSION_BUILD);
|
||||
od_log(&instance->log, NULL, "");
|
||||
od_log(&instance->log, "");
|
||||
/* validate configuration scheme */
|
||||
rc = od_scheme_validate(&instance->scheme, &instance->log);
|
||||
if (rc == -1)
|
||||
|
@ -133,7 +134,7 @@ int od_instance_main(od_instance_t *instance, int argc, char **argv)
|
|||
/* print configuration scheme */
|
||||
if (instance->scheme.log_verbosity >= 1) {
|
||||
od_scheme_print(&instance->scheme, &instance->log);
|
||||
od_log(&instance->log, NULL, "");
|
||||
od_log(&instance->log, "");
|
||||
}
|
||||
/* create pid file */
|
||||
if (instance->scheme.pid_file)
|
||||
|
@ -152,7 +153,7 @@ int od_instance_main(od_instance_t *instance, int argc, char **argv)
|
|||
};
|
||||
system.task_queue = machine_queue_create();
|
||||
if (system.task_queue == NULL) {
|
||||
od_error(&instance->log, NULL, "failed to create task queue");
|
||||
od_error(&instance->log, "failed to create task queue");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "od_macro.h"
|
||||
|
|
56
src/od_log.c
56
src/od_log.c
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
@ -27,41 +28,45 @@
|
|||
#include "od_log.h"
|
||||
#include "od_io.h"
|
||||
|
||||
int od_log_init(od_log_t *l, od_pid_t *pid, od_syslog_t *syslog)
|
||||
int od_log_init(od_log_t *log, od_pid_t *pid, od_syslog_t *syslog)
|
||||
{
|
||||
l->verbosity = 0;
|
||||
l->pid = pid;
|
||||
l->syslog = syslog;
|
||||
l->fd = 0;
|
||||
log->verbosity = 0;
|
||||
log->pid = pid;
|
||||
log->syslog = syslog;
|
||||
log->fd = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int od_log_open(od_log_t *l, char *path)
|
||||
int od_log_open(od_log_t *log, char *path)
|
||||
{
|
||||
int rc = open(path, O_RDWR|O_CREAT|O_APPEND, 0644);
|
||||
if (rc == -1)
|
||||
return -1;
|
||||
l->fd = rc;
|
||||
log->fd = rc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int od_log_close(od_log_t *l)
|
||||
int od_log_close(od_log_t *log)
|
||||
{
|
||||
if (l->fd == -1)
|
||||
if (log->fd == -1)
|
||||
return 0;
|
||||
int rc = close(l->fd);
|
||||
l->fd = -1;
|
||||
int rc = close(log->fd);
|
||||
log->fd = -1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
int od_logv(od_log_t *l, od_syslogprio_t prio,
|
||||
machine_io_t peer,
|
||||
int od_logv(od_log_t *log, od_syslogprio_t prio,
|
||||
char *ident,
|
||||
char *object,
|
||||
uint64_t object_id,
|
||||
char *state,
|
||||
char *fmt, va_list args)
|
||||
{
|
||||
char buffer[512];
|
||||
|
||||
/* pid */
|
||||
int len = snprintf(buffer, sizeof(buffer), "%d ", l->pid->pid);
|
||||
int len;
|
||||
len = snprintf(buffer, sizeof(buffer), "%d ", log->pid->pid);
|
||||
/* time */
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
|
@ -69,20 +74,27 @@ int od_logv(od_log_t *l, od_syslogprio_t prio,
|
|||
localtime(&tv.tv_sec));
|
||||
len += snprintf(buffer + len, sizeof(buffer) - len, "%03d ",
|
||||
(int)tv.tv_usec / 1000);
|
||||
/* message ident */
|
||||
/* ident */
|
||||
if (ident)
|
||||
len += snprintf(buffer + len, sizeof(buffer) - len, "%s ", ident);
|
||||
/* peer */
|
||||
if (peer) {
|
||||
char peer_name[128];
|
||||
od_getpeername(peer, peer_name, sizeof(peer_name));
|
||||
len += snprintf(buffer + len, sizeof(buffer) - len, "%s ", peer_name);
|
||||
|
||||
/* object and id */
|
||||
if (object) {
|
||||
len += snprintf(buffer + len, sizeof(buffer) - len, "%s%" PRIu64": ",
|
||||
object, object_id);
|
||||
}
|
||||
|
||||
/* state */
|
||||
if (state) {
|
||||
len += snprintf(buffer + len, sizeof(buffer) - len, "(%s) ", state);
|
||||
}
|
||||
|
||||
/* message */
|
||||
len += vsnprintf(buffer + len, sizeof(buffer) - len, fmt, args);
|
||||
va_end(args);
|
||||
len += snprintf(buffer + len, sizeof(buffer), "\n");
|
||||
int rc = write(l->fd, buffer, len);
|
||||
od_syslog(l->syslog, prio, buffer);
|
||||
|
||||
int rc = write(log->fd, buffer, len);
|
||||
od_syslog(log->syslog, prio, buffer);
|
||||
return rc > 0;
|
||||
}
|
||||
|
|
77
src/od_log.h
77
src/od_log.h
|
@ -20,41 +20,96 @@ struct od_log
|
|||
int od_log_init(od_log_t*, od_pid_t*, od_syslog_t*);
|
||||
int od_log_open(od_log_t*, char*);
|
||||
int od_log_close(od_log_t*);
|
||||
int od_logv(od_log_t*, od_syslogprio_t, machine_io_t, char*, char*, va_list);
|
||||
int od_logv(od_log_t*, od_syslogprio_t, char*,
|
||||
char*, uint64_t, char*,
|
||||
char*, va_list);
|
||||
|
||||
static inline void
|
||||
od_logset_verbosity(od_log_t *l, int level) {
|
||||
l->verbosity = level;
|
||||
od_logset_verbosity(od_log_t *log, int level)
|
||||
{
|
||||
log->verbosity = level;
|
||||
}
|
||||
|
||||
static inline int
|
||||
od_log(od_log_t *l, machine_io_t peer, char *fmt, ...)
|
||||
od_log(od_log_t *log, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int rc = od_logv(l, OD_SYSLOG_INFO, peer, NULL, fmt, args);
|
||||
int rc = od_logv(log, OD_SYSLOG_INFO, NULL, NULL, 0, NULL, fmt, args);
|
||||
va_end(args);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static inline int
|
||||
od_debug(od_log_t *l, machine_io_t peer, char *fmt, ...)
|
||||
od_error(od_log_t *log, char *fmt, ...)
|
||||
{
|
||||
if (l->verbosity < 2)
|
||||
return 0;
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int rc = od_logv(l, OD_SYSLOG_DEBUG, peer, "debug:", fmt, args);
|
||||
int rc = od_logv(log, OD_SYSLOG_ERROR, "error:", NULL, 0, NULL, fmt, args);
|
||||
va_end(args);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* client */
|
||||
|
||||
static inline int
|
||||
od_log_client(od_log_t *log, uint64_t id, char *state, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int rc = od_logv(log, OD_SYSLOG_INFO, NULL, "C", id, state, fmt, args);
|
||||
va_end(args);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static inline int
|
||||
od_error(od_log_t *l, machine_io_t peer, char *fmt, ...)
|
||||
od_debug_client(od_log_t *log, uint64_t id, char *state, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int rc = od_logv(l, OD_SYSLOG_ERROR, peer, "error:", fmt, args);
|
||||
int rc = od_logv(log, OD_SYSLOG_INFO, "debug:", "C", id, state, fmt, args);
|
||||
va_end(args);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static inline int
|
||||
od_error_client(od_log_t *log, uint64_t id, char *state, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int rc = od_logv(log, OD_SYSLOG_ERROR, "error:", "C", id, state, fmt, args);
|
||||
va_end(args);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* server */
|
||||
|
||||
static inline int
|
||||
od_log_server(od_log_t *log, uint64_t id, char *state, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int rc = od_logv(log, OD_SYSLOG_INFO, NULL, "S", id, state, fmt, args);
|
||||
va_end(args);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static inline int
|
||||
od_debug_server(od_log_t *log, uint64_t id, char *state, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int rc = od_logv(log, OD_SYSLOG_INFO, "debug:", "S", id, state, fmt, args);
|
||||
va_end(args);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static inline int
|
||||
od_error_server(od_log_t *log, uint64_t id, char *state, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int rc = od_logv(log, OD_SYSLOG_ERROR, "error:", "S", id, state, fmt, args);
|
||||
va_end(args);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <machinarium.h>
|
||||
|
@ -51,15 +52,15 @@ od_periodic_stats (od_router_t *router)
|
|||
od_instance_t *instance = router->system->instance;
|
||||
if (router->route_pool.count == 0)
|
||||
return;
|
||||
od_log(&instance->log, NULL, "statistics");
|
||||
od_log(&instance->log, "statistics");
|
||||
od_list_t *i;
|
||||
od_list_foreach(&router->route_pool.list, i) {
|
||||
od_route_t *route;
|
||||
route = od_container_of(i, od_route_t, link);
|
||||
od_log(&instance->log, NULL,
|
||||
od_log(&instance->log,
|
||||
" [%.*s, %.*s] clients %d, "
|
||||
"pool_active %d, "
|
||||
"pool_idle %d ",
|
||||
"pool_active %d, "
|
||||
"pool_idle %d ",
|
||||
route->id.database_len,
|
||||
route->id.database,
|
||||
route->id.user_len,
|
||||
|
@ -86,8 +87,9 @@ od_expire_mark(od_server_t *server, void *arg)
|
|||
*/
|
||||
if (! route->scheme->ttl)
|
||||
return 0;
|
||||
od_debug(&instance->log, server->io, "S: idle time: %d",
|
||||
server->idle_time);
|
||||
od_debug_server(&instance->log, server->id, "expire",
|
||||
"idle time: %d",
|
||||
server->idle_time);
|
||||
if (server->idle_time < route->scheme->ttl) {
|
||||
server->idle_time++;
|
||||
return 0;
|
||||
|
@ -97,7 +99,6 @@ od_expire_mark(od_server_t *server, void *arg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void od_periodic(void *arg)
|
||||
{
|
||||
od_router_t *router = arg;
|
||||
|
@ -145,9 +146,9 @@ void od_periodic(void *arg)
|
|||
server = od_routepool_next(&router->route_pool, OD_SEXPIRE);
|
||||
if (server == NULL)
|
||||
break;
|
||||
od_debug(&instance->log, server->io,
|
||||
"S: closing idle connection (%d secs)",
|
||||
server->idle_time);
|
||||
od_debug_server(&instance->log, server->id, "expire",
|
||||
"closing idle connection (%d secs)",
|
||||
server->idle_time);
|
||||
server->idle_time = 0;
|
||||
|
||||
od_route_t *route = server->route;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <machinarium.h>
|
||||
|
@ -42,6 +43,8 @@ od_pooler(void *arg)
|
|||
od_pooler_t *pooler = arg;
|
||||
od_instance_t *instance = pooler->system->instance;
|
||||
|
||||
od_log(&instance->log, "(pooler) started");
|
||||
|
||||
/* init pooler tls */
|
||||
int rc;
|
||||
#if 0
|
||||
|
@ -77,7 +80,7 @@ od_pooler(void *arg)
|
|||
struct addrinfo *ai = NULL;
|
||||
rc = machine_getaddrinfo(host, port, hints_ptr, &ai, UINT32_MAX);
|
||||
if (rc < 0) {
|
||||
od_error(&instance->log, NULL, "failed to resolve %s:%d",
|
||||
od_error(&instance->log, "failed to resolve %s:%d",
|
||||
instance->scheme.host,
|
||||
instance->scheme.port);
|
||||
return;
|
||||
|
@ -87,7 +90,7 @@ od_pooler(void *arg)
|
|||
/* io */
|
||||
pooler->server = machine_io_create();
|
||||
if (pooler->server == NULL) {
|
||||
od_error(&instance->log, NULL, "failed to create pooler io");
|
||||
od_error(&instance->log, "failed to create pooler io");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -95,16 +98,16 @@ od_pooler(void *arg)
|
|||
rc = machine_bind(pooler->server, ai->ai_addr);
|
||||
freeaddrinfo(ai);
|
||||
if (rc < 0) {
|
||||
od_error(&instance->log, NULL, "bind %s:%d failed",
|
||||
od_error(&instance->log, "bind %s:%d failed",
|
||||
instance->scheme.host,
|
||||
instance->scheme.port);
|
||||
return;
|
||||
}
|
||||
|
||||
od_log(&instance->log, NULL, "listening on %s:%d",
|
||||
od_log(&instance->log, "(pooler) listening on %s:%d",
|
||||
instance->scheme.host,
|
||||
instance->scheme.port);
|
||||
od_log(&instance->log, NULL, "");
|
||||
od_log(&instance->log, "");
|
||||
|
||||
/* main loop */
|
||||
while (machine_active())
|
||||
|
@ -113,7 +116,7 @@ od_pooler(void *arg)
|
|||
rc = machine_accept(pooler->server, &client_io,
|
||||
instance->scheme.backlog, UINT32_MAX);
|
||||
if (rc < 0) {
|
||||
od_error(&instance->log, NULL, "accept failed");
|
||||
od_error(&instance->log, "pooler accept failed");
|
||||
continue;
|
||||
}
|
||||
/* todo: client_max limit */
|
||||
|
@ -124,7 +127,7 @@ od_pooler(void *arg)
|
|||
machine_set_keepalive(client_io, 1, instance->scheme.keepalive);
|
||||
rc = machine_set_readahead(client_io, instance->scheme.readahead);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, NULL, "failed to set client readahead");
|
||||
od_error(&instance->log, "failed to set client readahead");
|
||||
machine_close(client_io);
|
||||
machine_io_free(client_io);
|
||||
continue;
|
||||
|
@ -133,8 +136,7 @@ od_pooler(void *arg)
|
|||
/* detach io from pooler event loop */
|
||||
rc = machine_io_detach(client_io);
|
||||
if (rc == -1) {
|
||||
od_error(&instance->log, client_io,
|
||||
"failed to transfer client io");
|
||||
od_error(&instance->log, "failed to transfer client io");
|
||||
machine_close(client_io);
|
||||
machine_io_free(client_io);
|
||||
continue;
|
||||
|
@ -143,8 +145,7 @@ od_pooler(void *arg)
|
|||
/* allocate new client */
|
||||
od_client_t *client = od_client_allocate();
|
||||
if (client == NULL) {
|
||||
od_error(&instance->log, client_io,
|
||||
"failed to allocate client object");
|
||||
od_error(&instance->log, "failed to allocate client object");
|
||||
machine_close(client_io);
|
||||
machine_io_free(client_io);
|
||||
continue;
|
||||
|
@ -175,7 +176,7 @@ int od_pooler_start(od_pooler_t *pooler)
|
|||
od_instance_t *instance = pooler->system->instance;
|
||||
pooler->machine = machine_create("pooler", od_pooler, pooler);
|
||||
if (pooler->machine == -1) {
|
||||
od_error(&instance->log, NULL, "failed to start server");
|
||||
od_error(&instance->log, "failed to start server");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <machinarium.h>
|
||||
|
@ -46,7 +47,7 @@ od_relay(void *arg)
|
|||
od_relay_t *relay = arg;
|
||||
od_instance_t *instance = relay->system->instance;
|
||||
|
||||
od_log(&instance->log, NULL, "relay: started");
|
||||
od_log(&instance->log, "(relay) started");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
|
@ -66,7 +67,8 @@ od_relay(void *arg)
|
|||
int64_t coroutine_id;
|
||||
coroutine_id = machine_coroutine_create(od_frontend, client);
|
||||
if (coroutine_id == -1) {
|
||||
od_error(&instance->log, client->io, "failed to create coroutine");
|
||||
od_error_client(&instance->log, client->id, "relay",
|
||||
"failed to create coroutine");
|
||||
machine_close(client->io);
|
||||
od_client_free(client);
|
||||
break;
|
||||
|
@ -82,7 +84,7 @@ od_relay(void *arg)
|
|||
machine_msg_free(msg);
|
||||
}
|
||||
|
||||
od_log(&instance->log, NULL, "relay: stopped");
|
||||
od_log(&instance->log, "(relay) stopped");
|
||||
}
|
||||
|
||||
void od_relay_init(od_relay_t *relay, od_system_t *system)
|
||||
|
@ -96,7 +98,7 @@ int od_relay_start(od_relay_t *relay)
|
|||
od_instance_t *instance = relay->system->instance;
|
||||
relay->machine = machine_create("relay", od_relay, relay);
|
||||
if (relay->machine == -1) {
|
||||
od_error(&instance->log, NULL, "failed to start relay");
|
||||
od_error(&instance->log, "failed to start relay");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <machinarium.h>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <machinarium.h>
|
||||
|
@ -96,7 +97,7 @@ od_router_fwd(od_router_t *router, so_bestartup_t *startup)
|
|||
return route;
|
||||
route = od_routepool_new(&router->route_pool, route_scheme, &id);
|
||||
if (route == NULL) {
|
||||
od_error(&instance->log, NULL, "failed to allocate route");
|
||||
od_error(&instance->log, "failed to allocate route");
|
||||
return NULL;
|
||||
}
|
||||
return route;
|
||||
|
@ -124,13 +125,17 @@ od_router_attacher(void *arg)
|
|||
|
||||
/* TODO: wait */
|
||||
|
||||
od_router_t *router;
|
||||
router = client->system->router;
|
||||
|
||||
/* create new backend connection */
|
||||
server = od_backend_new(client->system->router, route);
|
||||
server = od_backend_new(router, route);
|
||||
if (server == NULL) {
|
||||
msg_attach->status = OD_RERROR;
|
||||
machine_queue_put(msg_attach->response, msg);
|
||||
return;
|
||||
}
|
||||
server->id = router->server_seq++;
|
||||
|
||||
/* detach server io from router context */
|
||||
machine_io_detach(server->io);
|
||||
|
@ -150,14 +155,13 @@ od_router(void *arg)
|
|||
od_router_t *router = arg;
|
||||
od_instance_t *instance = router->system->instance;
|
||||
|
||||
od_log(&instance->log, NULL, "router: started");
|
||||
od_log(&instance->log, "(router) started");
|
||||
|
||||
/* start periodic task coroutine */
|
||||
int64_t coroutine_id;
|
||||
coroutine_id = machine_coroutine_create(od_periodic, router);
|
||||
if (coroutine_id == -1) {
|
||||
od_error(&instance->log, NULL,
|
||||
"failed to create periodic coroutine");
|
||||
od_error(&instance->log, "failed to create periodic coroutine");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -189,8 +193,8 @@ od_router(void *arg)
|
|||
int client_total;
|
||||
client_total = od_clientpool_total(&route->client_pool);
|
||||
if (client_total >= route->scheme->client_max) {
|
||||
od_log(&instance->log, NULL,
|
||||
"router: route '%s' client_max reached (%d)",
|
||||
od_log(&instance->log,
|
||||
"(router) route '%s' client_max reached (%d)",
|
||||
route->scheme->target,
|
||||
route->scheme->client_max);
|
||||
msg_route->status = OD_RERROR_LIMIT;
|
||||
|
@ -319,9 +323,10 @@ int od_router_init(od_router_t *router, od_system_t *system)
|
|||
od_routepool_init(&router->route_pool);
|
||||
router->machine = -1;
|
||||
router->system = system;
|
||||
router->server_seq = 0;
|
||||
router->queue = machine_queue_create();
|
||||
if (router->queue == NULL) {
|
||||
od_error(&instance->log, NULL, "failed to create router queue");
|
||||
od_error(&instance->log, "failed to create router queue");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -332,7 +337,7 @@ int od_router_start(od_router_t *router)
|
|||
od_instance_t *instance = router->system->instance;
|
||||
router->machine = machine_create("router", od_router, router);
|
||||
if (router->machine == -1) {
|
||||
od_error(&instance->log, NULL, "failed to start router");
|
||||
od_error(&instance->log, "failed to start router");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -22,6 +22,7 @@ struct od_router
|
|||
int64_t machine;
|
||||
od_routepool_t route_pool;
|
||||
machine_queue_t queue;
|
||||
uint64_t server_seq;
|
||||
od_system_t *system;
|
||||
};
|
||||
|
||||
|
|
143
src/od_scheme.c
143
src/od_scheme.c
|
@ -9,6 +9,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <machinarium.h>
|
||||
|
||||
|
@ -178,7 +179,7 @@ int od_scheme_validate(od_scheme_t *scheme, od_log_t *log)
|
|||
{
|
||||
/* pooling mode */
|
||||
if (scheme->pooling == NULL) {
|
||||
od_error(log, NULL, "pooling mode is not set");
|
||||
od_error(log, "pooling mode is not set");
|
||||
return -1;
|
||||
}
|
||||
if (strcmp(scheme->pooling, "session") == 0)
|
||||
|
@ -188,20 +189,20 @@ int od_scheme_validate(od_scheme_t *scheme, od_log_t *log)
|
|||
scheme->pooling_mode = OD_PTRANSACTION;
|
||||
|
||||
if (scheme->pooling_mode == OD_PUNDEF) {
|
||||
od_error(log, NULL, "unknown pooling mode");
|
||||
od_error(log, "unknown pooling mode");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* routing mode */
|
||||
if (scheme->routing == NULL) {
|
||||
od_error(log, NULL, "routing mode is not set");
|
||||
od_error(log, "routing mode is not set");
|
||||
return -1;
|
||||
}
|
||||
if (strcmp(scheme->routing, "forward") == 0)
|
||||
scheme->routing_mode = OD_RFORWARD;
|
||||
|
||||
if (scheme->routing_mode == OD_RUNDEF) {
|
||||
od_error(log, NULL, "unknown routing mode");
|
||||
od_error(log, "unknown routing mode");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -226,14 +227,14 @@ int od_scheme_validate(od_scheme_t *scheme, od_log_t *log)
|
|||
if (strcmp(scheme->tls_mode, "verify_full") == 0) {
|
||||
scheme->tls_verify = OD_TVERIFY_FULL;
|
||||
} else {
|
||||
od_error(log, NULL, "unknown tls mode");
|
||||
od_error(log, "unknown tls mode");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* servers */
|
||||
if (od_list_empty(&scheme->servers)) {
|
||||
od_error(log, NULL, "no servers defined");
|
||||
od_error(log, "no servers defined");
|
||||
return -1;
|
||||
}
|
||||
od_list_t *i;
|
||||
|
@ -241,7 +242,7 @@ int od_scheme_validate(od_scheme_t *scheme, od_log_t *log)
|
|||
od_schemeserver_t *server;
|
||||
server = od_container_of(i, od_schemeserver_t, link);
|
||||
if (server->host == NULL) {
|
||||
od_error(log, NULL, "server '%s': no host is specified",
|
||||
od_error(log, "server '%s': no host is specified",
|
||||
server->name);
|
||||
return -1;
|
||||
}
|
||||
|
@ -261,7 +262,7 @@ int od_scheme_validate(od_scheme_t *scheme, od_log_t *log)
|
|||
if (strcmp(server->tls_mode, "verify_full") == 0) {
|
||||
server->tls_verify = OD_TVERIFY_FULL;
|
||||
} else {
|
||||
od_error(log, NULL, "unknown server tls mode");
|
||||
od_error(log, "unknown server tls mode");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -274,19 +275,19 @@ int od_scheme_validate(od_scheme_t *scheme, od_log_t *log)
|
|||
od_schemeroute_t *route;
|
||||
route = od_container_of(i, od_schemeroute_t, link);
|
||||
if (route->route == NULL) {
|
||||
od_error(log, NULL, "route '%s': no route server is specified",
|
||||
od_error(log, "route '%s': no route server is specified",
|
||||
route->target);
|
||||
return -1;
|
||||
}
|
||||
route->server = od_schemeserver_match(scheme, route->route);
|
||||
if (route->server == NULL) {
|
||||
od_error(log, NULL, "route '%s': no route server '%s' found",
|
||||
od_error(log, "route '%s': no route server '%s' found",
|
||||
route->target);
|
||||
return -1;
|
||||
}
|
||||
if (route->is_default) {
|
||||
if (default_route) {
|
||||
od_error(log, NULL, "more than one default route");
|
||||
od_error(log, "more than one default route");
|
||||
return -1;
|
||||
}
|
||||
default_route = route;
|
||||
|
@ -296,7 +297,7 @@ int od_scheme_validate(od_scheme_t *scheme, od_log_t *log)
|
|||
|
||||
/* users */
|
||||
if (od_list_empty(&scheme->users)) {
|
||||
od_error(log, NULL, "no users defined");
|
||||
od_error(log, "no users defined");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -307,9 +308,9 @@ int od_scheme_validate(od_scheme_t *scheme, od_log_t *log)
|
|||
user = od_container_of(i, od_schemeuser_t, link);
|
||||
if (! user->auth) {
|
||||
if (user->is_default)
|
||||
od_error(log, NULL, "default user authentication mode is not defined");
|
||||
od_error(log, "default user authentication mode is not defined");
|
||||
else
|
||||
od_error(log, NULL, "user '%s' authentication mode is not defined",
|
||||
od_error(log, "user '%s' authentication mode is not defined",
|
||||
user->user);
|
||||
return -1;
|
||||
}
|
||||
|
@ -319,7 +320,7 @@ int od_scheme_validate(od_scheme_t *scheme, od_log_t *log)
|
|||
if (strcmp(user->auth, "clear_text") == 0) {
|
||||
user->auth_mode = OD_ACLEAR_TEXT;
|
||||
if (user->password == NULL) {
|
||||
od_error(log, NULL, "user '%s' password is not set",
|
||||
od_error(log, "user '%s' password is not set",
|
||||
user->user);
|
||||
return -1;
|
||||
}
|
||||
|
@ -327,18 +328,18 @@ int od_scheme_validate(od_scheme_t *scheme, od_log_t *log)
|
|||
if (strcmp(user->auth, "md5") == 0) {
|
||||
user->auth_mode = OD_AMD5;
|
||||
if (user->password == NULL) {
|
||||
od_error(log, NULL, "user '%s' password is not set",
|
||||
od_error(log, "user '%s' password is not set",
|
||||
user->user);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
od_error(log, NULL, "user '%s' has unknown authentication mode",
|
||||
od_error(log, "user '%s' has unknown authentication mode",
|
||||
user->user);
|
||||
return -1;
|
||||
}
|
||||
if (user->is_default) {
|
||||
if (default_user) {
|
||||
od_error(log, NULL, "more than one default user");
|
||||
od_error(log, "more than one default user");
|
||||
return -1;
|
||||
}
|
||||
default_user = user;
|
||||
|
@ -350,102 +351,102 @@ int od_scheme_validate(od_scheme_t *scheme, od_log_t *log)
|
|||
|
||||
void od_scheme_print(od_scheme_t *scheme, od_log_t *log)
|
||||
{
|
||||
od_log(log, NULL, "using configuration file '%s'",
|
||||
od_log(log, "using configuration file '%s'",
|
||||
scheme->config_file);
|
||||
if (scheme->log_verbosity)
|
||||
od_log(log, NULL, "log_verbosity %d", scheme->log_verbosity);
|
||||
od_log(log, "log_verbosity %d", scheme->log_verbosity);
|
||||
if (scheme->log_file)
|
||||
od_log(log, NULL, "log_file %s", scheme->log_file);
|
||||
od_log(log, "log_file %s", scheme->log_file);
|
||||
if (scheme->pid_file)
|
||||
od_log(log, NULL, "pid_file %s", scheme->pid_file);
|
||||
od_log(log, "pid_file %s", scheme->pid_file);
|
||||
if (scheme->syslog)
|
||||
od_log(log, NULL, "syslog %d", scheme->syslog);
|
||||
od_log(log, "syslog %d", scheme->syslog);
|
||||
if (scheme->syslog_ident)
|
||||
od_log(log, NULL, "syslog_ident %s", scheme->syslog_ident);
|
||||
od_log(log, "syslog_ident %s", scheme->syslog_ident);
|
||||
if (scheme->syslog_facility)
|
||||
od_log(log, NULL, "syslog_facility %s", scheme->syslog_facility);
|
||||
od_log(log, "syslog_facility %s", scheme->syslog_facility);
|
||||
if (scheme->stats_period)
|
||||
od_log(log, NULL, "stats_period %d", scheme->stats_period);
|
||||
od_log(log, "stats_period %d", scheme->stats_period);
|
||||
if (scheme->daemonize)
|
||||
od_log(log, NULL, "daemonize %s",
|
||||
od_log(log, "daemonize %s",
|
||||
scheme->daemonize ? "yes" : "no");
|
||||
od_log(log, NULL, "");
|
||||
od_log(log, NULL, "pooling %s", scheme->pooling);
|
||||
od_log(log, NULL, "");
|
||||
od_log(log, NULL, "listen");
|
||||
od_log(log, NULL, " host %s ", scheme->host);
|
||||
od_log(log, NULL, " port %d", scheme->port);
|
||||
od_log(log, NULL, " backlog %d", scheme->backlog);
|
||||
od_log(log, NULL, " nodelay %d", scheme->nodelay);
|
||||
od_log(log, NULL, " keepalive %d", scheme->keepalive);
|
||||
od_log(log, NULL, " readahead %d", scheme->readahead);
|
||||
od_log(log, "");
|
||||
od_log(log, "pooling %s", scheme->pooling);
|
||||
od_log(log, "");
|
||||
od_log(log, "listen");
|
||||
od_log(log, " host %s ", scheme->host);
|
||||
od_log(log, " port %d", scheme->port);
|
||||
od_log(log, " backlog %d", scheme->backlog);
|
||||
od_log(log, " nodelay %d", scheme->nodelay);
|
||||
od_log(log, " keepalive %d", scheme->keepalive);
|
||||
od_log(log, " readahead %d", scheme->readahead);
|
||||
if (scheme->tls_mode)
|
||||
od_log(log, NULL, " tls_mode %s", scheme->tls_mode);
|
||||
od_log(log, " tls_mode %s", scheme->tls_mode);
|
||||
if (scheme->tls_ca_file)
|
||||
od_log(log, NULL, " tls_ca_file %s", scheme->tls_ca_file);
|
||||
od_log(log, " tls_ca_file %s", scheme->tls_ca_file);
|
||||
if (scheme->tls_key_file)
|
||||
od_log(log, NULL, " tls_key_file %s", scheme->tls_key_file);
|
||||
od_log(log, " tls_key_file %s", scheme->tls_key_file);
|
||||
if (scheme->tls_cert_file)
|
||||
od_log(log, NULL, " tls_cert_file %s", scheme->tls_cert_file);
|
||||
od_log(log, " tls_cert_file %s", scheme->tls_cert_file);
|
||||
if (scheme->tls_protocols)
|
||||
od_log(log, NULL, " tls_protocols %s", scheme->tls_protocols);
|
||||
od_log(log, NULL, "");
|
||||
od_log(log, NULL, "servers");
|
||||
od_log(log, " tls_protocols %s", scheme->tls_protocols);
|
||||
od_log(log, "");
|
||||
od_log(log, "servers");
|
||||
od_list_t *i;
|
||||
od_list_foreach(&scheme->servers, i) {
|
||||
od_schemeserver_t *server;
|
||||
server = od_container_of(i, od_schemeserver_t, link);
|
||||
od_log(log, NULL, " <%s> %s",
|
||||
od_log(log, " <%s> %s",
|
||||
server->name ? server->name : "",
|
||||
server->is_default ? "default" : "");
|
||||
od_log(log, NULL, " host %s", server->host);
|
||||
od_log(log, NULL, " port %d", server->port);
|
||||
od_log(log, " host %s", server->host);
|
||||
od_log(log, " port %d", server->port);
|
||||
if (server->tls_mode)
|
||||
od_log(log, NULL, " tls_mode %s", server->tls_mode);
|
||||
od_log(log, " tls_mode %s", server->tls_mode);
|
||||
if (server->tls_ca_file)
|
||||
od_log(log, NULL, " tls_ca_file %s", server->tls_ca_file);
|
||||
od_log(log, " tls_ca_file %s", server->tls_ca_file);
|
||||
if (server->tls_key_file)
|
||||
od_log(log, NULL, " tls_key_file %s", server->tls_key_file);
|
||||
od_log(log, " tls_key_file %s", server->tls_key_file);
|
||||
if (server->tls_cert_file)
|
||||
od_log(log, NULL, " tls_cert_file %s", server->tls_cert_file);
|
||||
od_log(log, " tls_cert_file %s", server->tls_cert_file);
|
||||
if (server->tls_protocols)
|
||||
od_log(log, NULL, " tls_protocols %s", server->tls_protocols);
|
||||
od_log(log, " tls_protocols %s", server->tls_protocols);
|
||||
}
|
||||
od_log(log, NULL, "");
|
||||
od_log(log, NULL, "routing");
|
||||
od_log(log, NULL, " mode %s", scheme->routing);
|
||||
od_log(log, "");
|
||||
od_log(log, "routing");
|
||||
od_log(log, " mode %s", scheme->routing);
|
||||
od_list_foreach(&scheme->routing_table, i) {
|
||||
od_schemeroute_t *route;
|
||||
route = od_container_of(i, od_schemeroute_t, link);
|
||||
od_log(log, NULL, " <%s>", route->target);
|
||||
od_log(log, NULL, " server %s", route->route);
|
||||
od_log(log, " <%s>", route->target);
|
||||
od_log(log, " server %s", route->route);
|
||||
if (route->database)
|
||||
od_log(log, NULL, " database %s", route->database);
|
||||
od_log(log, " database %s", route->database);
|
||||
if (route->user)
|
||||
od_log(log, NULL, " user %s", route->user);
|
||||
od_log(log, NULL, " ttl %d", route->ttl);
|
||||
od_log(log, NULL, " cancel %s",
|
||||
od_log(log, " user %s", route->user);
|
||||
od_log(log, " ttl %d", route->ttl);
|
||||
od_log(log, " cancel %s",
|
||||
route->discard ? "yes" : "no");
|
||||
od_log(log, NULL, " rollback %s",
|
||||
od_log(log, " rollback %s",
|
||||
route->discard ? "yes" : "no");
|
||||
od_log(log, NULL, " discard %s",
|
||||
od_log(log, " discard %s",
|
||||
route->discard ? "yes" : "no");
|
||||
od_log(log, NULL, " pool_size %d", route->pool_size);
|
||||
od_log(log, NULL, " pool_timeout %d", route->pool_timeout);
|
||||
od_log(log, " pool_size %d", route->pool_size);
|
||||
od_log(log, " pool_timeout %d", route->pool_timeout);
|
||||
}
|
||||
if (! od_list_empty(&scheme->users)) {
|
||||
od_log(log, NULL, "");
|
||||
od_log(log, NULL, "users");
|
||||
od_log(log, "");
|
||||
od_log(log, "users");
|
||||
od_list_foreach(&scheme->users, i) {
|
||||
od_schemeuser_t *user;
|
||||
user = od_container_of(i, od_schemeuser_t, link);
|
||||
if (user->is_default)
|
||||
od_log(log, NULL, " default");
|
||||
od_log(log, " default");
|
||||
else
|
||||
od_log(log, NULL, " <%s>", user->user);
|
||||
od_log(log, " <%s>", user->user);
|
||||
if (user->is_deny)
|
||||
od_log(log, NULL, " deny");
|
||||
od_log(log, NULL, " authentication %s", user->auth);
|
||||
od_log(log, " deny");
|
||||
od_log(log, " authentication %s", user->auth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ typedef enum
|
|||
struct od_server
|
||||
{
|
||||
od_serverstate_t state;
|
||||
uint64_t id;
|
||||
so_stream_t stream;
|
||||
machine_io_t io;
|
||||
machine_tls_t tls;
|
||||
|
@ -44,6 +45,7 @@ static inline void
|
|||
od_server_init(od_server_t *server)
|
||||
{
|
||||
server->state = OD_SUNDEF;
|
||||
server->id = 0;
|
||||
server->route = NULL;
|
||||
server->system = NULL;
|
||||
server->io = NULL;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <machinarium.h>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <syslog.h>
|
||||
|
||||
|
|
Loading…
Reference in New Issue