Exemplo n.º 1
0
static int undiverted(const char *path)
{
	const char * const cmd[] =
		{"dpkg-divert", "--listpackage", path, NULL};
	pid_t child;
	char packagename[sizeof("bash\n")];
	size_t len;
	FILE *in = spawn_pipe(&child, cmd, -1);
	int diverted = 1;

	/* Is $path diverted by someone other than bash? */

	len = fread(packagename, 1, sizeof(packagename), in);
	if (ferror(in))
		die_errno("cannot read from dpkg-divert");
	if (len == 0)
		diverted = 0;	/* No diversion. */
	if (len == strlen("bash\n") && !memcmp(packagename, "bash\n", len))
		diverted = 0;	/* Diverted by bash. */

	if (fclose(in))
		die_errno("cannot close read end of pipe");
	wait_or_die(child, "dpkg-divert", ERROR_OK | SIGPIPE_OK);
	return !diverted;
}
Exemplo n.º 2
0
static int binsh_in_filelist(const char *package)
{
	const char * const cmd[] = {"dpkg-query", "-L", package, NULL};
	pid_t child;
	int sink;
	FILE *in;
	int found;

	/*
	 * dpkg -L $package 2>/dev/null | ...
	 *
	 * Redirection of stderr is for quieter output
	 * when $package is not installed.  If opening /dev/null
	 * fails, no problem; leave stderr alone in that case.
	 */
	sink = open("/dev/null", O_WRONLY);
	if (sink >= 0)
		set_cloexec(sink);
	in = spawn_pipe(&child, cmd, sink);

	/* ... | grep "^/bin/sh\$" */
	found = has_binsh_line(in);
	if (fclose(in))
		die_errno("cannot close read end of pipe");

	/*
	 * dpkg -L will error out if $package is not already installed.
	 *
	 * We stopped reading early if we found a match, so
	 * tolerate SIGPIPE in that case.
	 */
	wait_or_die(child, "dpkg-query -L", ERROR_OK |
						(found ? SIGPIPE_OK : 0));
	return found;
}
int main (int argc, char *argv[])
{

  SUCCESS_OR_DIE (gaspi_proc_init (GASPI_BLOCK));

  gaspi_rank_t iProc, nProc;
  SUCCESS_OR_DIE (gaspi_proc_rank (&iProc));
  SUCCESS_OR_DIE (gaspi_proc_num (&nProc));

  // number of threads
  const int NTHREADS = 2;

  // number of buffers
  const int NWAY     = 2;

  gaspi_segment_id_t const segment_id = 0;

  // allocate segment for array for local vector, left halo and right halo
  SUCCESS_OR_DIE ( gaspi_segment_create
      ( segment_id, NWAY * (NTHREADS + 2) * 2 * VLEN * sizeof (double)
      , GASPI_GROUP_ALL, GASPI_BLOCK, GASPI_MEM_UNINITIALIZED));
  gaspi_pointer_t array;
  SUCCESS_OR_DIE ( gaspi_segment_ptr ( segment_id, &array) );

  // initial buffer id
  int buffer_id = 0;

  // set notification values
  gaspi_notification_id_t left_data_available[NWAY];
  gaspi_notification_id_t right_data_available[NWAY];
  for (gaspi_notification_id_t id = 0; id < NWAY; ++id)
  {
    left_data_available[id] = id;
    right_data_available[id] = NWAY + id;
  }

  // set queue id
  gaspi_queue_id_t queue_id = 0;

  // initialize data
  data_init (NTHREADS, iProc, buffer_id, array);

  omp_set_num_threads (NTHREADS);

  double time = -now();

#pragma omp parallel default (shared) firstprivate (buffer_id)
  {

    const int tid = omp_get_thread_num();

    for (int k = 0; k < NITER; ++k)
    {
      for ( int i = 0; i < nProc * NTHREADS; ++i )
      {

	const int left_halo   = 0;
	const int slice_id    = tid + 1;
	const int right_halo  = NTHREADS+1;
	
        if (tid == 0)
        {
	  // issue write
          wait_for_queue_max_half (&queue_id);
          SUCCESS_OR_DIE ( gaspi_write_notify
              ( segment_id, array_OFFSET_left (buffer_id, left_halo + 1, 0), LEFT(iProc, nProc) 
              , segment_id, array_OFFSET_left (buffer_id, right_halo, 0), VLEN * sizeof (double)
              , right_data_available[buffer_id], 1 + i, queue_id, GASPI_BLOCK));

	  // issue write
          wait_for_queue_max_half (&queue_id);
          SUCCESS_OR_DIE ( gaspi_write_notify
              ( segment_id, array_OFFSET_right (buffer_id, right_halo - 1, 0), RIGHT(iProc, nProc)
              , segment_id, array_OFFSET_right (buffer_id, left_halo, 0), VLEN * sizeof (double)
              , left_data_available[buffer_id], 1 + i, queue_id, GASPI_BLOCK));


	  // wait for data notification
          wait_or_die (segment_id, right_data_available[buffer_id], 1 + i);

	  // wait for data notification
          wait_or_die (segment_id, left_data_available[buffer_id], 1 + i);


        }
#pragma omp barrier

	// compute data, read from id "buffer_id", write to id "1 - buffer_id"
	data_compute ( NTHREADS, array, 1 - buffer_id, buffer_id, slice_id);

#pragma omp barrier

	// alternate the buffer
	buffer_id = 1 - buffer_id;

      }
    }
  }

  time += now();

  data_verify (NTHREADS, iProc, (NITER * nProc * NTHREADS) % NWAY, array);

  printf ("# gaspi %s nProc %d vlen %i niter %d nthreads %i nway %i time %g\n"
         , argv[0], nProc, VLEN, NITER, NTHREADS, NWAY, time
         );

  gaspi_proc_term (GASPI_BLOCK);

  return EXIT_SUCCESS;
}