Пример #1
0
static int proc_lookupbase(struct inode * dir,const char * name, int len,
                           struct inode ** result)
{
    unsigned int pid, ino;
    int i;

    *result = NULL;
    if (!dir)
        return -ENOENT;
    if (!S_ISDIR(dir->i_mode)) {
        iput(dir);
        return -ENOENT;
    }
    ino = dir->i_ino;
    pid = ino >> 16;
    i = NR_BASE_DIRENTRY;
    while (i-- > 0 && !proc_match(len,name,base_dir+i))
        /* nothing */;
    if (i < 0) {
        iput(dir);
        return -ENOENT;
    }
    if (base_dir[i].low_ino == 1)
        ino = 1;
    else
        ino = (pid << 16) + base_dir[i].low_ino;
    for (i = 0 ; i < NR_TASKS ; i++)
        if (task[i] && task[i]->pid == pid)
            break;
    if (!pid || i >= NR_TASKS) {
        iput(dir);
        return -ENOENT;
    }
    if (!(*result = iget(dir->i_sb,ino))) {
        iput(dir);
        return -ENOENT;
    }
    iput(dir);
    return 0;
}
Пример #2
0
int
g_print_stats (char *file, uint32_t flags, size_t block_sz)
{
  g_setjmp (0, "g_print_stats", NULL, NULL);

  if (block_sz)
    {
      g_act_1.block_sz = block_sz;
    }

  if (g_fopen (file, "r", F_DL_FOPEN_BUFFER | flags, &g_act_1))
    {
      return 2;
    }

  if (gfl & F_OPT_LOADQ)
    {
      goto rc_end;
    }

  void *buffer = calloc (1, g_act_1.block_sz);

  pt_g_bmatch proc_match = g_bmatch;

  int r = 0;

  if (gfl & F_OPT_SORT)
    {
      if (gfl & F_OPT_NOBUFFER)
	{
	  print_str ("ERROR: %s: unable to sort with buffering disabled\n",
		     g_act_1.file);
	  goto r_end;
	}

      void *s_exec = (void*) g_act_1.exec_args.exc;

      if (l_sfo == L_STFO_SORT)
	{
	  if (g_print_do_filter (&g_act_1, s_exec))
	    {
	      goto r_end;
	    }
	}

      if (gfl & F_OPT_KILL_GLOBAL)
	{
	  goto r_end;
	}

      if (do_sort (&g_act_1, g_sort_field, g_sort_flags))
	{
	  goto r_end;
	}

      if (l_sfo == L_STFO_FILTER)
	{
	  if (g_print_do_filter (&g_act_1, s_exec))
	    {
	      goto r_end;
	    }
	}

      if (gfl & F_OPT_KILL_GLOBAL)
	{
	  goto r_end;
	}

      g_act_1.max_hits = 0;
      g_act_1.max_results = 0;

      if (g_act_1.j_offset == 2)
	{
	  g_act_1.buffer.r_pos = md_last (&g_act_1.buffer);
	}
      else
	{
	  g_act_1.buffer.r_pos = md_first (&g_act_1.buffer);
	}

      //proc_match = g_bmatch_dummy;

      md_g_free_cb (&g_act_1._match_rr, g_cl_mrr);
    }

  __d_is_wb w_d_s = g_act_1.w_d;

  g_act_1.w_d = g_act_1.w_d_pr;

  g_do_ppprint (&g_act_1, F_GH_PRE_PRINT, &g_act_1.pre_print_mech,
		g_act_1.g_proc4_pr);

  if (gfl0 & F_OPT_LOADQA)
    {
      goto r_end;
    }

  g_act_1.w_d = w_d_s;

  void *ptr;

  size_t c = 0;

  g_setjmp (F_SIGERR_CONTINUE, "g_print_stats(loop)", NULL, NULL);

  g_act_1.buffer.offset = 0;

  if (!sigsetjmp(g_sigjmp.env, 1))
    {
      while ((ptr = g_read (buffer, &g_act_1, g_act_1.block_sz)))
	{
	  if ((gfl & F_OPT_KILL_GLOBAL))
	    {
	      break;
	    }

	  if ((r = proc_match (ptr, &g_act_1, &g_act_1.buffer)))
	    {
	      if (r == -1)
		{
		  print_str ("ERROR: %s: [%d] matching record failed\n",
			     g_act_1.file, r);
		  break;
		}

	      continue;
	    }

	  c++;
	  g_act_1.g_proc4 ((void*) &g_act_1, ptr, NULL);

	}

    }
  else
    {
      print_str (
	  "ERROR: %s: an exception has occured, terminating enumeration and attempt cleanup..\n",
	  g_act_1.file);
      EXITVAL = 2;
      goto r_end;
    }

  g_act_1.w_d = g_act_1.w_d_po;

  g_do_ppprint (&g_act_1, F_GH_POST_PRINT, &g_act_1.post_print_mech,
		g_act_1.g_proc4_po);

  if (gfl & F_OPT_MODE_RAWDUMP)
    {
#ifdef HAVE_ZLIB_H
      if ((g_act_1.flags & F_GH_IO_GZIP) && g_act_1.gz_fh1)
	{
	  gzflush(g_act_1.gz_fh1, Z_FINISH);
	}
#endif
      fflush (stdout);
    }

  // g_setjmp(0, "dirlog_print_stats(2)", NULL, NULL);

  if (!(g_act_1.flags & F_GH_ISONLINE) && (gfl0 & F_OPT_STATS))
    {
      fprintf (
	  stderr,
	  "STATS: %s: processed %llu/%llu records\n",
	  file,
	  (unsigned long long int) c,
	  !g_act_1.buffer.count ?
	      (unsigned long long int) c : g_act_1.buffer.count);
    }

  if (0 == c && 0 == EXITVAL)
    {
      EXITVAL = 2;
    }

  r_end:

  free (buffer);

  rc_end:

  g_close (&g_act_1);

  return EXITVAL;
}