develooper Front page | perl.perl5.porters | Postings from September 2003

[perl #23779] $? and negative exit codes

Thread Next
From:
Tels
Date:
September 10, 2003 20:36
Subject:
[perl #23779] $? and negative exit codes
Message ID:
rt-23779-64475.8.16332483179352@rt.perl.org
# New Ticket Created by  Tels 
# Please include the string:  [perl #23779]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=23779 >


-----BEGIN PGP SIGNED MESSAGE-----

This is a bug report for perl from perl_dummy@bloodgate.com,
generated with the help of perlbug 1.34 running under perl v5.8.0.


- -----------------------------------------------------------------
[Please enter your report here]

The docs for perldoc -f system says:

  You can check all the failure possibilities by inspecting $? like this:

	$exit_value  = $? >> 8;
	$signal_num  = $? & 127;
	$dumped_core = $? & 128;

However, $exit_value does not represent the true exit value with negative
exit values:

	te@null:~> cat exit.pl
	#!/usr/bin/perl -w
	
	exit shift;
	te@null:~> perl -le 'system "perl exit.pl 0"; $exit_code = $? >> 8; print 
"$exit_code"'
	0
	te@null:~> perl -le 'system "perl exit.pl 1"; $exit_code = $? >> 8; print 
"$exit_code"'
	1
	te@null:~> perl -le 'system "perl exit.pl -1"; $exit_code = $? >> 8; print 
"$exit_code"'
	255

I thought problem is with '>>' and negative values, but:

te@null:~> perl -le 'system "perl exit.pl -1"; $exit_code = int($? / 256); 
print "$exit_code $?"'
255 65280

Maybe this is simple a unsigned vs. signed issue? On a different system were
I noticed this first I would get the decimal equivalent of "0xFFFFFFFF >> 1",
e.g. 2147483647 for $?.

Now, compare this to:

	te@null:~> perl -le 'system "exit.pl -1"; $exit_code = int($? / 256); print 
"$exit_code $?"'
	0 -1

[Please do not change anything below this line]
- -----------------------------------------------------------------
- ---
Flags:
    category=docs
    severity=medium
- ---
This perlbug was built using Perl v5.8.0 - Thu Mar 13 22:21:38 UTC 2003
It is being executed now by  Perl v5.8.0 - Thu Mar 13 22:14:08 UTC 2003.

Site configuration information for perl v5.8.0:

Configured by root at Thu Mar 13 22:14:08 UTC 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.20, archname=i586-linux-thread-multi
    uname='linux d20 2.4.20 #1 smp thu oct 10 18:10:26 utc 2002 i686 unknown 
unknown gnulinux '
    config_args='-ds -e -Dprefix=/usr -Dusethreads -Di_db -Di_dbm -Di_ndbm 
- -Di_gdbm -Duseshrplib=true'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define 
usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing 
- -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O3 --pipe',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing'
    ccversion='', gccversion='3.3 20030226 (prerelease) (SuSE Linux)', 
gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =''
    libpth=/lib /usr/lib /usr/local/lib
    libs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic 
- -Wl,-rpath,/usr/lib/perl5/5.8.0/i586-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared'

Locally applied patches:
    

- ---
@INC for perl v5.8.0:
    /usr/lib/perl5/5.8.0/i586-linux-thread-multi
    /usr/lib/perl5/5.8.0
    /usr/lib/perl5/site_perl/5.8.0/i586-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    .

- ---
Environment for perl v5.8.0:
    HOME=/home/te
    LANG=en_US
    LANGUAGE (unset)
    LC_COLLATE=POSIX
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    
PATH=/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/java/bin:/opt/gnome/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

- -- 
 Signed on Wed Sep 10 23:04:11 2003 with key 0x93B84C15.
 PGP key on http://bloodgate.com/tels.asc or per email.

 "Wo die Schononen schön wohnen."

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)
Comment: When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl.

iQEVAwUBP1+R4XcLPEOTuEwVAQGM/wf9G/KKXwIdwZc97E+cfkWvKkTYIz+8dTrX
oyx9JMIKFEz429PZsPTqXbp5vDgq3Fce/5HVWvBjm1z1NpKInyRhugBUB1hOylQT
B19Ka/a3lEsuELuUu74JwhFZqYipz/ud/kvAgsqcVSZQIjDc/Zir8bmIWfgkK3PL
QUt5f+1TjSPohfwVz9OLW3Xen+1/qxs7PTnEwY35Fa5S3J29d9Sh672OVXP2R7GJ
jQ1KEhnNWgCy3I+cF8vZ8j3gMKfZD0Nk/pg+gyrkZaQCN2y0AnLQT2ja8QNPVtwR
i5a/KxqK7jo+05tzZeCemDRvTeVIOSZmBCtvuxuLxwYOEqSTh9a9QQ==
=l90s
-----END PGP SIGNATURE-----



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About