My program uses an environment variable DBG_MSG
value to determine the level of debug messages. DBG_MSG=3
prints the maximum debug information.
However whenever the program is behaving in a strange unexpected way the environment variable is not set to print the full debug information. And when program is rerun with environment set it won't show the same error.
I am thinking of implementing a signal handler for SIGUSR1
to set this environment variable at runtime, using putenv(3)
. This way I can send the signal to a hung job to make it print more debug info.
What are some safety measures to take when doing this ?
Are there any other ways to change environment of a running program from outside ?