changed exit code for 'dc' in Ubuntu Bionic

Bug #1788681 reported by Wladimir Mutel
18
This bug affects 3 people
Affects Status Importance Assigned to Milestone
bc (Ubuntu)
Confirmed
Undecided
Unassigned
dphys-swapfile (Ubuntu)
Fix Released
Undecided
Axel Beckert

Bug Description

in Ubuntu Xenial :
$ lsb_release -rdc ; echo 1 1 + p q | dc ; echo $?
Description: Ubuntu 16.04.4 LTS
Release: 16.04
Codename: xenial
2
0

in Ubuntu Bionic :
$ lsb_release -rdc ; echo 1 1 + p q | dc ; echo $?
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic
2
1

This change causes some scripts using 'dc' to fail, most importantly, 'dphys-swapfile' which for some ironic reason uses 'dc' instead of 'echo $((...))' for its calculations.

Revision history for this message
Wladimir Mutel (mwg) wrote :

same is reproduced when you run 'dc', enter into it some expression ending with 'p q', and examining its exit code with 'echo $?' afterwards

Revision history for this message
Axel Beckert (xtaran) wrote : Re: [Bug 1788681] [NEW] changed exit code for 'dc' in Ubuntu Bionic

Hi Wladimir,

Wladimir Mutel wrote:
> in Ubuntu Xenial :
> $ lsb_release -rdc ; echo 1 1 + p q | dc ; echo $?
> Description: Ubuntu 16.04.4 LTS
> Release: 16.04
> Codename: xenial
> 2
> 0
>
> in Ubuntu Bionic :
> $ lsb_release -rdc ; echo 1 1 + p q | dc ; echo $?
> Description: Ubuntu 18.04.1 LTS
> Release: 18.04
> Codename: bionic
> 2
> 1
>
> This change causes some scripts using 'dc' to fail, most importantly,
> 'dphys-swapfile'

Thanks for that bug report. This might be the cause for
https://bugs.debian.org/906767 which I'm currently trying to fix.

> which for some ironic reason uses 'dc' instead of 'echo
> $((...))' for its calculations.

That's upstream's decision. And since I know that upstream also runs
rather old Unices, I assume it's because $(( ... )) might not be
available in all shells. According to
https://en.wikipedia.org/wiki/Comparison_of_command_shells#cite_ref-57
it should though be available in all relevant shells since 1992.

The relevant change in dc seems to be from 1.3 to 1.4:

    Detects and reports on any output errors; exits non-success.

The fix seems simple: Drop the "q":

~ → echo 1 1 + p q | dc ; echo $?
2
1
~ → echo 1 1 + p | dc ; echo $?
2
0

Will have to check if that's indeed the cause for
https://bugs.debian.org/906767, but will do a new upload to Debian
Unstable in either case.

Someone else will need to take care of a regression fix for bionic
though.

  Regards, Axel
--
 ,''`. | Axel Beckert <email address hidden>, https://people.debian.org/~abe/
: :' : | Debian Developer, ftp.ch.debian.org Admin
`. `' | 4096R: 2517 B724 C5F6 CA99 5329 6E61 2FF9 CD59 6126 16B5
  `- | 1024D: F067 EA27 26B9 C3FC 1486 202E C09E 1D89 9593 0EDE

tags: added: bionic cosmic
Changed in dphys-swapfile (Ubuntu):
status: New → Confirmed
Axel Beckert (xtaran)
Changed in dphys-swapfile (Ubuntu):
assignee: nobody → Axel Beckert (xtaran)
status: Confirmed → In Progress
Axel Beckert (xtaran)
Changed in dphys-swapfile (Ubuntu):
status: In Progress → Fix Committed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package dphys-swapfile - 20100506-5

---------------
dphys-swapfile (20100506-5) unstable; urgency=high

  * Add patch to fix the setup subcommand exiting prematurely with more
    recent dc versions. (Closes: #906767, LP: #1788681) Also update
    check-diskspace-first.patch which uses the same syntax. Thanks to
    eHenry Berg for the initial bug report, Davide Prina for additional
    debugging help, and Wladimir Mutel for finding the actual culprit.

 -- Axel Beckert <email address hidden> Thu, 23 Aug 2018 23:29:41 +0200

Changed in dphys-swapfile (Ubuntu):
status: Fix Committed → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in bc (Ubuntu):
status: New → Confirmed
Revision history for this message
Paul Graydon (twirrim) wrote :

Fix has only been released for Cosmic. Given the package is basically non-functional on Bionic, is there a plan to backport the fix? There doesn't seem much point in keeping it in the repository otherwise.

Revision history for this message
Wladimir Mutel (mwg) wrote (last edit ):

4 years passed, no movements detected in Bionic ...

Revision history for this message
DanglingPointer (ferncasado) wrote :

Holy necromancy! Is this still a bug? Is this affecting latest LTS 22.04?

Revision history for this message
DanglingPointer (ferncasado) wrote :

$ lsb_release -rdc ; echo 1 1 + p q | dc ; echo $?
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy
2
1

tags: added: jammy
Revision history for this message
Wladimir Mutel (mwg) wrote :

The bug is not in bc/dc (which documented their change of behavior).
It is in dphys-swapfile script which used to exit 'dc' by 'q' command.
The proper fix, in my view, would still be to use arithmetic substitution $((...)) provided by most modern shells, and make dphys-swapfile independent from 'dc' at all.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.