This service will be undergoing maintenance at 00:00 UTC, 2016-08-01. It is expected to last about 1 hours
Bug 105371 - RFE: exit/kill strace with traced child's exitcode/signal
RFE: exit/kill strace with traced child's exitcode/signal
Status: CLOSED ERRATA
Product: Fedora
Classification: Fedora
Component: strace (Show other bugs)
rawhide
All Linux
low Severity medium
: ---
: ---
Assigned To: Roland McGrath
David Lawrence
: FutureFeature, Patch
: 163613 (view as bug list)
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-09-25 10:45 EDT by Dmitry V. Levin
Modified: 2009-11-12 21:34 EST (History)
7 users (show)

See Also:
Fixed In Version: 4.5.19-1.fc10
Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2009-11-12 21:33:15 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)
proposed patch (3.79 KB, patch)
2003-09-25 10:46 EDT, Dmitry V. Levin
no flags Details | Diff
proposed patch (3.42 KB, patch)
2003-12-14 17:29 EST, Dmitry V. Levin
no flags Details | Diff
strace-4.5.12-alt-keep_status.patch (3.49 KB, patch)
2005-06-15 14:53 EDT, Dmitry V. Levin
no flags Details | Diff
strace-4.5.13-alt-keep_status.patch (3.50 KB, patch)
2005-08-08 13:26 EDT, Dmitry V. Levin
no flags Details | Diff
strace-4.5.14-alt-keep_status.patch (3.49 KB, patch)
2006-01-17 18:14 EST, Dmitry V. Levin
no flags Details | Diff
Patch: exit/kill ourself with straced child's exitcode/signal (1.91 KB, patch)
2008-09-24 12:07 EDT, Denys Vlasenko
no flags Details | Diff
strace-4.5.18-exit.patch (1.83 KB, patch)
2008-09-29 18:35 EDT, Dmitry V. Levin
no flags Details | Diff

  None (edit)
Description Dmitry V. Levin 2003-09-25 10:45:32 EDT
Description of problem: 
There is a need to translate exit status of traced process to strace caller. 
I'd like to propose new option -k for that purpose. 
 
Version-Release number of selected component (if applicable): 
4.4.99 
 
How to test: 
$ strace /bin/false 2>/dev/null; echo rc=$? 
rc=0 
$ strace /bin/true 2>/dev/null; echo rc=$? 
rc=0 
$ strace -k /bin/false 2>/dev/null; echo rc=$? 
rc=1 
$ strace -k /bin/true 2>/dev/null; echo rc=$? 
rc=0
Comment 1 Dmitry V. Levin 2003-09-25 10:46:09 EDT
Created attachment 94716 [details]
proposed patch
Comment 2 Roland McGrath 2003-11-06 21:27:44 EST
One problem with this interface is that strace getting an error itself
will still pollute the return value of the program.
Comment 3 Dmitry V. Levin 2003-11-07 08:53:42 EST
Is there any better approach? 
Comment 4 Dmitry V. Levin 2003-12-14 17:29:20 EST
Created attachment 96530 [details]
proposed patch

rediffed for strace-4.5.1, without coredump trace feature.
Comment 5 Dmitry V. Levin 2005-06-15 14:53:03 EDT
Created attachment 115496 [details]
strace-4.5.12-alt-keep_status.patch

Rediffed for new strace version.
Comment 6 Hans Ecke 2005-07-14 11:27:23 EDT
I'd like to support Dmitry's proposal. I run strace to know what files an 
application accesses that I only have as a binary. It works great! 
Unfortunately it does not give me an indication of the program's return value. 
So I have to parse strace's output for that which is error prone. 
 
Roland, its okay if we return failure if either program or strace fail. As the 
caller I can still output a reasonable error message. 
 
 
Comment 7 Roland McGrath 2005-07-19 17:12:02 EDT
*** Bug 163613 has been marked as a duplicate of this bug. ***
Comment 8 Dmitry V. Levin 2005-08-08 13:26:46 EDT
Created attachment 117548 [details]
strace-4.5.13-alt-keep_status.patch

Rediffed for strace-4.5.13.
Comment 9 Dmitry V. Levin 2006-01-17 18:14:28 EST
Created attachment 123341 [details]
strace-4.5.14-alt-keep_status.patch

Rediffed for strace-4.5.14
Comment 10 Roland McGrath 2007-11-19 17:19:46 EST
Please post on the ml, I think this can go in now.
No reason to conditionalize setting "return_code".

I think I'd like to see all other existing exit calls changed to
exit(failure_code) and then under -k we might set failure_code to 128 or
something.  That way strace having an error is easier to distinguish from the
likely exit codes of a traced process (such as 1 or 2).
Comment 11 Dmitry V. Levin 2007-11-19 18:25:40 EST
Dedicated exit code 128 in "-k" mode is OK for me.
Comment 12 John Poelstra 2008-07-02 15:28:30 EDT
(In reply to comment #10)
> Please post on the ml, I think this can go in now.
> No reason to conditionalize setting "return_code".
> 
> I think I'd like to see all other existing exit calls changed to
> exit(failure_code) and then under -k we might set failure_code to 128 or
> something.  That way strace having an error is easier to distinguish from the
> likely exit codes of a traced process (such as 1 or 2).

Hi Roland,

Should the status of this bug be changed as result of the ML discussion or any
subsequent work?

Thanks,
John
Comment 13 Denys Vlasenko 2008-09-09 08:14:06 EDT
Not to be meant as a criticism, but just a thought: passing back the exit code is a good idea, but sometimes it is not enough. For example, when parent process is normally sending signals to child, it breaks when you run child under strace.

Imagine that parent listens on a socekt and starts children for new connections:

$ parent 1.2.3.4:56 -e child arg1 arg1

If you run it like

$ parent 1.2.3.4:56 -e strace child arg1 arg1

, attempts to send signals between parent and child would not work as intended.

The nice thing to have would be an option for strace to fork, and exec traced child in *parent*, not child. Then child attaches to parent similarly to strace -p PID.

But of course this goes far beyond this bug.
Comment 14 Denys Vlasenko 2008-09-24 12:07:11 EDT
Created attachment 317603 [details]
Patch: exit/kill ourself with straced child's exitcode/signal

Apparently discussion on mailing list died out with no results.

I propose this patch. It just makes strace exit with child's exitcode.
Rationale:

I think in real-world usage people do not check strace usage in scripts. They just use it correctly, so that it doesn't exit(1) with usage info and whatnot.

But know for a fact that when I try to debug something by replacing "cmd [args]" with "strace cmd [args]" the fact that parent does not see exit code of cmd but seels zero, always, sometimes is a problem.

IOW: I do not think that there are users who will be adversely affected by this change in behavior. Therefore I do not think adding a switch to enable this is worth it. It will be just a case of featuritis.

Problems this patch fixes compared to previous patches:

* strace returns exit code of straced process, *never its children*.
* If child died from a signal, strace will (try to) die from the same signal.
* strace -p <pid> is not affected (will exit 0 as before).
Comment 15 Dmitry V. Levin 2008-09-29 18:29:39 EDT
(In reply to comment #14)
> Created an attachment (id=317603) [details]
> Patch: exit/kill ourself with straced child's exitcode/signal

I think your idea how to implement this RFE is better than mine.
I tested it and have no compatibility problems so far.
I'm OK to install your patch with minor cleanup.
Comment 16 Dmitry V. Levin 2008-09-29 18:35:29 EDT
Created attachment 318019 [details]
strace-4.5.18-exit.patch

Proposed patch (patch by Denys Vlasenko with minor cleanup).
Comment 17 rep.dot.nop 2008-10-16 13:27:02 EDT
in comment #10 Roland said "changed to exit(failure_code)", so what about using the EXIT_FAILURE as per stdlib.h as opposed to hardcoding it? Minor nit..
Comment 18 Fedora Update System 2009-10-21 14:08:50 EDT
strace-4.5.19-1.fc10 has been submitted as an update for Fedora 10.
http://admin.fedoraproject.org/updates/strace-4.5.19-1.fc10
Comment 19 Fedora Update System 2009-10-21 14:09:37 EDT
strace-4.5.19-1.fc11 has been submitted as an update for Fedora 11.
http://admin.fedoraproject.org/updates/strace-4.5.19-1.fc11
Comment 20 Fedora Update System 2009-10-27 02:32:38 EDT
strace-4.5.19-1.fc10 has been pushed to the Fedora 10 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update strace'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/F10/FEDORA-2009-10733
Comment 21 Fedora Update System 2009-10-27 03:13:20 EDT
strace-4.5.19-1.fc11 has been pushed to the Fedora 11 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update strace'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/F11/FEDORA-2009-10843
Comment 22 Fedora Update System 2009-11-12 21:32:33 EST
strace-4.5.19-1.fc11 has been pushed to the Fedora 11 stable repository.  If problems still persist, please make note of it in this bug report.
Comment 23 Fedora Update System 2009-11-12 21:34:00 EST
strace-4.5.19-1.fc10 has been pushed to the Fedora 10 stable repository.  If problems still persist, please make note of it in this bug report.

Note You need to log in before you can comment on or make changes to this bug.