Exemple #1
0
Test(test_pathutils, test_is_regular)
{
  int fd = open("test2.file", O_CREAT | O_RDWR, 0644);
  int error = close(fd);
  cr_assert_not(error, "close error");

  cr_assert(is_file_regular("test2.file"), "this is a regular file");
  cr_assert_not(is_file_regular("./"), "this is not a regular file");

  error = unlink("test2.file");
  cr_assert_not(error, "unlink error");
}
Exemple #2
0
static gboolean
pdbtool_merge_dir(const gchar *dir, gboolean recursive, GString *merged)
{
  GDir *pdb_dir;
  gboolean ok = TRUE;
  GError *error = NULL;
  const gchar *filename;

  if ((pdb_dir = g_dir_open(dir, 0, &error)) == NULL)
    {
      fprintf(stderr, "Error opening directory %s, error='%s'\n", merge_dir, error ? error->message : "Unknown error");
      g_clear_error(&error);
      return FALSE;
    }

  while ((filename = g_dir_read_name(pdb_dir)) != NULL && ok)
    {
      gchar *full_name = g_build_filename(dir, filename, NULL);

      if (recursive && is_file_directory(full_name))
        {
          ok = pdbtool_merge_dir(full_name, recursive, merged);
        }
      else if (is_file_regular(full_name) && (!merge_glob || g_pattern_match_simple(merge_glob, filename)))
        {
          ok = pdbtool_merge_file(full_name, merged);
        }
      g_free(full_name);
    }
  g_dir_close(pdb_dir);
  return TRUE;
}
Exemple #3
0
static void
log_writer_start_watches(LogWriter *self)
{
  gint fd;
  GIOCondition cond;

  if (!self->watches_running)
    {
      log_proto_prepare(self->proto, &fd, &cond);

      if (self->pollable_state < 0)
        {
          if (is_file_regular(fd))
            self->pollable_state = 0;
          else
            self->pollable_state = iv_fd_pollable(fd);
        }

      if (self->pollable_state)
        {
          self->fd_watch.fd = fd;
          iv_fd_register(&self->fd_watch);
        }

      log_writer_update_watches(self);
      self->watches_running = TRUE;
    }
}
Exemple #4
0
static void
log_writer_start_watches(LogWriter *self)
{
  gint fd;
  GIOCondition cond;

  if (self->watches_running)
    return;

  log_proto_client_prepare(self->proto, &fd, &cond);

  self->fd_watch.fd = fd;

  if (self->pollable_state < 0)
    {
      if (is_file_regular(fd))
        self->pollable_state = 0;
      else
        self->pollable_state = !iv_fd_register_try(&self->fd_watch);
    }
  else if (self->pollable_state > 0)
    iv_fd_register(&self->fd_watch);

  log_writer_update_watches(self);
  self->watches_running = TRUE;
}
Exemple #5
0
static gboolean
_pdb_file_validate(const gchar *filename, GError **error, PdbGetXsdDirFunc get_xsd_dir)
{
  gchar *xmllint_cmdline;
  gint version;
  gint exit_status;
  gchar *stderr_content = NULL;
  gchar *xsd_file;

  g_return_val_if_fail(error == NULL || *error == NULL, FALSE);

  version = pdb_file_detect_version(filename, error);
  if (!version)
    return FALSE;

  xsd_file = _get_xsd_file(version, get_xsd_dir);
  if (!is_file_regular(xsd_file))
    {
      g_set_error(error, PDB_ERROR, PDB_ERROR_FAILED, "XSD file is not available at %s", xsd_file);
      g_free(xsd_file);
      return FALSE;
    }

  xmllint_cmdline = g_strdup_printf("xmllint --noout --nonet --schema '%s' '%s'", xsd_file, filename);
  g_free(xsd_file);

  if (!g_spawn_command_line_sync(xmllint_cmdline, NULL, &stderr_content, &exit_status, error))
    {
      g_free(xmllint_cmdline);
      g_free(stderr_content);
      return FALSE;
    }

  if (exit_status != 0)
    {
      g_set_error(error, PDB_ERROR, PDB_ERROR_FAILED,
                  "Non-zero exit code from xmllint while validating PDB file, "
                  "schema version %d, rc=%d, error: %s, command line %s",
                  version,
                  WEXITSTATUS(exit_status), stderr_content,
                  xmllint_cmdline);
      g_free(stderr_content);
      g_free(xmllint_cmdline);
      return FALSE;
    }
  g_free(xmllint_cmdline);
  g_free(stderr_content);
  return TRUE;
}
Exemple #6
0
static GModule *
plugin_dlopen_module(const gchar *module_name, const gchar *module_path)
{
  gchar *plugin_module_name = NULL;
  gchar **module_path_dirs, *p, *dot;
  GModule *mod;
  gint i;

  module_path_dirs = g_strsplit(module_path ? : "", G_SEARCHPATH_SEPARATOR_S, 0);
  i = 0;
  while (module_path_dirs && module_path_dirs[i])
    {
      plugin_module_name = g_module_build_path(module_path_dirs[i], module_name);
      if (is_file_regular(plugin_module_name))
        break;

      /* also check if a libtool archive exists (for example in the build directory) */
#ifndef _AIX
      dot = strrchr(plugin_module_name, '.');
      if (dot)
        {
          *dot = 0;
          p = g_strdup_printf("%s.la", plugin_module_name);
          g_free(plugin_module_name);
          plugin_module_name = p;
        }
      if (is_file_regular(plugin_module_name))
        break;

      /* On AIX the modules in .a files */
#else
      dot = strrchr(plugin_module_name, '.');
      if (dot)
        {
          *dot = 0;
          p = g_strdup_printf("%s.a", plugin_module_name);
          g_free(plugin_module_name);
          plugin_module_name = p;
        }
      if (is_file_regular(plugin_module_name))
        break;
#endif

      g_free(plugin_module_name);
      plugin_module_name = NULL;
      i++;
    }
  g_strfreev(module_path_dirs);
  if (!plugin_module_name)
    {
      msg_error("Plugin module not found in 'module-path'",
                evt_tag_str("module-path", module_path),
                evt_tag_str("module", module_name));
      return NULL;
    }
  msg_trace("Trying to open module",
            evt_tag_str("module", module_name),
            evt_tag_str("filename", plugin_module_name));

  mod = g_module_open(plugin_module_name, G_MODULE_BIND_LAZY);
  g_free(plugin_module_name);
  if (!mod)
    {
      msg_error("Error opening plugin module",
                evt_tag_str("module", module_name),
                evt_tag_str("error", g_module_error()));
      return NULL;
    }
  return mod;
}