Skip to content

Commit

Permalink
syslog-ng-ctl: add support for "attach debugger"
Browse files Browse the repository at this point in the history
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
  • Loading branch information
bazsi committed Oct 27, 2024
1 parent 3a402c3 commit ca8b036
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
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
17 changes: 17 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_console_is_released_or_peer_disappears(ControlConnection *cc, gint m
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 All @@ -149,6 +153,10 @@ control_connection_attach(ControlConnection *cc, GString *command, gpointer user
if (cmds[3] && !_control_process_log_level(cmds[3], result))
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");
Expand All @@ -174,7 +182,16 @@ control_connection_attach(ControlConnection *cc, GString *command, gpointer user
}
console_acquire_from_fds(fds);

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));
}
_wait_until_console_is_released_or_peer_disappears(cc, n_seconds, cancelled);
if (start_debugger && debugger_is_running())
{
debugger_stop();
}
g_string_assign(result, "OK [console output ends here]");
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

0 comments on commit ca8b036

Please sign in to comment.