/*
 * Copyright 2010 The Native Client Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>


int main(int argc, char **argv, char **env) {
  int count = 0;
  char **ptr;

  for (ptr = environ; *ptr != NULL; ptr++) {
    count++;
  }
  printf("%i environment variables\n", count);
  for (ptr = environ; *ptr != NULL; ptr++) {
    printf("%s\n", *ptr);
  }

  assert(env == environ);

  return 0;
}

/*
 * Copyright 2010 The Native Client Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

/*
 * In the glibc dynamic linking case, CommandSelLdrTestNacl
 * passes LD_LIBRARY_PATH in the environment for tests.
 * Ignore this variable for purposes of this test.
 */
static bool skip_env_var(const char *envstring) {
#ifdef __GLIBC__
  static const char kLdLibraryPath[] = "LD_LIBRARY_PATH=";
  if (!strncmp(envstring, kLdLibraryPath, sizeof(kLdLibraryPath) - 1))
    return true;
#endif
  return false;
}

int main(int argc, char **argv, char **env) {
  int count = 0;
  char **ptr;

  for (ptr = environ; *ptr != NULL; ptr++) {
    if (!skip_env_var(*ptr))
      count++;
  }
  printf("%i environment variables\n", count);
  for (ptr = environ; *ptr != NULL; ptr++) {
    if (!skip_env_var(*ptr))
      puts(*ptr);
  }

  assert(env == environ);

  return 0;
}

Make environment_variables test ignore LD_LIBRARY_PATH for glibc
Make environment_variables test ignore LD_LIBRARY_PATH for glibc

This test pumps specific values through sel_ldr with -E and then
tests that the entire environment seen by the untrusted program
is exactly that list, using a golden file.  CommandSelLdrTestNacl
uses -E to pass LD_LIBRARY_PATH to the nexe for new (ARM) glibc.
So that variable's presence in environ is not a bug.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=3068
TEST= trybots + scons platform=arm --nacl_glibc run_env_var_test_irt
R=phosek@chromium.org, mseaborn@chromium.org

Review URL: https://codereview.chromium.org/1116963005
