Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syslog ng ctl attach debugger #327

Merged
merged 9 commits into from
Nov 12, 2024
5 changes: 5 additions & 0 deletions lib/debugger/debugger-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ _pipe_hook(LogPipe *s, LogMessage *msg, const LogPathOptions *path_options)
return debugger_stop_at_breakpoint(current_debugger, s, msg);
}

gboolean
debugger_is_running(void)
{
return current_debugger != NULL;
}

static void
_install_hook(gpointer user_data)
Expand Down
1 change: 1 addition & 0 deletions lib/debugger/debugger-main.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "debugger/debugger.h"
#include "cfg.h"

gboolean debugger_is_running(void);
void debugger_start(MainLoop *main_loop, GlobalConfig *cfg);
void debugger_stop(void);

Expand Down
19 changes: 19 additions & 0 deletions lib/mainloop-control.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "cfg-walker.h"
#include "logpipe.h"
#include "console.h"
#include "debugger/debugger-main.h"

#include <string.h>

Expand Down Expand Up @@ -121,9 +122,12 @@ _wait_until_peer_disappears(ControlConnection *cc, gint max_seconds, gboolean *c
static void
control_connection_attach(ControlConnection *cc, GString *command, gpointer user_data, gboolean *cancelled)
{
MainLoop *main_loop = (MainLoop *) user_data;
gchar **cmds = g_strsplit(command->str, " ", 4);

GString *result = g_string_sized_new(128);
gint n_seconds = -1;
gboolean start_debugger = FALSE;
struct
{
gboolean log_stderr;
Expand Down Expand Up @@ -155,6 +159,10 @@ control_connection_attach(ControlConnection *cc, GString *command, gpointer user
goto exit;
}
}
else if (g_str_equal(cmds[1], "DEBUGGER"))
{
start_debugger = TRUE;
}
else
{
g_string_assign(result, "FAIL This version of syslog-ng only supports attaching to STDIO or LOGS");
Expand Down Expand Up @@ -183,8 +191,19 @@ control_connection_attach(ControlConnection *cc, GString *command, gpointer user
log_stderr = new_values.log_stderr;
msg_set_log_level(new_values.log_level);

if (start_debugger && !debugger_is_running())
{
//cfg_load_module(self->current_configuration, "mod-python");
debugger_start(main_loop, main_loop_get_current_config(main_loop));
alltilla marked this conversation as resolved.
Show resolved Hide resolved
}

_wait_until_peer_disappears(cc, n_seconds, cancelled);

if (start_debugger && debugger_is_running())
{
debugger_stop();
}

log_stderr = old_values.log_stderr;
msg_set_log_level(old_values.log_level);

Expand Down
4 changes: 3 additions & 1 deletion syslog-ng-ctl/commands/attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ GOptionEntry attach_options[] =
{
{ "seconds", 0, 0, G_OPTION_ARG_INT, &attach_options_seconds, "amount of time to attach for", NULL },
{ "log-level", 0, 0, G_OPTION_ARG_CALLBACK, _store_log_level, "change syslog-ng log level", "<default|verbose|debug|trace>" },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &attach_commands, "attach mode: logs, stdio", NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &attach_commands, "attach mode: logs, debugger, stdio", NULL },
{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
};

Expand All @@ -73,6 +73,8 @@ slng_attach(int argc, char *argv[], const gchar *mode, GOptionContext *ctx)
g_string_append(command, " STDIO");
else if (g_str_equal(attach_mode, "logs"))
g_string_append(command, " LOGS");
else if (g_str_equal(attach_mode, "debugger"))
g_string_append(command, " DEBUGGER");
else
{
fprintf(stderr, "Unknown attach mode\n");
Expand Down
Loading