Stas Bekman > Env-C-0.06 > Env::C

Download:
Env-C-0.06.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  2
Open  0
View/Report Bugs
Module Version: 0.06   Source   Latest Release: Env-C-0.08

NAME ^

Env::C - Get/Set/Unset Environment Variables on the C level

SYNOPSIS ^

  use Env::C;
  
  my $key = "USER";
  $val = Env::C::getenv($key) || '';
  
  Env::C::setenv($key, "foobar", [$override]);
  $new_val = Env::C::getenv($key) || '';
  
  Env::C::unsetenv($key);
  
  my $ar_env = Env::C::getallenv();
  print join "\n", @$ar_env;

DESCRIPTION ^

This module provides a Perl API for getenv(3), setenv(3) and unsetenv(3). It also can return all the environ variables.

Sometimes Perl invokes modules with underlaying C APIs which rely on certain environment variables to be set, if these variables are set in Perl and the glue code doesn't worry to set them on the C level, these variables might not be seen by the C level. This module shows what really the C level sees.

FUNCTIONS

EXPORT

None.

Thread-safety and Thread-locality ^

This module should not be used in the threaded enviroment.

Thread-locality: the OS, which maintains the struct environ, shares it between all threads in the process. So if you modify it in one thread, all other threads will see the new value. Something that will most likely break the code.

This module is not thread-safe, since two threads may attempt to modify/read the struct environ at the same time. I could add locking if in threaded-environment. However since the lock can't be seen by other applications, they can still bypass it causing race condition. But since thread-locality is not maintained, making this module thread-safe is useless.

If you need to modify the C level of %ENV for all threads to see, do that before threads are started. (e.g. for mod_perl 2.0, at the server startup).

AUTHOR ^

Stas Bekman <stas@stason.org>

COPYRIGHT ^

This is a free software; you can redistribute it and/or modify it under the terms of the Artistic License.

SEE ALSO ^

perl.

syntax highlighting: