Ticket was cloned from Red Hat Bugzilla (product Red Hat Enterprise Linux 6): Bug 1159124
Environment: ----------- # cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.5 (Santiago) Syntax: ----------- ns-newpwpolicy.pl [ -D rootdn ] [ -w password | -j filename ] [ -p port ] [ -h host ] -U userDN -S suffixDN [ -v ] [ -? ] Observation: ----------- The script itself does not exit properly even if the commands within it obviously have failed. Description of the problem: --------------------------- Even with a non-existent user, the script continues and exits with 0 as return code. This is incorrect, right? This script should exist with non-zero exit code (preferably same as what is reported by the directory server). # ./ns-newpwpolicy.pl -D cn=Manager -w Manager -U "cn=system_credential_access,cn=config" No such object (32) adding new entry "cn=nsPwPolicyContainer,cn=config" ldap_add: Already exists (68) Entry cn=nsPwPolicyContainer,cn=config already exists. Please ignore the error adding new entry "cn=cn\=nsPwPolicyEntry\,cn\=system_credential_access\,cn\=con fig,cn=nsPwPolicyContainer,cn=config" ldap_add: Already exists (68) Entry cn=cn\=nsPwPolicyEntry\,cn\=system_credential_access\,cn\=config,cn=nsPwP olicyContainer,cn=config already exists. Please ignore the error modifying entry "cn=system_credential_access,cn=config" ldap_modify: No such object (32) Error 8192 while modifing cn=system_credential_access,cn=config. Exiting. #echo $? 0
The problem here is that the Perl exit() function does not expect an exit code larger than 255. If the value is larger (such as 8192 above), it ends up being 0. We are ending up with these odd exit codes due to some missing shift operations. For example, we have correct and incorrect exit value processing in ns-newpwpolicy.pl:
open(FD,"| $ldapadd"); print FD @{$all[$i]}; close(FD); if ( $? != 0 ) { $retCode=$?>>8; if ( $retCode == 68 ) {
open(FD,"| $modifyCfg "); print(FD $modConfig); close(FD); $retcode = $?; if ( $retcode != 0 ) { print( STDERR "1 Error $retcode while modifing \"cn=config\". Exiting.\n" ); exit ($retcode); }
We need to shift the value from $? to the right by 8 to get the actual exit value of the command that is being run as desribed in the Perl system() function documentation:
http://perldoc.perl.org/functions/system.html
Do we need to do this for all of our .pl scripts?
Replying to [comment:5 rmeggins]:
Yeah, must of them do need to be adjusted. Attaching new patch...
attachment 0001-Ticket-47962-perl-scripts-not-returning-expected-err.patch
322d7d0..d8e7912 389-ds-base-1.2.11 -> 389-ds-base-1.2.11 commit d8e7912 Author: Mark Reynolds mreynolds@redhat.com Date: Wed Dec 17 11:56:42 2014 -0500
Metadata Update from @mreynolds: - Issue assigned to mreynolds - Issue set to the milestone: 1.2.11.33
389-ds-base is moving from Pagure to Github. This means that new issues and pull requests will be accepted only in 389-ds-base's github repository.
This issue has been cloned to Github and is available here: - https://github.com/389ds/389-ds-base/issues/1293
If you want to receive further updates on the issue, please navigate to the github issue and click on subscribe button.
subscribe
Thank you for understanding. We apologize for all inconvenience.
Metadata Update from @spichugi: - Issue close_status updated to: wontfix (was: Fixed)
Login to comment on this ticket.