Bug 229346 - freebsd-update install return code changed
Summary: freebsd-update install return code changed
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 11.2-RELEASE
Hardware: amd64 Any
: --- Affects Many People
Assignee: Pietro Cerutti
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-26 15:31 UTC by Mike Cole
Modified: 2019-09-26 20:56 UTC (History)
11 users (show)

See Also:


Attachments
fix ezjail getting stuck in endless loop during update (401 bytes, patch)
2019-01-22 07:24 UTC, topical
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Cole 2018-06-26 15:31:11 UTC
In 11.1 if you run:

freebsd-update install

and have no updates available you get a return text of:

No updates are available to install.
Run '/usr/sbin/freebsd-update fetch' first.

and a return code of:

echo $?
1

In 11.2 this returns the same text, but the return code is now:

echo $?
0

This breaks many scripts and jail managers because during an upgrade they loop to see how many times freebsd-update install needs to run (some times multiple).  This will affect most jail users.
Comment 1 Mike Cole 2018-06-26 15:48:15 UTC
As an example, here is iocell's upgrade code:

https://github.com/bartekrutkowski/iocell/blob/master/lib/ioc-upgrade

Line 323

                while [ $? -eq 0 ] ; do
                    chroot ${_mountpoint}/root \
                        env UNAME_r="${_oldrelease}" env PAGER="/bin/cat" \
                        freebsd-update -r ${_release} install
                done
Comment 2 topical 2018-07-15 21:31:17 UTC
This als breaks ezjail, being the recommended jail manager according the FreeBSD handbook.

After successful update, ezjail-admin get stuck in an endless loop:

src component not installed, skipped
No updates are available to install.
Run '/usr/sbin/freebsd-update fetch' first.
src component not installed, skipped
No updates are available to install.
Run '/usr/sbin/freebsd-update fetch' first.
src component not installed, skipped
No updates are available to install.
Run '/usr/sbin/freebsd-update fetch' first.

I don't see a workaround but patching freebsd-update, which isn't really reasonable.

Please, change the return code to anything else but zero!
Comment 3 ilyushkeane 2018-08-29 15:36:02 UTC
@topical as for ezjail the loop is:

while [ $? -eq 0 ]; do
  env UNAME_r="${ezjail_osversion_source}" PAGER=/bin/cat freebsd-update -b ${DESTDIR} -r ${ezjail_osversion_target} install
done

which (I assume) means, that ezjail-admin stucks in loop AFTER `freebsd-update install` run at least once. Check basejail version -- in my case it's updated.
Comment 4 topical 2018-08-29 20:56:41 UTC
@ilyushkeane

as written, the jail is indeed updated, but ezjail is stuck in an endless loop. This is why we need a proper exit code of freebsd-update.
Comment 5 Mark Johnston freebsd_committer freebsd_triage 2018-08-29 22:38:04 UTC
Looks like the behaviour changed in r324441.
Comment 6 topical 2019-01-22 07:23:25 UTC
I upgraded my systems to FreeBSD 12.0 and ezjail still gets stuck in an endless loop unless I apply the patch.

Could someone please apply it?
Comment 7 topical 2019-01-22 07:24:47 UTC
Created attachment 201320 [details]
fix ezjail getting stuck in endless loop during update
Comment 8 Andres Montalban 2019-03-11 19:32:09 UTC
This is a PITA when you have to upgrade multiple jails hosts, I had to apply the patch in order to continue with our upgrades.

This should be prioritized as it's affecting multiple users.
Comment 9 commit-hook freebsd_committer freebsd_triage 2019-03-12 08:32:05 UTC
A commit references this bug:

Author: gahr
Date: Tue Mar 12 08:31:44 UTC 2019
New revision: 345055
URL: https://svnweb.freebsd.org/changeset/base/345055

Log:
  freebsd-update: restore old exit code when no updates are available locally

  This unbreaks ezjail and iocell, which get into an endless loop trying to
  figure out how many times "freebsd-update install" needs to be called.

  PR:		229346
  Submitted by:	Mike Cole <mcole36@gmail.com>
  Approved by:	bapt
  MFC after:	1 week

Changes:
  head/usr.sbin/freebsd-update/freebsd-update.sh
Comment 10 commit-hook freebsd_committer freebsd_triage 2019-03-20 10:10:22 UTC
A commit references this bug:

Author: gahr
Date: Wed Mar 20 10:09:38 UTC 2019
New revision: 345320
URL: https://svnweb.freebsd.org/changeset/base/345320

Log:
  MFC r34505: freebsd-update: restore old exit code when no updates are available
  locally

  This unbreaks ezjail and iocell, which get into an endless loop trying to
  figure out how many times "freebsd-update install" needs to be called.

  PR:		229346
  Submitted by:	Mike Cole <mcole36 at gmail.com>
  Approved by:	bapt

Changes:
_U  stable/12/
  stable/12/usr.sbin/freebsd-update/freebsd-update.sh
Comment 11 commit-hook freebsd_committer freebsd_triage 2019-03-20 10:21:37 UTC
A commit references this bug:

Author: gahr
Date: Wed Mar 20 10:20:48 UTC 2019
New revision: 345322
URL: https://svnweb.freebsd.org/changeset/base/345322

Log:
  MFC r34505: freebsd-update: restore old exit code when no updates are available
  locally

  This unbreaks ezjail and iocell, which get into an endless loop trying to
  figure out how many times "freebsd-update install" needs to be called.

  PR:		229346
  Submitted by:	Mike Cole <mcole36 at gmail.com>
  Approved by:	bapt

Changes:
_U  stable/11/
  stable/11/usr.sbin/freebsd-update/freebsd-update.sh
Comment 12 commit-hook freebsd_committer freebsd_triage 2019-09-24 20:50:15 UTC
A commit references this bug:

Author: grembo
Date: Tue Sep 24 20:49:33 UTC 2019
New revision: 352662
URL: https://svnweb.freebsd.org/changeset/base/352662

Log:
  freebsd-update: Add `updatesready' and `showconfig' commands

  `freebsd-update updatesready' can be used to check if there are any pending
  fetched updates that can be installed.

  `freebsd-update showconfig' writes freebsd-update's configuration to
  stdout.

  This also changes the exit code of `freebsd-update install' to 2 in case
  there are no updates pending to be installed and there wasn't a fetch phase
  in the same invocation. This allows scripts to tell apart these error
  conditions without breaking existing jail managers.

  See freebsd-update(8) for details.

  PR:		240757, 240177, 229346
  Reviewed by:	manpages (bcr), sectam (emaste), yuripv
  Differential Revision:	https://reviews.freebsd.org/D21473

Changes:
  head/usr.sbin/freebsd-update/freebsd-update.8
  head/usr.sbin/freebsd-update/freebsd-update.sh
Comment 13 commit-hook freebsd_committer freebsd_triage 2019-09-26 16:33:32 UTC
A commit references this bug:

Author: grembo
Date: Thu Sep 26 16:33:21 UTC 2019
New revision: 352758
URL: https://svnweb.freebsd.org/changeset/base/352758

Log:
  MFC r352513, r352514, r352662:

  As suggested by koobs, MFC recent freebsd-update changes to
  have a consistent user experience on all supported
  versions.

  r352513:
  freebsd-update.8: appease igor

  igor follows American style guides in the belief that abbreviations i.e.
  and e.g. are always followed by a comma.  Make that change now so that
  future updates to freebsd-update.8 do not complain about this.

  r352514:
  freebsd-update: make usage output consistent

  Drop trailing . which appeared only on description of IDS.

  r352662:
  freebsd-update: Add `updatesready' and `showconfig' commands

  `freebsd-update updatesready' can be used to check if there are any pending
  fetched updates that can be installed.

  `freebsd-update showconfig' writes freebsd-update's configuration to
  stdout.

  This also changes the exit code of `freebsd-update install' to 2 in case
  there are no updates pending to be installed and there wasn't a fetch phase
  in the same invocation. This allows scripts to tell apart these error
  conditions without breaking existing jail managers.

  PR:		240757, 240177, 229346
  Reviewed by:	manpages (bcr), secteam (emaste), yuripv
  Differential Revision:	https://reviews.freebsd.org/D21473

Changes:
  stable/11/usr.sbin/freebsd-update/freebsd-update.8
  stable/11/usr.sbin/freebsd-update/freebsd-update.sh
Comment 14 commit-hook freebsd_committer freebsd_triage 2019-09-26 16:35:36 UTC
A commit references this bug:

Author: grembo
Date: Thu Sep 26 16:34:44 UTC 2019
New revision: 352759
URL: https://svnweb.freebsd.org/changeset/base/352759

Log:
  MFC r352513, r352514, r352662:

  As suggested by koobs, MFC recent freebsd-update changes to
  have a consistent user experience on all supported
  versions.

  r352513:
  freebsd-update.8: appease igor

  igor follows American style guides in the belief that abbreviations i.e.
  and e.g. are always followed by a comma.  Make that change now so that
  future updates to freebsd-update.8 do not complain about this.

  r352514:
  freebsd-update: make usage output consistent

  Drop trailing . which appeared only on description of IDS.

  r352662:
  freebsd-update: Add `updatesready' and `showconfig' commands

  `freebsd-update updatesready' can be used to check if there are any pending
  fetched updates that can be installed.

  `freebsd-update showconfig' writes freebsd-update's configuration to
  stdout.

  This also changes the exit code of `freebsd-update install' to 2 in case
  there are no updates pending to be installed and there wasn't a fetch phase
  in the same invocation. This allows scripts to tell apart these error
  conditions without breaking existing jail managers.

  PR:		240757, 240177, 229346
  Reviewed by:	manpages (bcr), secteam (emaste), yuripv
  Differential Revision:	https://reviews.freebsd.org/D21473

Changes:
  stable/12/usr.sbin/freebsd-update/freebsd-update.8
  stable/12/usr.sbin/freebsd-update/freebsd-update.sh
Comment 15 commit-hook freebsd_committer freebsd_triage 2019-09-26 20:56:12 UTC
A commit references this bug:

Author: grembo
Date: Thu Sep 26 20:56:08 UTC 2019
New revision: 352774
URL: https://svnweb.freebsd.org/changeset/base/352774

Log:
  MF stable/12 r352759,r352771

  Approved by:	re (gjb)

  r352759:
  freebsd-update.8: Style fixes, document new features.
  freebsd-update:   Make usage output consistent.
  freebsd-update:   Add `updatesready' and `showconfig' commands
  freebsd-update:   Change exit code of `freebsd-update install' to 2
                    in case there are no pending updates and there wasn't
                    a fetch phase in the same invocation.

  r352771:
  Add mergeinfo missing in r352759

  PR:		240757, 240177, 229346
  Reviewed by:	manpages (bcr), secteam (emaste), yuripv
  Differential Revision:	https://reviews.freebsd.org/D21473

Changes:
_U  releng/12.1/
  releng/12.1/usr.sbin/freebsd-update/freebsd-update.8
  releng/12.1/usr.sbin/freebsd-update/freebsd-update.sh