int main(int argc, char** argv)
{
  char cwd[512];
  char path[512];

  cwd[0] = 0;
  if (! getcwd(cwd, sizeof(cwd)))
    perror("getcwd");
  strcat(cwd, "/");

  snprintf(path, sizeof(path), "/proc/%d/cmdline", getpid());

  test_cmdline(cwd, "/proc/self/cmdline", "/proc/self/cmdline");
  test_cmdline(cwd, "/proc/<pid>/cmdline", path);

  snprintf(path, sizeof(path), "/proc/%d/exe", getpid());

  test_readlink(cwd, "/proc/self/exe", "/proc/self/exe");
  test_readlink(cwd, "/proc/<pid>/exe", path);

  test_readlinkat(cwd, "/proc/self/exe", "/proc/self/exe");
  test_readlinkat(cwd, "/proc/<pid>/exe", path);

  return 0;
}
Ejemplo n.º 2
0
int
main (void)
{
  char buf[80];
  int result;

  /* Remove any leftovers from a previous partial run.  */
  ignore_value (system ("rm -rf " BASE "*"));

  /* Perform same checks as counterpart functions.  */
  result = test_readlink (do_readlink, false);
  ASSERT (test_symlink (do_symlink, false) == result);
  dfd = openat (AT_FDCWD, ".", O_RDONLY);
  ASSERT (0 <= dfd);
  ASSERT (test_readlink (do_readlink, false) == result);
  ASSERT (test_symlink (do_symlink, false) == result);

  /* Now perform some cross-directory checks.  Skip everything else on
     mingw.  */
  if (HAVE_SYMLINK)
    {
      const char *contents = "don't matter!";
      ssize_t exp = strlen (contents);

      /* Create link while cwd is '.', then read it in '..'.  */
      ASSERT (symlinkat (contents, AT_FDCWD, BASE "link") == 0);
      errno = 0;
      ASSERT (symlinkat (contents, dfd, BASE "link") == -1);
      ASSERT (errno == EEXIST);
      ASSERT (chdir ("..") == 0);
      errno = 0;
      ASSERT (readlinkat (AT_FDCWD, BASE "link", buf, sizeof buf) == -1);
      ASSERT (errno == ENOENT);
      ASSERT (readlinkat (dfd, BASE "link", buf, sizeof buf) == exp);
      ASSERT (strncmp (contents, buf, exp) == 0);
      ASSERT (unlinkat (dfd, BASE "link", 0) == 0);

      /* Create link while cwd is '..', then read it in '.'.  */
      ASSERT (symlinkat (contents, dfd, BASE "link") == 0);
      ASSERT (fchdir (dfd) == 0);
      errno = 0;
      ASSERT (symlinkat (contents, AT_FDCWD, BASE "link") == -1);
      ASSERT (errno == EEXIST);
      buf[0] = '\0';
      ASSERT (readlinkat (AT_FDCWD, BASE "link", buf, sizeof buf) == exp);
      ASSERT (strncmp (contents, buf, exp) == 0);
      buf[0] = '\0';
      ASSERT (readlinkat (dfd, BASE "link", buf, sizeof buf) == exp);
      ASSERT (strncmp (contents, buf, exp) == 0);
      ASSERT (unlink (BASE "link") == 0);
    }

  ASSERT (close (dfd) == 0);
  if (result == 77)
    fputs ("skipping test: symlinks not supported on this file system\n",
           stderr);
  return result;
}
Ejemplo n.º 3
0
int
main (void)
{
  /* Remove any leftovers from a previous partial run.  */
  ignore_value (system ("rm -rf " BASE "*"));

  return test_readlink (readlink, true);
}
Ejemplo n.º 4
0
int main(int argc, char **argv) {
	setvbuf(stdout, NULL, _IONBF, 0);
	assert(chdir("/ext2") == 0);

	test_open_read("abslinketc", 0);
	test_open_read("abslinkroot", 0);
	test_open_read("nestlink/5/mountslink", 0);
	test_open_read("nestedlinksdir/5/file", 0);

	test_open_read("nestedlinksdir/1/file", ELOOP);
	test_open_read("inf1", ELOOP);
	test_open_read("broken/relfile", ENOENT);

	test_opendir_getdents("bin", 0);
	test_opendir_getdents("nestedlinksdir/6", 0);

	test_opendir_getdents("nestedlinksdir/2", ELOOP);
	test_opendir_getdents("inf1", ELOOP);
	test_opendir_getdents("broken/absdir", ENOENT);

	test_readlink("longlink", 0, "this_is_a_very_long_link_value/which_certainly_is_longer_than_the_60_char_limit_on_fast_symbolic_links");
	test_readlink("shortlink_absolute", 0, "/bin/ls");
	test_readlink("broken/absfile", 0, "/doesnotexist");
	test_readlink("nestedlinksdir", EINVAL, NULL);
	test_readlink("/ext2/numbers", EINVAL, NULL);
	test_readlink("doesnotexist", ENOENT, NULL);

	struct stat st;

	printf("testing stat on shortlink_relative... ");
	int ret = stat("shortlink_relative", &st);
	if (ret != 0) {
		printf("failed, error = %s\n", strerror(errno));
		failures++;
	}
	else {
		if (st.st_size == 292) {
			printf("success\n");
			successes++;
		}
		else {
			printf("failed! size != 292\n");
			failures++;
		}
	}

	printf("testing lstat on shortlink_relative... ");
	ret = lstat("shortlink_relative", &st);
	if (ret != 0) {
		printf("failed, error = %s\n", strerror(errno));
		failures++;
	}
	else {
		if (st.st_size == 7) {
			printf("success\n");
			successes++;
		}
		else {
			printf("failed! size != 7\n");
			failures++;
		}
	}

	// Test everything again, but with absolute paths, and with PWD != the ext2 root

	assert(chdir("/bin/tests") == 0);

	test_open_read("/ext2/abslinketc", 0);
	test_open_read("/ext2/abslinkroot", 0);
	test_open_read("/ext2/nestlink/5/mountslink", 0);
	test_open_read("/ext2/nestedlinksdir/5/file", 0);

	test_open_read("/ext2/nestedlinksdir/1/file", ELOOP);
	test_open_read("/ext2/inf1", ELOOP);
	test_open_read("/ext2/broken/relfile", ENOENT);

	test_opendir_getdents("/ext2/bin", 0);
	test_opendir_getdents("/ext2/nestedlinksdir/6", 0);

	test_opendir_getdents("/ext2/nestedlinksdir/2", ELOOP);
	test_opendir_getdents("/ext2/inf1", ELOOP);
	test_opendir_getdents("/ext2/broken/absdir", ENOENT);

	test_readlink("/ext2/longlink", 0, "this_is_a_very_long_link_value/which_certainly_is_longer_than_the_60_char_limit_on_fast_symbolic_links");
	test_readlink("/ext2/shortlink_absolute", 0, "/bin/ls");
	test_readlink("/ext2/broken/absfile", 0, "/doesnotexist");
	test_readlink("/ext2/nestedlinksdir", EINVAL, NULL);
	test_readlink("/ext2/numbers", EINVAL, NULL);
	test_readlink("/ext2/doesnotexist", ENOENT, NULL);

	printf("testing stat on shortlink_relative... ");
	ret = stat("/ext2/shortlink_relative", &st);
	if (ret != 0) {
		printf("failed, error = %s\n", strerror(errno));
		failures++;
	}
	else {
		if (st.st_size == 292) {
			printf("success\n");
			successes++;
		}
		else {
			printf("failed! size != 292\n");
			failures++;
		}
	}

	printf("testing lstat on shortlink_relative... ");
	ret = lstat("/ext2/shortlink_relative", &st);
	if (ret != 0) {
		printf("failed, error = %s\n", strerror(errno));
		failures++;
	}
	else {
		if (st.st_size == 7) {
			printf("success\n");
			successes++;
		}
		else {
			printf("failed! size != 7\n");
			failures++;
		}
	}

	printf("done testing! %d successes, %d failures\n", successes, failures);

	return failures; // hopefully equivalent to return 0
}