envlogtest - environment logging utility.
This duplicates the information found in README.txt in the download package.
Extract files with:
# tar -xvzf envlogtest-1.tar.gz
Version 1
envlogtest
Copyright © 2014 C_Xperimental.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
Texts.
An example of envlogtest in use:
Sat May 10 13:14:51 2014
envlogtest networking right at the beginning
Real user ID = 0, real group ID = 0
Effective user ID = 0, effective group ID = 0
No supplementary groups were found
CONSOLE=/dev/console
HOME=/
init=/sbin/init
runlevel=S
INIT_VERSION=sysvinit-2.88
TERM=linux
COLUMNS=175
BOOT_IMAGE=Linux
PATH=/sbin:/bin:/usr/local/bin
RUNLEVEL=S
AUTOBOOT=YES
PREVLEVEL=N
SHELL=/bin/sh
PWD=/
previous=N
LINES=65
rootmnt=/root
STDIN_FILENO = 0 : ttyname = /dev/console
STDOUT_FILENO = 1 : ttyname = /dev/pts/2
STDERR_FILENO = 2 : ttyname = /dev/pts/2
FD 0 : FD_CLOEXEC not set
FD 0 : O_RDONLY not set
FD 0 : O_WRONLY not set
FD 0 : O_RDWR set
FD 0 : O_APPEND not set
FD 0 : O_NONBLOCK not set
FD 0 : O_ASYNC not set
FD 0 : O_FSYNC not set
FD 1 : FD_CLOEXEC not set
FD 1 : O_RDONLY not set
FD 1 : O_WRONLY not set
FD 1 : O_RDWR set
FD 1 : O_APPEND not set
FD 1 : O_NONBLOCK not set
FD 1 : O_ASYNC not set
FD 1 : O_FSYNC not set
FD 2 : FD_CLOEXEC not set
FD 2 : O_RDONLY not set
FD 2 : O_WRONLY not set
FD 2 : O_RDWR set
FD 2 : O_APPEND not set
FD 2 : O_NONBLOCK not set
FD 2 : O_ASYNC not set
FD 2 : O_FSYNC not set
This entry was created by adding the command:
envlogtest networking right at the beginning
to the script "/etc/init.d/networking". Watch out for whitespace - preceding
tabs or spaces might make a difference for commands to work in some shell
scripts.
Also some characters could cause syntax errors, simple words as shown are the
easiest to use for an identifying argument to envlogtest.
It doesn't matter what arguments you give envlogtest, it just uses them to
print out as an identifier for the log. Probably there are some limits on
the amount of text, governed by the OS, but for any sensible use you can add
whatever is convenient.
If the /etc/init.d/networking script had been modified for example, use:
#invoke-rc.d networking stop / #invoke-rc.d networking start to test afterwards
as it may be better to find any error messages now, than at the next boot.
For an init script envlogtest should be located somewhere in the PATH variable
at the top of the script, or the PATH variable expanded to include say
/usr/local/bin if it is not already included, if the envlogtest executable
was in /usr/local/bin.
If any of these read ttyname = (null):
STDIN_FILENO = 0 : ttyname = /dev/console
STDOUT_FILENO = 1 : ttyname = /dev/pts/2
STDERR_FILENO = 2 : ttyname = /dev/pts/2
it means the file descriptor is not connected to a tty, it does not mean it is
pointed at /dev/null although that is one possibility, it only proves it isn't
a tty.
envlogtest was written to debug the boot sequence and find out what was
happening at various points, and when those events happened. It can be used
along with bootlog and syslog to cross reference the times when scripts begin
and end, as sometimes an apparently simple init script may start a chain of
code that takes several seconds before the script finally exits.
This is usually in parallel with other init scripts running and may extend
into a different runlevel than the one in which it was started.
It might well be helpful in it's present form, but there is no reason why
additional tests should not be added if desired. To avoid altering timings
too much I suggest scattering a few "envlogtest running at wherever" commands
in the init scripts and then narrowing down to the area of interest, deleting
unneeded additions. Also back up a copy of the old init script in case of
accidentally deleting bits, so the copy can be cp 'd back when the test is no
longer needed. As envlogtest is quite minimal it is unlikely to alter timings,
but doubtless if it was deployed in large enough numbers it could do.
As an alternative to a back up the relevant package could be reinstalled.
envlogtest can also be added as a function in larger pieces of code and run
at points of interest, if it was useful to check timings and environment
issues. See the file envlogfunction.c for an example of this. Actually it is
4 functions as implemented here. Some C programming knowledge is needed to
use this.
"gcc" must be installed before compiling.
Compile envlogtest from the source file with:
$ gcc -Wall -Wextra -o envlogtest envlogtest.c
Minimise the binary size:
$ strip -s envlogtest
Create the log file:
# touch /var/log/envlogtest_log
Set permissions
# chmod a+rw /var/log/envlogtest_log
If you were concerned about non root users reading the contents:
#chmod go-r /var/log/envlogtest_log
This is the easiest way to set up the log file properly as otherwise
envlogtest would need root permission to run which can cause complications.
envlogtest was not written for high security applications. In most situations
it won't print especially private data. It's intended to be a simple testing
device for solving occasional problems.
Configure logrotate for log file.
Create this file at this location: /etc/logrotate.d/envlogtest
with these contents shown below:
/var/log/envlogtest_log
{
rotate 7
daily
dateext
missingok
notifempty
nocompress
copytruncate
}
This enables logrotate to automatically manage the log files created, so they
do not fill up. If no output is written on a particular day then no rotation
takes place.
When all the elements are in place the information will be gathered and
collected until you are ready to analyse it, or a particular event happens you
are investigating.
The rotation happens once a day and 7 files are backed up before the oldest is
automatically deleted.
(Presuming logrotate, cron and in most cases anacron are installed and working)
The log file location is set in "main":
char *log_file_name = "/var/log/envlogtest_log";
This can be changed if desired.
Install envlogtest:
# cp envlogtest /usr/local/bin
To test run envlogtest:
$ envlogtest running as a test example from the command line
Written and tested in Debian Linux 6 Squeeze, and 7 Wheezy.
Extract files with:
# tar -xvzf envlogtest-1.tar.gz
Version 1
envlogtest
Copyright © 2014 C_Xperimental.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
Texts.
An example of envlogtest in use:
Sat May 10 13:14:51 2014
envlogtest networking right at the beginning
Real user ID = 0, real group ID = 0
Effective user ID = 0, effective group ID = 0
No supplementary groups were found
CONSOLE=/dev/console
HOME=/
init=/sbin/init
runlevel=S
INIT_VERSION=sysvinit-2.88
TERM=linux
COLUMNS=175
BOOT_IMAGE=Linux
PATH=/sbin:/bin:/usr/local/bin
RUNLEVEL=S
AUTOBOOT=YES
PREVLEVEL=N
SHELL=/bin/sh
PWD=/
previous=N
LINES=65
rootmnt=/root
STDIN_FILENO = 0 : ttyname = /dev/console
STDOUT_FILENO = 1 : ttyname = /dev/pts/2
STDERR_FILENO = 2 : ttyname = /dev/pts/2
FD 0 : FD_CLOEXEC not set
FD 0 : O_RDONLY not set
FD 0 : O_WRONLY not set
FD 0 : O_RDWR set
FD 0 : O_APPEND not set
FD 0 : O_NONBLOCK not set
FD 0 : O_ASYNC not set
FD 0 : O_FSYNC not set
FD 1 : FD_CLOEXEC not set
FD 1 : O_RDONLY not set
FD 1 : O_WRONLY not set
FD 1 : O_RDWR set
FD 1 : O_APPEND not set
FD 1 : O_NONBLOCK not set
FD 1 : O_ASYNC not set
FD 1 : O_FSYNC not set
FD 2 : FD_CLOEXEC not set
FD 2 : O_RDONLY not set
FD 2 : O_WRONLY not set
FD 2 : O_RDWR set
FD 2 : O_APPEND not set
FD 2 : O_NONBLOCK not set
FD 2 : O_ASYNC not set
FD 2 : O_FSYNC not set
This entry was created by adding the command:
envlogtest networking right at the beginning
to the script "/etc/init.d/networking". Watch out for whitespace - preceding
tabs or spaces might make a difference for commands to work in some shell
scripts.
Also some characters could cause syntax errors, simple words as shown are the
easiest to use for an identifying argument to envlogtest.
It doesn't matter what arguments you give envlogtest, it just uses them to
print out as an identifier for the log. Probably there are some limits on
the amount of text, governed by the OS, but for any sensible use you can add
whatever is convenient.
If the /etc/init.d/networking script had been modified for example, use:
#invoke-rc.d networking stop / #invoke-rc.d networking start to test afterwards
as it may be better to find any error messages now, than at the next boot.
For an init script envlogtest should be located somewhere in the PATH variable
at the top of the script, or the PATH variable expanded to include say
/usr/local/bin if it is not already included, if the envlogtest executable
was in /usr/local/bin.
If any of these read ttyname = (null):
STDIN_FILENO = 0 : ttyname = /dev/console
STDOUT_FILENO = 1 : ttyname = /dev/pts/2
STDERR_FILENO = 2 : ttyname = /dev/pts/2
it means the file descriptor is not connected to a tty, it does not mean it is
pointed at /dev/null although that is one possibility, it only proves it isn't
a tty.
envlogtest was written to debug the boot sequence and find out what was
happening at various points, and when those events happened. It can be used
along with bootlog and syslog to cross reference the times when scripts begin
and end, as sometimes an apparently simple init script may start a chain of
code that takes several seconds before the script finally exits.
This is usually in parallel with other init scripts running and may extend
into a different runlevel than the one in which it was started.
It might well be helpful in it's present form, but there is no reason why
additional tests should not be added if desired. To avoid altering timings
too much I suggest scattering a few "envlogtest running at wherever" commands
in the init scripts and then narrowing down to the area of interest, deleting
unneeded additions. Also back up a copy of the old init script in case of
accidentally deleting bits, so the copy can be cp 'd back when the test is no
longer needed. As envlogtest is quite minimal it is unlikely to alter timings,
but doubtless if it was deployed in large enough numbers it could do.
As an alternative to a back up the relevant package could be reinstalled.
envlogtest can also be added as a function in larger pieces of code and run
at points of interest, if it was useful to check timings and environment
issues. See the file envlogfunction.c for an example of this. Actually it is
4 functions as implemented here. Some C programming knowledge is needed to
use this.
"gcc" must be installed before compiling.
Compile envlogtest from the source file with:
$ gcc -Wall -Wextra -o envlogtest envlogtest.c
Minimise the binary size:
$ strip -s envlogtest
Create the log file:
# touch /var/log/envlogtest_log
Set permissions
# chmod a+rw /var/log/envlogtest_log
If you were concerned about non root users reading the contents:
#chmod go-r /var/log/envlogtest_log
This is the easiest way to set up the log file properly as otherwise
envlogtest would need root permission to run which can cause complications.
envlogtest was not written for high security applications. In most situations
it won't print especially private data. It's intended to be a simple testing
device for solving occasional problems.
Configure logrotate for log file.
Create this file at this location: /etc/logrotate.d/envlogtest
with these contents shown below:
/var/log/envlogtest_log
{
rotate 7
daily
dateext
missingok
notifempty
nocompress
copytruncate
}
This enables logrotate to automatically manage the log files created, so they
do not fill up. If no output is written on a particular day then no rotation
takes place.
When all the elements are in place the information will be gathered and
collected until you are ready to analyse it, or a particular event happens you
are investigating.
The rotation happens once a day and 7 files are backed up before the oldest is
automatically deleted.
(Presuming logrotate, cron and in most cases anacron are installed and working)
The log file location is set in "main":
char *log_file_name = "/var/log/envlogtest_log";
This can be changed if desired.
Install envlogtest:
# cp envlogtest /usr/local/bin
To test run envlogtest:
$ envlogtest running as a test example from the command line
Written and tested in Debian Linux 6 Squeeze, and 7 Wheezy.