Ejemplo n.º 1
0
static void
control_connection_reset_stats(ControlConnection *cc, GString *command, gpointer user_data)
{
  GString *result = g_string_new("OK The statistics of syslog-ng have been reset to 0.");
  stats_reset_counters();
  control_connection_send_reply(cc, result);
}
Ejemplo n.º 2
0
static void
control_connection_send_stats(ControlConnection *cc, GString *command, gpointer user_data)
{
  gchar *stats = stats_generate_csv();
  GString *result = g_string_new(stats);
  g_free(stats);
  control_connection_send_reply(cc, result);
}
Ejemplo n.º 3
0
static void
control_connection_message_log(ControlConnection *self, GString *command)
{
  gchar **cmds = g_strsplit(command->str, " ", 3);
  gboolean on;
  int *type = NULL;

  if (!cmds[1])
    {
      control_connection_send_reply(self, "Invalid arguments received, expected at least one argument", FALSE);
      goto exit;
    }

  if (g_str_equal(cmds[1], "DEBUG"))
    type = &debug_flag;
  else if (g_str_equal(cmds[1], "VERBOSE")) 
    type = &verbose_flag;
  else if (g_str_equal(cmds[1], "TRACE")) 
    type = &trace_flag;

  if (type)
    {
      if (cmds[2])
        {
          on = g_str_equal(cmds[2], "ON");
          if (*type != on)
            {
              msg_info("Verbosity changed", evt_tag_str("type", cmds[1]), evt_tag_int("on", on), NULL);
              *type = on;
            }

          control_connection_send_reply(self, "OK", FALSE);
        }
      else
        {
          control_connection_send_reply(self, g_strdup_printf("%s=%d", cmds[1], *type), TRUE);
        }
    }
  else
    control_connection_send_reply(self, "Invalid arguments received", FALSE);

exit:
  g_strfreev(cmds);
}
Ejemplo n.º 4
0
static void
control_connection_send_stats(ControlConnection *self, GString *command)
{
  control_connection_send_reply(self, stats_generate_csv(), TRUE);
}
Ejemplo n.º 5
0
static void
control_connection_reload(ControlConnection *self, GString *command)
{
  main_loop_reload_config_initiate();
  control_connection_send_reply(self, "OK Config reload initiated", FALSE);
}
Ejemplo n.º 6
0
static void
control_connection_io_input(void *s)
{
  ControlConnection *self = (ControlConnection *) s;
  GString *command = NULL;
  GString *reply = NULL;
  gchar *nl;
  gint rc;
  gint orig_len;
  GList *iter;

  if (self->input_buffer->len > MAX_CONTROL_LINE_LENGTH)
    {
      /* too much data in input, drop the connection */
      msg_error("Too much data in the control socket input buffer",
                NULL);
      control_connection_stop_watches(self);
      control_connection_free(self);
      return;
    }

  orig_len = self->input_buffer->len;

  /* NOTE: plus one for the terminating NUL */
  g_string_set_size(self->input_buffer, self->input_buffer->len + 128 + 1);
  rc = self->read(self, self->input_buffer->str + orig_len, 128);
  if (rc < 0)
    {
      if (errno != EAGAIN)
        {
          msg_error("Error reading command on control channel, closing control channel",
                    evt_tag_errno("error", errno),
                    NULL);
          goto destroy_connection;
        }
      /* EAGAIN, should try again when data comes */
      control_connection_update_watches(self);
      return;
    }
  else if (rc == 0)
    {
      msg_debug("EOF on control channel, closing connection",
                NULL);
      goto destroy_connection;
    }
  else
    {
      self->input_buffer->len = orig_len + rc;
      self->input_buffer->str[self->input_buffer->len] = 0;
    }

  /* here we have finished reading the input, check if there's a newline somewhere */
  nl = strchr(self->input_buffer->str, '\n');
  if (nl)
    {
      command = g_string_sized_new(128);
      /* command doesn't contain NL */
      g_string_assign_len(command, self->input_buffer->str, nl - self->input_buffer->str);
      /* strip NL */
      /*g_string_erase(self->input_buffer, 0, command->len + 1);*/
      g_string_truncate(self->input_buffer, 0);
    }
  else
    {
      /* no EOL in the input buffer, wait for more data */
      control_connection_update_watches(self);
      return;
    }

  for (iter = self->server->control_commands; iter != NULL; iter = iter->next)
    {
      if (strncmp(((ControlCommand*)iter->data)->command_name, command->str, strlen(((ControlCommand*)iter->data)->command_name)) == 0)
        {
          reply = ((ControlCommand*)iter->data)->func(command);
          control_connection_send_reply(self, reply);
          break;
        }
    }
  if (iter == NULL)
    {
      msg_error("Unknown command read on control channel, closing control channel",
                evt_tag_str("command", command->str), NULL);
      g_string_free(command, TRUE);
      goto destroy_connection;
    }
  control_connection_update_watches(self);
  g_string_free(command, TRUE);
  return;
 destroy_connection:
  control_connection_stop_watches(self);
  control_connection_free(self);
}