Пример #1
0
struct lex_file* lf_stream_create(FILE* file)
{
	if(file==NULL)
	{
		return NULL;
	}
	struct lex_file* lf=(struct lex_file*)malloc(sizeof(*lf));
	lf_init(lf,file);
	return lf;
};
Пример #2
0
struct lex_file* lf_create(char* file_name)
{
	FILE* file=fopen(file_name,"r");
	if(file==NULL)
	{
		return NULL;
	}
	struct lex_file* lf=(struct lex_file*)malloc(sizeof(*lf));
	lf_init(lf,file);
	return lf;
}
Пример #3
0
void pkt_manager_init(void) {
  rmt_transmit_cb = cb_init(TRANSMIT_CB_SIZE, CB_WRITE_BLOCK, CB_READ_BLOCK);

  packet_id = 0;

  lf_init();

  ingress_pipeline_init();

  queuing_init();

  mirroring_init();

  egress_pipeline_init();

  pthread_create(&pkt_out_thread, NULL,
		 pkt_out_loop, NULL); 
}
Пример #4
0
static int realmode(unsigned nthreads)
{
int	listensock;
struct	cthreadinfo *threads;
struct	dupinfo di;

	listensock=lf_init("filters/dupfilter-mode",
		ALLFILTERSOCKETDIR "/dupfilter",
		ALLFILTERSOCKETDIR "/.dupfilter",
		FILTERSOCKETDIR "/dupfilter",
		FILTERSOCKETDIR "/.dupfilter");

	if (listensock < 0)
		return (1);

	threads=cthread_init(nthreads, sizeof(struct dupinfo),
		(void (*)(void *))&hashclient_wrapper,
		(void (*)(void *))&checkclient);
	if (!threads)
	{
		perror("cthread_init");
		return (1);
	}

	lf_init_completed(listensock);

	for (;;)
	{
		if ((di.fd=lf_accept(listensock)) < 0)	break;

		di.cancelfunc= &realcancel;

		if ( cthread_go(threads,
			(void (*)(void *, void *))&initdupinfo, &di))
		{
			perror("cthread_go");
			break;
		}
	}
	cthread_wait(threads);
	return (0);
}
Пример #5
0
int main(int argc, char **argv, char **env)
{
char	*fn, *f;
int	rc;
char	buffer[1];
int	waitstat;
struct	stat	stat_buf;

	fn=config_localfilename("filters/perlfilter-numprocs");
	if ( (f=config_read1l(fn)) != 0)
	{
		sscanf(f, "%u", &nchildren);
		free(f);
	}
	free(fn);
	if (nchildren <= 0)	nchildren=1;

	fn=config_localfilename("filters/perlfilter");
	if ( (f=config_read1l(fn)) == 0)
	{
		fprintf(stderr, "filters/perlfilter: not defined.\n");
		exit(1);
	}

	filter=f;

	if (stat(filter, &stat_buf))
	{
		perror(filter);
		exit(1);
	}

	listen_sock=lf_init("filters/perlfilter-mode",
		ALLFILTERSOCKETDIR "/perlfilter",
		ALLFILTERSOCKETDIR "/.perlfilter",
		FILTERSOCKETDIR "/perlfilter",
		FILTERSOCKETDIR "/.perlfilter");

	if (listen_sock < 0)
	{
		perror("socket");
		exit(1);
	}

	rc=wait_startchildren(nchildren, &children);

	if (rc < 0)
	{
		perror("fork");
		exit(1);
	}

	if (rc > 0)
	{
		lf_init_completed(listen_sock);
		perlfilter();
	}

	signal(SIGCHLD, reap_children);
	lf_init_completed(listen_sock);

	while (read(0, &buffer, 1) != 0)
	{
		;
	}
	wait_restore();

	/* Wait for all child processes to terminate */

	while (wait(&waitstat) > 0)
		;
	exit(0);
	return (0);
}
Пример #6
0
int
main (int argc, char *argv[])
{
  int opt;
  char const *prog;

  exit_failure = EXIT_TROUBLE;
  initialize_main (&argc, &argv);
  program_name = argv[0];
  setlocale (LC_ALL, "");
  bindtextdomain (PACKAGE, LOCALEDIR);
  textdomain (PACKAGE);
  c_stack_action (cleanup);

  prog = getenv ("EDITOR");
  if (prog)
    editor_program = prog;

  diffarg (DEFAULT_DIFF_PROGRAM);

  /* parse command line args */
  while ((opt = getopt_long (argc, argv, "abBdEHiI:lo:stvw:W", longopts, 0))
	 != -1)
    {
      switch (opt)
	{
	case 'a':
	  diffarg ("-a");
	  break;

	case 'b':
	  diffarg ("-b");
	  break;

	case 'B':
	  diffarg ("-B");
	  break;

	case 'd':
	  diffarg ("-d");
	  break;

	case 'E':
	  diffarg ("-E");
	  break;

	case 'H':
	  diffarg ("-H");
	  break;

	case 'i':
	  diffarg ("-i");
	  break;

	case 'I':
	  diffarg ("-I");
	  diffarg (optarg);
	  break;

	case 'l':
	  diffarg ("--left-column");
	  break;

	case 'o':
	  output = optarg;
	  break;

	case 's':
	  suppress_common_lines = true;
	  break;

	case 't':
	  diffarg ("-t");
	  break;

	case 'v':
	  version_etc (stdout, "sdiff", PACKAGE_NAME, PACKAGE_VERSION,
		       "Thomas Lord", (char *) 0);
	  check_stdout ();
	  return EXIT_SUCCESS;

	case 'w':
	  diffarg ("-W");
	  diffarg (optarg);
	  break;

	case 'W':
	  diffarg ("-w");
	  break;

	case DIFF_PROGRAM_OPTION:
	  diffargv[0] = optarg;
	  break;

	case HELP_OPTION:
	  usage ();
	  check_stdout ();
	  return EXIT_SUCCESS;

	case STRIP_TRAILING_CR_OPTION:
	  diffarg ("--strip-trailing-cr");
	  break;

	case TABSIZE_OPTION:
	  diffarg ("--tabsize");
	  diffarg (optarg);
	  break;

	default:
	  try_help (0, 0);
	}
    }

  if (argc - optind != 2)
    {
      if (argc - optind < 2)
	try_help ("missing operand after `%s'", argv[argc - 1]);
      else
	try_help ("extra operand `%s'", argv[optind + 2]);
    }

  if (! output)
    {
      /* easy case: diff does everything for us */
      if (suppress_common_lines)
	diffarg ("--suppress-common-lines");
      diffarg ("-y");
      diffarg ("--");
      diffarg (argv[optind]);
      diffarg (argv[optind + 1]);
      diffarg (0);
      execvp (diffargv[0], (char **) diffargv);
      perror_fatal (diffargv[0]);
    }
  else
    {
      char const *lname, *rname;
      FILE *left, *right, *out, *diffout;
      bool interact_ok;
      struct line_filter lfilt;
      struct line_filter rfilt;
      struct line_filter diff_filt;
      bool leftdir = diraccess (argv[optind]);
      bool rightdir = diraccess (argv[optind + 1]);

      if (leftdir & rightdir)
	fatal ("both files to be compared are directories");

      lname = expand_name (argv[optind], leftdir, argv[optind + 1]);
      left = ck_fopen (lname, "r");
      rname = expand_name (argv[optind + 1], rightdir, argv[optind]);
      right = ck_fopen (rname, "r");
      out = ck_fopen (output, "w");

      diffarg ("--sdiff-merge-assist");
      diffarg ("--");
      diffarg (argv[optind]);
      diffarg (argv[optind + 1]);
      diffarg (0);

      trapsigs ();

#if ! (HAVE_WORKING_FORK || HAVE_WORKING_VFORK)
      {
	size_t cmdsize = 1;
	char *p, *command;
	int i;

	for (i = 0;  diffargv[i];  i++)
	  cmdsize += quote_system_arg (0, diffargv[i]) + 1;
	command = p = xmalloc (cmdsize);
	for (i = 0;  diffargv[i];  i++)
	  {
	    p += quote_system_arg (p, diffargv[i]);
	    *p++ = ' ';
	  }
	p[-1] = 0;
	errno = 0;
	diffout = popen (command, "r");
	if (! diffout)
	  perror_fatal (command);
	free (command);
      }
#else
      {
	int diff_fds[2];
# if HAVE_WORKING_VFORK
	sigset_t procmask;
	sigset_t blocked;
# endif

	if (pipe (diff_fds) != 0)
	  perror_fatal ("pipe");

# if HAVE_WORKING_VFORK
	/* Block SIGINT and SIGPIPE.  */
	sigemptyset (&blocked);
	sigaddset (&blocked, SIGINT);
	sigaddset (&blocked, SIGPIPE);
	sigprocmask (SIG_BLOCK, &blocked, &procmask);
# endif
	diffpid = vfork ();
	if (diffpid < 0)
	  perror_fatal ("fork");
	if (! diffpid)
	  {
	    /* Alter the child's SIGINT and SIGPIPE handlers;
	       this may munge the parent.
	       The child ignores SIGINT in case the user interrupts the editor.
	       The child does not ignore SIGPIPE, even if the parent does.  */
	    if (initial_handler (handler_index_of_SIGINT) != SIG_IGN)
	      signal_handler (SIGINT, SIG_IGN);
	    signal_handler (SIGPIPE, SIG_DFL);
# if HAVE_WORKING_VFORK
	    /* Stop blocking SIGINT and SIGPIPE in the child.  */
	    sigprocmask (SIG_SETMASK, &procmask, 0);
# endif
	    close (diff_fds[0]);
	    if (diff_fds[1] != STDOUT_FILENO)
	      {
		dup2 (diff_fds[1], STDOUT_FILENO);
		close (diff_fds[1]);
	      }

	    execvp (diffargv[0], (char **) diffargv);
	    _exit (errno == ENOENT ? 127 : 126);
	  }

# if HAVE_WORKING_VFORK
	/* Restore the parent's SIGINT and SIGPIPE behavior.  */
	if (initial_handler (handler_index_of_SIGINT) != SIG_IGN)
	  signal_handler (SIGINT, catchsig);
	if (initial_handler (handler_index_of_SIGPIPE) != SIG_IGN)
	  signal_handler (SIGPIPE, catchsig);
	else
	  signal_handler (SIGPIPE, SIG_IGN);

	/* Stop blocking SIGINT and SIGPIPE in the parent.  */
	sigprocmask (SIG_SETMASK, &procmask, 0);
# endif

	close (diff_fds[1]);
	diffout = fdopen (diff_fds[0], "r");
	if (! diffout)
	  perror_fatal ("fdopen");
      }
#endif

      lf_init (&diff_filt, diffout);
      lf_init (&lfilt, left);
      lf_init (&rfilt, right);

      interact_ok = interact (&diff_filt, &lfilt, lname, &rfilt, rname, out);

      ck_fclose (left);
      ck_fclose (right);
      ck_fclose (out);

      {
	int wstatus;
	int werrno = 0;

#if ! (HAVE_WORKING_FORK || HAVE_WORKING_VFORK)
	wstatus = pclose (diffout);
	if (wstatus == -1)
	  werrno = errno;
#else
	ck_fclose (diffout);
	while (waitpid (diffpid, &wstatus, 0) < 0)
	  if (errno == EINTR)
	    checksigs ();
	  else
	    perror_fatal ("waitpid");
	diffpid = 0;
#endif

	if (tmpname)
	  {
	    unlink (tmpname);
	    tmpname = 0;
	  }

	if (! interact_ok)
	  exiterr ();

	check_child_status (werrno, wstatus, EXIT_FAILURE, diffargv[0]);
	untrapsig (0);
	checksigs ();
	exit (WEXITSTATUS (wstatus));
      }
    }
  return EXIT_SUCCESS;			/* Fool `-Wall'.  */
}