コード例 #1
0
ファイル: affile-source.c プロジェクト: Achint08/syslog-ng
/* NOTE: runs in the main thread */
static void
affile_sd_notify(LogPipe *s, gint notify_code, gpointer user_data)
{
  AFFileSourceDriver *self = (AFFileSourceDriver *) s;
  GlobalConfig *cfg = log_pipe_get_config(s);
  gint fd;
  
  switch (notify_code)
    {
    case NC_FILE_MOVED:
      { 
        msg_verbose("Follow-mode file source moved, tracking of the new file is started",
                    evt_tag_str("filename", self->filename->str),
                    NULL);
        
        log_pipe_deinit((LogPipe *) self->reader);
        log_pipe_unref((LogPipe *) self->reader);
        self->reader = NULL;
        
        if (affile_sd_open_file(self, self->filename->str, &fd))
          {
            LogProtoServer *proto;
            PollEvents *poll_events;
            
            poll_events = affile_sd_construct_poll_events(self, fd);
            if (!poll_events)
              break;

            proto = affile_sd_construct_proto(self, fd);

            self->reader = log_reader_new(self->super.super.super.cfg);
            log_reader_reopen(self->reader, proto, poll_events);

            log_reader_set_options(self->reader,
                                   s,
                                   &self->reader_options,
                                   STATS_LEVEL1,
                                   SCS_FILE,
                                   self->super.super.id,
                                   self->filename->str);
            log_reader_set_immediate_check(self->reader);

            log_pipe_append((LogPipe *) self->reader, s);
            if (!log_pipe_init((LogPipe *) self->reader))
              {
                msg_error("Error initializing log_reader, closing fd",
                          evt_tag_int("fd", fd),
                          NULL);
                log_pipe_unref((LogPipe *) self->reader);
                self->reader = NULL;
                close(fd);
              }
            affile_sd_recover_state(s, cfg, proto);
          }
        break;
      }
    default:
      break;
    }
}
コード例 #2
0
ファイル: afprog.c プロジェクト: pzoleex/syslog-ng
static gboolean
afprogram_sd_init(LogPipe *s)
{
    AFProgramSourceDriver *self = (AFProgramSourceDriver *) s;
    GlobalConfig *cfg = log_pipe_get_config(s);
    gint fd;

    if (!log_src_driver_init_method(s))
        return FALSE;

    if (cfg)
        log_reader_options_init(&self->reader_options, cfg, self->super.super.group);

    msg_verbose("Starting source program",
                evt_tag_str("cmdline", self->process_info.cmdline->str));

    if (!afprogram_popen(&self->process_info, G_IO_IN, &fd))
        return FALSE;

    /* parent */
    child_manager_register(self->process_info.pid, afprogram_sd_exit, log_pipe_ref(&self->super.super.super),
                           (GDestroyNotify) log_pipe_unref);

    g_fd_set_nonblock(fd, TRUE);
    g_fd_set_cloexec(fd, TRUE);
    if (!self->reader)
    {
        LogTransport *transport;

        transport = log_transport_pipe_new(fd);
        self->reader = log_reader_new(s->cfg);
        log_reader_reopen(self->reader, log_proto_text_server_new(transport, &self->reader_options.proto_options.super),
                          poll_fd_events_new(fd));
        log_reader_set_options(self->reader,
                               s,
                               &self->reader_options,
                               STATS_LEVEL0,
                               SCS_PROGRAM,
                               self->super.super.id,
                               self->process_info.cmdline->str);
    }
    log_pipe_append((LogPipe *) self->reader, &self->super.super.super);
    if (!log_pipe_init((LogPipe *) self->reader))
    {
        msg_error("Error initializing program source, closing fd",
                  evt_tag_int("fd", fd));
        log_pipe_unref((LogPipe *) self->reader);
        self->reader = NULL;
        close(fd);
        return FALSE;
    }
    return TRUE;
}
コード例 #3
0
ファイル: afsocket-source.c プロジェクト: jbfuzier/syslog-ng
static gboolean
afsocket_sc_init(LogPipe *s)
{
  AFSocketSourceConnection *self = (AFSocketSourceConnection *) s;
  LogTransport *transport;
  LogProtoServer *proto;

  if (!self->reader)
    {
      transport = afsocket_sc_construct_transport(self, self->sock);
      /* transport_mapper_inet_construct_log_transport() can return NULL on TLS errors */
      if (!transport)
        return FALSE;

      proto = log_proto_server_factory_construct(self->owner->proto_factory, transport, &self->owner->reader_options.proto_options.super);
      self->reader = log_reader_new(s->cfg);
      log_reader_reopen(self->reader, proto, poll_fd_events_new(self->sock));
      log_reader_set_peer_addr(self->reader, self->peer_addr);
    }
  log_reader_set_options(self->reader, s,
                         &self->owner->reader_options,
                         STATS_LEVEL1,
                         self->owner->transport_mapper->stats_source,
                         self->owner->super.super.id,
                         afsocket_sc_stats_instance(self));
  log_pipe_append((LogPipe *) self->reader, s);
  if (log_pipe_init((LogPipe *) self->reader))
    {
      return TRUE;
    }
  else
    {
      log_pipe_unref((LogPipe *) self->reader);
      self->reader = NULL;
    }
  return FALSE;
}
コード例 #4
0
ファイル: afstreams.c プロジェクト: create-iv/syslog-ng
static gboolean
afstreams_sd_init(LogPipe *s)
{
  AFStreamsSourceDriver *self = (AFStreamsSourceDriver *) s;
  GlobalConfig *cfg = log_pipe_get_config(s);
  gint fd;

  if (!log_src_driver_init_method(s))
    return FALSE;

  log_reader_options_init(&self->reader_options, cfg, self->super.super.group);

  fd = open(self->dev_filename->str, O_RDONLY | O_NOCTTY | O_NONBLOCK);
  if (fd != -1)
    {
      struct strioctl ioc;

      g_fd_set_cloexec(fd, TRUE);
      memset(&ioc, 0, sizeof(ioc));
      ioc.ic_cmd = I_CONSLOG;
      if (ioctl(fd, I_STR, &ioc) < 0)
        {
          msg_error("Error in ioctl(I_STR, I_CONSLOG)",
                    evt_tag_str(EVT_TAG_FILENAME, self->dev_filename->str),
                    evt_tag_errno(EVT_TAG_OSERROR, errno));
          close(fd);
          return FALSE;
        }
      g_fd_set_nonblock(fd, TRUE);
      self->reader = log_reader_new(cfg);
      log_reader_reopen(self->reader, log_proto_dgram_server_new(log_transport_streams_new(fd), &self->reader_options.proto_options.super), poll_fd_events_new(fd));
      log_reader_set_options(self->reader,
                             s,
                             &self->reader_options,
                             STATS_LEVEL1,
                             SCS_SUN_STREAMS,
                             self->super.super.id,
                             self->dev_filename->str);
      log_pipe_append((LogPipe *) self->reader, s);

      if (self->door_filename)
        {

          /* door creation is deferred, because it creates threads which is
           * not inherited through forks, and syslog-ng forks during
           * startup, but _after_ the configuration was initialized */

          register_application_hook(AH_POST_DAEMONIZED, afstreams_init_door, self);
        }
      if (!log_pipe_init((LogPipe *) self->reader))
        {
          msg_error("Error initializing log_reader, closing fd",
                    evt_tag_int("fd", fd));
          log_pipe_unref((LogPipe *) self->reader);
          self->reader = NULL;
          close(fd);
          return FALSE;
        }

    }
  else
    {
      msg_error("Error opening syslog device",
                evt_tag_str(EVT_TAG_FILENAME, self->dev_filename->str),
                evt_tag_errno(EVT_TAG_OSERROR, errno));
      return FALSE;
    }
  return TRUE;
}
コード例 #5
0
ファイル: affile-source.c プロジェクト: Achint08/syslog-ng
static gboolean
affile_sd_init(LogPipe *s)
{
  AFFileSourceDriver *self = (AFFileSourceDriver *) s;
  GlobalConfig *cfg = log_pipe_get_config(s);
  gint fd;
  gboolean file_opened, open_deferred = FALSE;

  if (!log_src_driver_init_method(s))
    return FALSE;

  log_reader_options_init(&self->reader_options, cfg, self->super.super.group);

  if ((self->multi_line_mode != MLM_PREFIX_GARBAGE && self->multi_line_mode != MLM_PREFIX_SUFFIX ) && (self->multi_line_prefix || self->multi_line_garbage))
    {
      msg_error("multi-line-prefix() and/or multi-line-garbage() specified but multi-line-mode() is not regexp based (prefix-garbage or prefix-suffix), please set multi-line-mode() properly", NULL);
      return FALSE;
    }

  file_opened = affile_sd_open_file(self, self->filename->str, &fd);
  if (!file_opened && self->follow_freq > 0)
    {
      msg_info("Follow-mode file source not found, deferring open",
               evt_tag_str("filename", self->filename->str),
               NULL);
      open_deferred = TRUE;
      fd = -1;
    }

  if (file_opened || open_deferred)
    {
      LogProtoServer *proto;
      PollEvents *poll_events;

      poll_events = affile_sd_construct_poll_events(self, fd);
      if (!poll_events)
        {
          close(fd);
          return FALSE;
        }

      proto = affile_sd_construct_proto(self, fd);
      self->reader = log_reader_new(self->super.super.super.cfg);
      log_reader_reopen(self->reader, proto, poll_events);

      log_reader_set_options(self->reader,
                             s,
                             &self->reader_options,
                             STATS_LEVEL1,
                             SCS_FILE,
                             self->super.super.id,
                             self->filename->str);
      /* NOTE: if the file could not be opened, we ignore the last
       * remembered file position, if the file is created in the future
       * we're going to read from the start. */
      
      log_pipe_append((LogPipe *) self->reader, s);
      if (!log_pipe_init((LogPipe *) self->reader))
        {
          msg_error("Error initializing log_reader, closing fd",
                    evt_tag_int("fd", fd),
                    NULL);
          log_pipe_unref((LogPipe *) self->reader);
          self->reader = NULL;
          close(fd);
          return FALSE;
        }
      affile_sd_recover_state(s, cfg, proto);
    }
  else
    {
      msg_error("Error opening file for reading",
                evt_tag_str("filename", self->filename->str),
                evt_tag_errno(EVT_TAG_OSERROR, errno),
                NULL);
      return self->super.super.optional;
    }
  return TRUE;

}
コード例 #6
0
ファイル: logreader.c プロジェクト: jszigetvari/syslog-ng
void
log_reader_close_proto(LogReader *self)
{
  log_reader_reopen(self, NULL, NULL);
}