Exemple #1
0
void ship_name(struct mtwist_state *mt, char *buffer, int buflen)
{
	switch (mtwist_int(mt, 6)) {
	case 0:
		snprintf(buffer, buflen, "%s %s",
			random_word(mt, SpaceWorthy, ARRAYSIZE(SpaceWorthy)),
			random_word(mt, Animal, ARRAYSIZE(Animal)));
		break;
	case 1:
		snprintf(buffer, buflen, "%s %s",
			random_word(mt, Animal, ARRAYSIZE(Animal)),
			random_word(mt, SpaceWorthy, ARRAYSIZE(SpaceWorthy)));
		break;
	case 2:
		snprintf(buffer, buflen, "%s %s",
			random_word(mt, ShipThing, ARRAYSIZE(ShipThing)),
			random_word(mt, SpaceWorthy, ARRAYSIZE(SpaceWorthy)));
		break;
	case 3:
		snprintf(buffer, buflen, "%s %s",
			random_name(mt),
			random_word(mt, SpaceWorthy, ARRAYSIZE(SpaceWorthy)));
		break;
	case 4:
		snprintf(buffer, buflen, "%s %s",
			random_word(mt, SpaceWorthy, ARRAYSIZE(SpaceWorthy)),
			random_name(mt));
		break;
	default:
		snprintf(buffer, buflen, "%s %s",
			random_word(mt, SpaceWorthy, ARRAYSIZE(SpaceWorthy)),
			random_word(mt, ShipThing, ARRAYSIZE(ShipThing)));
		break;
	}
}
Exemple #2
0
	Area::Area() : north(0), east(0), west(0), south(0)
	{
		random_name();
		character_vec = new vector<Character*>();
                item_vec = new vector<Item*>();
                cout << "Area created " << endl;
	}
Exemple #3
0
/* If the network is enabled, we want <sysroot>/etc/resolv.conf to
 * reflect the contents of /etc/resolv.conf so that name resolution
 * works.  It would be nice to bind-mount the file (single file bind
 * mounts are possible).  However annoyingly that doesn't work for
 * Ubuntu guests where the guest resolv.conf is a dangling symlink,
 * and for reasons unknown mount tries to follow the symlink and
 * fails (likely a bug).  So this is a hack.  Note we only invoke
 * this if the network is enabled.
 */
static int
set_up_etc_resolv_conf (struct resolver_state *rs)
{
  struct stat statbuf;
  CLEANUP_FREE char *buf = NULL;

  rs->sysroot_etc_resolv_conf_old = NULL;

  rs->sysroot_etc_resolv_conf = sysroot_path ("/etc/resolv.conf");

  if (!rs->sysroot_etc_resolv_conf) {
    reply_with_perror ("malloc");
    goto error;
  }

  /* If /etc/resolv.conf exists, rename it to the backup file.  Note
   * that on Ubuntu it's a dangling symlink.
   */
  if (lstat (rs->sysroot_etc_resolv_conf, &statbuf) == 0) {
    /* Make a random name for the backup file. */
    if (asprintf (&buf, "%s/etc/XXXXXXXX", sysroot) == -1) {
      reply_with_perror ("asprintf");
      goto error;
    }
    if (random_name (buf) == -1) {
      reply_with_perror ("random_name");
      goto error;
    }
    rs->sysroot_etc_resolv_conf_old = strdup (buf);
    if (!rs->sysroot_etc_resolv_conf_old) {
      reply_with_perror ("strdup");
      goto error;
    }

    if (verbose)
      fprintf (stderr, "renaming %s to %s\n", rs->sysroot_etc_resolv_conf,
               rs->sysroot_etc_resolv_conf_old);

    if (rename (rs->sysroot_etc_resolv_conf,
                rs->sysroot_etc_resolv_conf_old) == -1) {
      reply_with_perror ("rename: %s to %s", rs->sysroot_etc_resolv_conf,
                         rs->sysroot_etc_resolv_conf_old);
      goto error;
    }
  }

  /* Now that the guest's <sysroot>/etc/resolv.conf is out the way, we
   * can create our own copy of the appliance /etc/resolv.conf.
   */
  ignore_value (command (NULL, NULL, str_cp, "/etc/resolv.conf",
                         rs->sysroot_etc_resolv_conf, NULL));

  rs->mounted = true;
  return 0;

 error:
  free (rs->sysroot_etc_resolv_conf);
  free (rs->sysroot_etc_resolv_conf_old);
  return -1;
}
void test(int segment_count, int test_count)
{
  for (int i = 0; i < test_count; ++i)
  {
    MeshT mesh;
    SegmentationT segmentation(mesh);

    std::map<std::string, int> segment_names;
    while (static_cast<int>(segment_names.size()) != segment_count)
      segment_names[random_name()] = rand() % 90 + 10;

    for (std::map<std::string, int>::const_iterator sit = segment_names.begin(); sit != segment_names.end(); ++sit)
    {
      for (int j = 0; j < sit->second; ++j)
        viennagrid::make_vertex( segmentation(sit->first) );
    }


    for (std::map<std::string, int>::const_iterator sit = segment_names.begin(); sit != segment_names.end(); ++sit)
    {
      if (static_cast<int>(viennagrid::vertices( segmentation(sit->first) ).size()) != sit->second)
      {
        std::cerr << "Numbers of vertices in a named segment is equal to created vertices" << std::endl;
        std::cerr << "FAILED!" << std::endl;
        exit(EXIT_FAILURE);
      }
    }
  }
}
Exemple #5
0
/* Detect if chown(2) is supported on the target directory. */
static int
is_chown_supported (const char *dir)
{
  CLEANUP_FREE char *buf = NULL;
  int fd, r, err, saved_errno;

  /* Create a randomly named file. */
  if (asprintf (&buf, "%s%s/XXXXXXXX.XXX", sysroot, dir) == -1) {
    err = errno;
    r = cancel_receive ();
    errno = err;
    reply_with_perror ("asprintf");
    return -1;
  }
  if (random_name (buf) == -1) {
    err = errno;
    r = cancel_receive ();
    errno = err;
    reply_with_perror ("random_name");
    return -1;
  }

  /* Maybe 'dir' is not a directory or filesystem not writable? */
  fd = open (buf, O_WRONLY|O_CREAT|O_NOCTTY|O_CLOEXEC, 0666);
  if (fd == -1) {
    err = errno;
    r = cancel_receive ();
    errno = err;
    reply_with_perror ("%s", dir);
    return -1;
  }

  /* This is the test. */
  r = fchown (fd, 1000, 1000);
  saved_errno = errno;

  /* Make sure the test file is removed. */
  close (fd);
  unlink (buf);

  if (r == -1 && saved_errno == EPERM) {
    /* This means chown is not supported by the filesystem. */
    return 0;
  }

  if (r == -1) {
    /* Some other error? */
    err = errno;
    r = cancel_receive ();
    errno = err;
    reply_with_perror_errno (saved_errno, "unexpected error in fchown");
    return -1;
  }

  /* Else chown is supported. */
  return 1;
}
int ftrig1_make (ftrig1 *f, char const *path)
{
  ftrig1 ff = FTRIG1_ZERO ;
  unsigned int pathlen = str_len(path) ;
  int e = 0 ;
  char tmp[pathlen + 46 + FTRIG1_PREFIXLEN] ;
  
  byte_copy(tmp, pathlen, path) ;
  tmp[pathlen] = '/' ; tmp[pathlen+1] = '.' ;
  byte_copy(tmp + pathlen + 2, FTRIG1_PREFIXLEN, FTRIG1_PREFIX) ;
  tmp[pathlen + 2 + FTRIG1_PREFIXLEN] = ':' ;
  if (!timestamp(tmp + pathlen + 3 + FTRIG1_PREFIXLEN)) return 0 ;
  tmp[pathlen + 28 + FTRIG1_PREFIXLEN] = ':' ;
  if (random_name(tmp + pathlen + 29 + FTRIG1_PREFIXLEN, 16) < 16) return 0 ;
  tmp[pathlen + 45 + FTRIG1_PREFIXLEN] = 0 ;
  
  {
    mode_t m = umask(0) ;
    if (fifo_make(tmp, S_IRUSR|S_IWUSR|S_IWGRP|S_IWOTH) == -1)
    {
      umask(m) ;
      return 0 ;
    }
    umask(m) ;
  }

  if (!stralloc_catb(&ff.name, tmp, pathlen+1)) { e = errno ; goto err0 ; }
  if (!stralloc_catb(&ff.name, tmp + pathlen + 2, FTRIG1_PREFIXLEN + 44))
  {
    e = errno ; goto err1 ;
  }
  ff.fd = open_read(tmp) ;
  if (ff.fd == -1) { e = errno ; goto err1 ; }
  ff.fdw = open_write(tmp) ;
  if (ff.fdw == -1) { e = errno ; goto err2 ; }
  if (rename(tmp, ff.name.s) == -1) goto err3 ;
  *f = ff ;
  return 1 ;

 err3:
  e = errno ;
  fd_close(ff.fdw) ;
 err2:
  fd_close(ff.fd) ;
 err1:
  stralloc_free(&ff.name) ;
 err0:
  unlink(tmp) ;
  errno = e ;
  return 0 ;
}
Exemple #7
0
/* Detect if chown(2) is supported on the target directory. */
static int
is_chown_supported (const char *dir)
{
  size_t len = sysroot_len + strlen (dir) + 64;
  char buf[len];
  int fd, r, saved_errno;

  /* Create a randomly named file. */
  snprintf (buf, len, "%s%s/XXXXXXXX.XXX", sysroot, dir);
  if (random_name (buf) == -1) {
    reply_with_perror ("random_name");
    return -1;
  }

  /* Maybe 'dir' is not a directory or filesystem not writable? */
  fd = open (buf, O_WRONLY|O_CREAT|O_NOCTTY|O_CLOEXEC, 0666);
  if (fd == -1) {
    reply_with_perror ("%s", dir);
    return -1;
  }

  /* This is the test. */
  r = fchown (fd, 1000, 1000);
  saved_errno = errno;

  /* Make sure the test file is removed. */
  close (fd);
  unlink (buf);

  if (r == -1 && saved_errno == EPERM) {
    /* This means chown is not supported by the filesystem. */
    return 0;
  }

  if (r == -1) {
    /* Some other error? */
    reply_with_perror_errno (saved_errno, "unexpected error in fchown");
    return -1;
  }

  /* Else chown is supported. */
  return 1;
}
Exemple #8
0
//*****************************************************************************
//*****************************************************************************
int bevt_client_init(void) {
    random_name(&bevt_client_g.rid[0], 8);

    bevt_client_g.sfd = selfpipe_init() ;
    if (bevt_client_g.sfd < 0) strerr_diefu1sys(111, "selfpipe_init") ;
    {
        sigset_t set ;
        sigemptyset(&set) ;
        sigaddset(&set, SIGCHLD) ;
        if (selfpipe_trapset(&set) < 0)
            strerr_diefu1sys(111, "trap signals") ;
    }

    BEVT_DEBUG_LOG_INFO("rid(%s)", (long long int)bevt_client_g.rid);
    if(bevt_client_start_relay(0)<0)
        return -1;

    return (errno=0,0);
}
Exemple #9
0
btbool	cmpdirChangeFiles(cmpdir_t *dir)
{
btbool	rval = 1;
int		i, len;
char	path[1024];
unsigned char block[BUF_SIZE];

	if(trace)
		printf("changing file in %s\n", dir->name);
	i = random_int(CMPDIR_MAX_FILES);
	if(dir->files[i].name[0]){	/* file exists */
		if(!verifyFile(dir, i))
			rval = 0;
		if(close(dir->files[i].fd)){
			perr(errno, "error closing file %s in dir %s", dir->files[i].name, dir->name);
			rval = 0;
		}
		sprintf(path, "%s/%s", dir->name, dir->files[i].name);
		if(unlink(path)){
			perr(errno, "error unlinking file %s", path);
			rval = 0;
		}
		dir->files[i].fd = 0;
		dir->files[i].name[0] = 0;
	}else{	/* file does not exist */
		random_name(dir->files[i].name, 8, i);
		dir->files[i].filePattern = random_int(65536);
		sprintf(path, "%s/%s", dir->name, dir->files[i].name);
		if((dir->files[i].fd = open(path, O_RDWR|O_CREAT|O_TRUNC, 0600)) < 0){
			perr(errno, "error creating file %s in dir %s", dir->files[i].name, dir->name);
			rval = 0;
			dir->files[i].fd = 0;
			dir->files[i].name[0] = 0;
		}else{
			if((len = write(dir->files[i].fd, blockWithPattern(dir->files[i].filePattern, block), BUF_SIZE)) != BUF_SIZE){
				perr(errno, "error writing file %s, wlen = %d", path, len);
				rval = 0;
			}
		}
	}
	return rval;
}
Exemple #10
0
/** constructor
 @return an object or a null pointer if the object couldn't be created */
struct Client *Client(void) {
	struct Client *client;

	if(!(client = malloc(sizeof(struct Client)))) {
		perror("Client constructor");
		Client_(&client);
		return 0;
	}
	client->is_running= 0;
	client->id        = unique++;
	client->ms_idle   = time_between_prints;
	client->pages_min = min_page;
	client->pages_max = max_page;
	client->prints    = random_int(min_prints, max_prints);
	random_name(client->name);
	fprintf(stderr, "Client: new, %s (%d) #%p.\n", client->name, client->id, (void *)client);
	/*fixme! post(empty);*/

	return client;
}
Exemple #11
0
/* XXX This function really should be cancellable (for the benefit of
 * virt-sparsify).  However currently the library can only handle
 * cancellation for FileIn/FileOut operations.
 */
int
do_zero_free_space (const char *dir)
{
  size_t len = strlen (dir);
  char filename[sysroot_len+len+14]; /* sysroot + dir + "/" + 8.3 + "\0" */
  int fd;
  unsigned skip = 0;
  struct statvfs statbuf;
  fsblkcnt_t bfree_initial;

  /* Choose a randomly named 8.3 file.  Because of the random name,
   * this won't conflict with existing files, and it should be
   * compatible with any filesystem type inc. FAT.
   */
  snprintf (filename, sysroot_len+len+14, "%s%s/XXXXXXXX.XXX", sysroot, dir);
  if (random_name (filename) == -1) {
    reply_with_perror ("random_name");
    return -1;
  }

  if (verbose)
    printf ("random filename: %s\n", filename);

  /* Open file and fill with zeroes until we run out of space. */
  fd = open (filename, O_WRONLY|O_CREAT|O_EXCL|O_NOCTTY|O_CLOEXEC, 0600);
  if (fd == -1) {
    reply_with_perror ("open: %s", filename);
    return -1;
  }

  /* To estimate progress in this operation, we're going to track
   * free blocks in this filesystem down to zero.
   */
  if (fstatvfs (fd, &statbuf) == -1) {
    reply_with_perror ("fstatvfs");
    close (fd);
    return -1;
  }
  bfree_initial = statbuf.f_bfree;

  for (;;) {
    if (write (fd, zero_buf, sizeof zero_buf) == -1) {
      if (errno == ENOSPC)      /* expected error */
        break;
      reply_with_perror ("write: %s", filename);
      close (fd);
      unlink (filename);
      return -1;
    }

    skip++;
    if ((skip & 256) == 0 && fstatvfs (fd, &statbuf) == 0)
      notify_progress (bfree_initial - statbuf.f_bfree, bfree_initial);
  }

  /* Make sure the file is completely written to disk. */
  close (fd); /* expect this to give an error, don't check it */

  sync_disks ();

  notify_progress (bfree_initial, bfree_initial);

  /* Remove the file. */
  if (unlink (filename) == -1) {
    reply_with_perror ("unlink: %s", filename);
    return -1;
  }

  return 0;
}
void character_name(struct mtwist_state *mt, char *buffer,
			int buflen)
{
	switch (mtwist_int(mt, 8)) {
	case 0:
		snprintf(buffer, buflen, "%s %s %s %s%s", character_title(mt),
				random_name(mt), random_name(mt), random_name(mt),
				post_nominal_letters(mt));
		break;
	case 1:
		snprintf(buffer, buflen, "%s %c. %c. %s%s", character_title(mt),
				random_initial(mt), random_initial(mt), random_name(mt),
				post_nominal_letters(mt));
		break;
	case 2:
	case 3:
		snprintf(buffer, buflen, "%s %c. %s %s%s", character_title(mt),
				random_initial(mt), random_name(mt), random_name(mt),
				post_nominal_letters(mt));
		break;
	case 4:
		snprintf(buffer, buflen, "%s %c. %s%s", character_title(mt),
				random_initial(mt), random_name(mt),
				post_nominal_letters(mt));
		break;
	case 5:
		snprintf(buffer, buflen, "%s %s%s", character_title(mt),
				random_name(mt),
				post_nominal_letters(mt));
		break;
	case 6:
		snprintf(buffer, buflen, "%s %s %s%s", character_title(mt),
				random_name(mt), random_name(mt),
				post_nominal_letters(mt));
		break;
	case 7:
	default:
		snprintf(buffer, buflen, "%s %c. %c. %s%s", character_title(mt),
				random_initial(mt), random_initial(mt), random_name(mt),
				post_nominal_letters(mt));
		break;
	}
}