Find out which environment variables are used by the team

in a Linux environment (in my case, XUbuntu), is there a way to find out which environment variables the command invoked from the console refers to?

It should be possible to learn about these variables, as someone needs to provide values ​​to the program. But is there a default way to do this?

This is about xprintidle.

Thanks in advance, Jost

+6
source share
4 answers

Assuming you want variables actually used by some process to execute a command, you could use ltrace and look for getenv calls

Of course, the getenv argument can be evaluated (so you cannot predict it).

However, some (old or strange) applications may use environ global or the third optional argument to main ; and some applications even change their environment using putenv , setenv or unsetenv (all 3 are libc functions, not the built-in shell).

but xprintidle mainly interacts with the Xorg server. I am surprised that you expect it to use a lot of environment variables (except DISPLAY ).

+7
source

Do you mean actual access or specific environment variables for the process?

For a specific environment, you can use:

perl -pe 's,\00,\n,g' /proc/xxxx/environ

where xxxx is the PID of your process.

To access the variables you will need to use something like ltrace and check for getenv() calls.

+3
source

If you need a list of environment variables, this is done using env

But determining which variables are available to the program is impossible, since they are all passed as is.

0
source

You can see the environment variables that are passed to your program using the printenv command.

One way programs can look at their environment is to use the getenv call so that you can use the LD_PRELOAD tracer program or trick to wrap this call and find out what they are looking for.

However, not all programs use getenv to view their environment. If the program uses the following (unusual) format for the main one, it can view environment variables using the envp pointer:

 int main(int argc, char *argv[], char *envp[]) { /* ... */ } 

In addition, programs can access the environment through the environment variable.

You will probably be able to track getenv calls, but this does not guarantee that it depends on the program and the program.

0
source

Source: https://habr.com/ru/post/903704/


All Articles