Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1073202

Summary: [s390x] program exit code is 92, even use return 0 at tail if main()
Product: Red Hat Enterprise Linux 7 Reporter: JianHong Yin <jiyin>
Component: glibcAssignee: Carlos O'Donell <codonell>
Status: CLOSED NOTABUG QA Contact: qe-baseos-tools-bugs
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.0CC: ashankar, fweimer, pfrankli, spoyarek
Target Milestone: rcKeywords: Reopened
Target Release: ---   
Hardware: s390x   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-03-13 06:15:37 UTC Type: Bug
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
crash3.c
none
worksFine.c none

Description JianHong Yin 2014-03-06 02:03:34 UTC
Created attachment 871178 [details]
crash3.c

Description of problem:
[s390x] program exit code is 92, even use return 0 at tail if main()

Version-Release number of selected component (if applicable):
------------------------------------------------
Time & CURDIR : [2014-03-05 04:36:07 @/mnt/tests/kernel/filesystems/nfs/regression/bz218777]
Case Name     : /kernel/filesystems/nfs/regression/bz218777
$HOSTNAME     : ibm-z10-56.rhts.eng.bos.redhat.com
Distro Info   : RedHatEnterpriseServer 7.0 : RHEL-7.0-20140226.0
NVR & host    : Linux ibm-z10-56.rhts.eng.bos.redhat.com 3.10.0-97.el7.s390x #1 SMP Tue Feb 25 15:22:22 EST 2014 s390x s390x s390x GNU/Linux
cmdline       :
	rd.dasd=0.0.0121 vconsole.font=latarcyrheb-sun16 rd.lvm.lv=rhel_ibm-z10-56/boot rd.lvm.lv=rhel_ibm-z10-56/swap crashkernel=auto  vconsole.keymap=us rd.dasd=0.0.0122 rd.dasd=0.0.0123 rd.dasd=0.0.0120 rd.lvm.lv=rhel_ibm-z10-56/root root=/dev/mapper/rhel_ibm--z10--56-root LANG=en_US.UTF-8 BOOT_IMAGE=0
Package Info  :
	libnfsidmap-0.25-9.el7.s390x
	package libsss_idmap is not installed
	nfs-utils-1.2.9-4.el7.s390x
------------------------------------------------

How reproducible:
always

Steps to Reproduce:
1. compile the .c file attached
2. ./a.out
3. echo $?

Actual results:
# echo $?
92

Expected results:
# echo $?
0

Additional info:
test in other arch, and test in RHEL6.5 works fine.

Comment 1 JianHong Yin 2014-03-06 02:06:52 UTC
Created attachment 871179 [details]
worksFine.c

Comment 2 JianHong Yin 2014-03-06 02:08:29 UTC
(In reply to Yin.JianHong from comment #1)
> Created attachment 871179 [details]
> worksFine.c

use the worksFine.c, it works fine; I'm confused,,

Comment 4 Carlos O'Donell 2014-03-08 02:03:05 UTC
(In reply to Yin.JianHong from comment #0)
> How reproducible:
> always
> 
> Steps to Reproduce:
> 1. compile the .c file attached
> 2. ./a.out
> 3. echo $?
> 
> Actual results:
> # echo $?
> 92
> 
> Expected results:
> # echo $?
> 0

Both of your programs may invoke undefined behaviour.

It is valid C++ to avoid the return in main, and in that case the return defaults to 0. This doesn't seem to be what you are doing, you need to compile with g++ to have this behaviour.

It is valid C99 to avoid the return in main, defaulting in that case to returning 0 e.g. use `-std=c99'. However, the RHEL compiler doesn't default to C99, you'd need to ask it.

In general failing to call exit or use a return statement from a non-void main results in undefined behaviour, you have violated ISO C90 and any behaviour can be expected from the return of main (your programs exit code).

Sometimes putting a call to a function that returns 0 at the end of main can result in the return register being carried unmodified to the exit of main and serving as the exit code. That is extremely bad practice, undefined behaviour, and as you can see the results are unpredictable.

The correct solution is use `return 0;' at the end of main or `return close(fd)'.

So you have several options:
* Fix the code (adding -Wall warns of the problems)
* Compile as C++.
* Compile as ISO C99.

Comment 5 JianHong Yin 2014-03-08 02:34:01 UTC
(In reply to Carlos O'Donell from comment #4)
> (In reply to Yin.JianHong from comment #0)
> > How reproducible:
> > always
> > 
> > Steps to Reproduce:
> > 1. compile the .c file attached
> > 2. ./a.out
> > 3. echo $?
> > 
> > Actual results:
> > # echo $?
> > 92
> > 
> > Expected results:
> > # echo $?
> > 0
> 
> Both of your programs may invoke undefined behaviour.
> 
> It is valid C++ to avoid the return in main, and in that case the return
> defaults to 0. This doesn't seem to be what you are doing, you need to
> compile with g++ to have this behaviour.
> 
> It is valid C99 to avoid the return in main, defaulting in that case to
> returning 0 e.g. use `-std=c99'. However, the RHEL compiler doesn't default
> to C99, you'd need to ask it.
> 
> In general failing to call exit or use a return statement from a non-void
> main results in undefined behaviour, you have violated ISO C90 and any
> behaviour can be expected from the return of main (your programs exit code).
> 
> Sometimes putting a call to a function that returns 0 at the end of main can
> result in the return register being carried unmodified to the exit of main
> and serving as the exit code. That is extremely bad practice, undefined
> behaviour, and as you can see the results are unpredictable.
> 
> The correct solution is use `return 0;' at the end of main or `return
> close(fd)'.
> 
> So you have several options:
> * Fix the code (adding -Wall warns of the problems)
> * Compile as C++.
> * Compile as ISO C99.

find a quarrel in a straw
I just curious: WHY different result between s390x and other arch.
”Platform-independent“ it can meet?

if feel no need, please close again with WONTFIX or CANTFIX;

Comment 6 Carlos O'Donell 2014-03-08 03:00:11 UTC
(In reply to Yin.JianHong from comment #5)
> find a quarrel in a straw
> I just curious: WHY different result between s390x and other arch.
> ”Platform-independent“ it can meet?
> 
> if feel no need, please close again with WONTFIX or CANTFIX;

The instruction scheduling is all based on the backend s390x support, and each backend is different and schedules differently, and thus you might not have the register with a zero return (result of close) result being preserved as the function exits. The function epilogue might touch it also for use as a temporary to return the stack. You have no control over this unless you use return or exit or a standard that guarantees it. It is very very platform *dependent*.

Cheers,
Carlos.

Comment 7 JianHong Yin 2014-03-08 05:21:27 UTC
Additional info: the same test in RHEL-6.5 it return 0;

so maybe, this is not a high priority problem,
but I think the developer should be clear why the different happen...

Comment 8 Carlos O'Donell 2014-03-13 06:15:37 UTC
There is nothing we can fix here. If someone has a concrete suggestion please file a new issue with the suggestion.