2003-01-21 Roland McGrath <roland@redhat.com>
* strace.c (usage): Omit -z, since it has never worked properly.
* NEWS: Likewise.
* strace.c (main): Grok new option `-E var=val' or `-E var' to put
var=val in environ or to remove var, respectively.
(usage): Mention it.
* strace.1, NEWS: Document it.
diff --git a/NEWS b/NEWS
index 273e97a..7bb2c40 100644
--- a/NEWS
+++ b/NEWS
@@ -1,9 +1,9 @@
-Changes in 4.4.93 TEST release
+Changes in 4.4.94 TEST release
==============
* New port to AMD's x86-64 architecture. One strace binary can
handle both new x86-64 and old i386 processes.
* Fixed support for LFS64 calls.
-* New switch (-z) for printing only non-failing syscalls.
+* New switch -E to add/remove environment variables for the command.
* Merged s390/s390x port.
* Trace an unbounded number of processes.
* Handle numerous new system calls in Linux 2.5, and new threads semantics.
diff --git a/strace.c b/strace.c
index a456efd..6171245 100644
--- a/strace.c
+++ b/strace.c
@@ -136,8 +136,10 @@
{
fprintf(ofp, "\
usage: strace [-dffhiqrtttTvVxx] [-a column] [-e expr] ... [-o file]\n\
- [-p pid] ... [-s strsize] [-u username] [command [arg ...]]\n\
- or: strace -c [-e expr] ... [-O overhead] [-S sortby] [command [arg ...]]\n\
+ [-p pid] ... [-s strsize] [-u username] [-E var=val] ...\n\
+ [command [arg ...]]\n\
+ or: strace -c [-e expr] ... [-O overhead] [-S sortby] [-E var=val] ...\n\
+ [command [arg ...]]\n\
-c -- count time, calls, and errors for each syscall and report summary\n\
-f -- follow forks, -ff -- with output into separate files\n\
-F -- attempt to follow vforks, -h -- print help message\n\
@@ -156,8 +158,12 @@
-s strsize -- limit length of print strings to STRSIZE chars (default %d)\n\
-S sortby -- sort syscall counts by: time, calls, name, nothing (default %s)\n\
-u username -- run command as username handling setuid and/or setgid\n\
+-E var=val -- put var=val in the environment for command\n\
+-E var -- remove var from the environment for command\n\
+" /* this is broken, so don't document it
-z -- print only succeeding syscalls\n\
-", DEFAULT_ACOLUMN, DEFAULT_STRLEN, DEFAULT_SORTBY);
+ */
+, DEFAULT_ACOLUMN, DEFAULT_STRLEN, DEFAULT_SORTBY);
exit(exitval);
}
@@ -200,7 +206,7 @@
set_sortby(DEFAULT_SORTBY);
set_personality(DEFAULT_PERSONALITY);
while ((c = getopt(argc, argv,
- "+cdfFhiqrtTvVxza:e:o:O:p:s:S:u:")) != EOF) {
+ "+cdfFhiqrtTvVxza:e:o:O:p:s:S:u:E:")) != EOF) {
switch (c) {
case 'c':
cflag++;
@@ -260,7 +266,7 @@
set_overhead(atoi(optarg));
break;
case 'p':
- if ((pid = atoi(optarg)) == 0) {
+ if ((pid = atoi(optarg)) <= 0) {
fprintf(stderr, "%s: Invalid process id: %s\n",
progname, optarg);
break;
@@ -270,7 +276,7 @@
break;
}
if ((tcp = alloctcb(pid)) == NULL) {
- fprintf(stderr, "%s: tcb table full, please recompile strace\n",
+ fprintf(stderr, "%s: out of memory\n",
progname);
exit(1);
}
@@ -286,6 +292,13 @@
case 'u':
username = strdup(optarg);
break;
+ case 'E':
+ if (putenv(optarg) < 0) {
+ fprintf(stderr, "%s: out of memory\n",
+ progname);
+ exit(1);
+ }
+ break;
default:
usage(stderr, 1);
break;