Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Add strace's -E option for setting/clearing environment variables
  from the command's inherited environment variable list.

  This eliminates having to use /bin/env and allows one to preload
  the subcommand using LD_PRELOAD.
  • Loading branch information
mheffner committed Oct 9, 2009
1 parent 1637655 commit f8ae467
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
13 changes: 12 additions & 1 deletion ltrace.1
Expand Up @@ -6,7 +6,7 @@ ltrace \- A library call tracer

.SH SYNOPSIS
.B ltrace
.I "[-CfhiLrStttV] [-a column] [-A maxelts] [-D level] [-e expr] [-l filename] [-n nr] [-o filename] [-p pid] ... [-s strsize] [-u username] [-X extern] [-x extern] ... [--align=column] [--debug=level] [--demangle] [--help] [--indent=nr] [--library=filename] [--output=filename] [--version] [command [arg ...]]"
.I "[-CfhiLrStttV] [-a column] [-A maxelts] [-D level] [-e expr] [-l filename] [-n nr] [-o filename] [-p pid] ... [-s strsize] [-u username] [-X extern] [-x extern] ... [--align=column] [--debug=level] [--demangle] [--help] [--indent=nr] [--library=filename] [--output=filename] [-Evar=val] [-Evar] [--version] [command [arg ...]]"

.SH DESCRIPTION
.B ltrace
Expand Down Expand Up @@ -76,6 +76,17 @@ Note that some shells use the exclamation point for history
expansion; even inside quoted arguments. If so, you must escape
the exclamation point with a backslash.
.TP
.I \-E var=val
Run command with
.I var=val
in its list of environment variables.
.TP
.I \-E var
Remove
.I var
from the inherited list of environment variables
before passing them on to the command.
.TP
.I \-f
Trace child processes as they are created by
currently traced processes as a result of the fork(2)
Expand Down
11 changes: 10 additions & 1 deletion options.c
Expand Up @@ -82,6 +82,8 @@ usage(void) {
" -D, --debug=LEVEL enable debugging (see -Dh or --debug=help).\n"
" -Dh, --debug=help show help on debugging.\n"
" -e expr modify which events to trace.\n"
" -E var=val put var=val in the environment for cmd.\n"
" -E var remove var from the environment for cmd.\n"
" -f trace children (fork() and clone()).\n"
" -F, --config=FILE load alternate configuration file (may be repeated).\n"
" -h, --help display this help and exit.\n"
Expand Down Expand Up @@ -204,7 +206,7 @@ process_options(int argc, char **argv) {
# ifdef USE_DEMANGLE
"C"
# endif
"a:A:D:e:F:l:n:o:p:s:u:x:X:", long_options,
"a:A:D:e:E:F:l:n:o:p:s:u:x:X:", long_options,
&option_index);
if (c == -1) {
break;
Expand Down Expand Up @@ -268,6 +270,13 @@ process_options(int argc, char **argv) {
}
break;
}
case 'E':
if (putenv(optarg) < 0) {
fprintf(stderr, "%s: Out of memory\n",
progname);
exit(1);
}
break;
case 'f':
options.follow = 1;
break;
Expand Down

0 comments on commit f8ae467

Please sign in to comment.