Bug 105371

Summary: RFE: exit/kill strace with traced child's exitcode/signal
Product: [Fedora] Fedora Reporter: Dmitry V. Levin <ldv>
Component: straceAssignee: Roland McGrath <roland>
Status: CLOSED ERRATA QA Contact: David Lawrence <dkl>
Severity: medium Docs Contact:
Priority: low    
Version: rawhideCC: dvlasenk, hansecke, jan.kratochvil, jreiser, poelstra, rep.dot.nop, sschaefer
Target Milestone: ---Keywords: FutureFeature, Patch
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: 4.5.19-1.fc10 Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-11-13 02:33:15 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
proposed patch
none
proposed patch
none
strace-4.5.12-alt-keep_status.patch
none
strace-4.5.13-alt-keep_status.patch
none
strace-4.5.14-alt-keep_status.patch
none
Patch: exit/kill ourself with straced child's exitcode/signal
none
strace-4.5.18-exit.patch none

Description Dmitry V. Levin 2003-09-25 14:45:32 UTC
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 14:46:09 UTC
Created attachment 94716 [details]
proposed patch

Comment 2 Roland McGrath 2003-11-07 02:27:44 UTC
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 13:53:42 UTC
Is there any better approach? 

Comment 4 Dmitry V. Levin 2003-12-14 22:29:20 UTC
Created attachment 96530 [details]
proposed patch

rediffed for strace-4.5.1, without coredump trace feature.

Comment 5 Dmitry V. Levin 2005-06-15 18:53:03 UTC
Created attachment 115496 [details]
strace-4.5.12-alt-keep_status.patch

Rediffed for new strace version.

Comment 6 Hans Ecke 2005-07-14 15:27:23 UTC
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 21:12:02 UTC
*** Bug 163613 has been marked as a duplicate of this bug. ***

Comment 8 Dmitry V. Levin 2005-08-08 17:26:46 UTC
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 23:14:28 UTC
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 22:19:46 UTC
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 23:25:40 UTC
Dedicated exit code 128 in "-k" mode is OK for me.

Comment 12 John Poelstra 2008-07-02 19:28:30 UTC
(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 12:14:06 UTC
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 16:07:11 UTC
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 22:29:39 UTC
(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 22:35:29 UTC
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 17:27:02 UTC
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 18:08:50 UTC
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 18:09:37 UTC
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 06:32:38 UTC
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 07:13:20 UTC
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-13 02:32:33 UTC
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-13 02:34:00 UTC
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.