[Nix-dev] Inspecting getenv(3) calls

Ludovic Courtès ludo at gnu.org
Wed Aug 12 15:52:34 CEST 2009


/* Display looked up environment variables.

   Compile as shown at the bottom of this file.

   Run with:

     $ LD_PRELOAD=./getenv.so some-program

   Written by Ludovic Court?s <ludo at gnu.org>.  Hereby placed under the
   LGPLv3+.
 */

#include <stdio.h>
#include <gnu/lib-names.h>
#include <dlfcn.h>

static void *glibc;
static char * (*glibc_getenv) (const char *);

static void load_glibc (void) __attribute__ ((__constructor__));

static void
load_glibc (void)
{
  glibc = dlopen (LIBC_SO, RTLD_LAZY);
  glibc_getenv = dlsym (glibc, "getenv");
}

char *
getenv (const char *name)
{
  char *result;

  result = glibc_getenv (name);

  printf ("getenv (\"%s\") = %s%s%s\n", name,
	  result ? "\"" : "",
	  result ? result : "NULL",
	  result ? "\"" : "");

  return result;
}

/*
   Local Variables:
   compile-command: "gcc -Wall -shared -fPIC -o getenv.so getenv.c"
   End:
 */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
Url : http://lists.science.uu.nl/pipermail/nix-dev/attachments/20090812/b8473d4a/attachment.bin 


More information about the nix-dev mailing list