Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 14 Jul 2024 13:18:03 +0000
From:      bugzilla-noreply@freebsd.org
To:        pkg@FreeBSD.org
Subject:   maintainer-feedback requested: [Bug 280275] ports-mgmt/pkg: Wrong exit code in periodic script 490.status-pkg-changes
Message-ID:  <bug-280275-32340-zJS1bY7NSU@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-280275-32340@https.bugs.freebsd.org/bugzilla/>
References:  <bug-280275-32340@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
Bugzilla Automation <bugzilla@FreeBSD.org> has asked freebsd-pkg (Nobody)
<pkg@FreeBSD.org> for maintainer-feedback:
Bug 280275: ports-mgmt/pkg: Wrong exit code in periodic script
490.status-pkg-changes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D280275



--- Description ---
I'm using the following periodic configuration, which should notify me when
packages have changed:

daily_show_success=3D"NO"
daily_status_pkg_changes_enable=3D"YES"

The script /usr/local/etc/periodic/daily/490.status-pkg-changes is run, but=
 due
to a bug in the list_pkgs function, the return code is not set correctly.

Here's the function:

11	list_pkgs() {
12	    local pkgargs=3D"$1"
13	    local bak_file=3D"$2"
14	    local rc
15
16	    bak=3D/var/backups
17
18	    [ -r $bak/$bak_file ] && mv -f $bak/$bak_file $bak/${bak_file}2
19	    ${pkgcmd} ${pkgargs} info > $bak/$bak_file
20	    rc=3D$?
21
22	    cmp -sz $bak/$bak_file $bak/${bak_file}2
23	    if [ $? -eq 1 ]; then
24		diff -U 0 $bak/${bak_file}2 $bak/${bak_file} | \
25		    grep '^[-+][^-+]' | sort -k 1.2
26	    fi
27
28	    return $rc
29	}


On line 19, the return code, $rc, is set to the exit code of "pkg info", wh=
ich
is usually 0 (success), whether packages have changed or not.

The comparison on line 22 however doesn't change $rc, even though it should=
, to
signal that packages have changed.

Otherwise, the overall exit code of the periodic script is 0 and won't get
picked up when $daily_show_success is disabled.

Additionally, although not responsible for the specific problem: In
list_pkgs_all() on line 51 and in each following loop, $rc is explicitly se=
t to
1 after invocation of list_pkgs(). $rc being overwritten there multiple tim=
es
is certainly not correct.

Of course, all of this builds on the assumption that 1) no package changes =
=3D
success 2) package changes =3D info.

So, to fix both of these issues, what about this diff? I also attached it w=
ith
hopefully correct formatting.

Kind regards,
Andre

--- /usr/local/etc/periodic/daily/490.status-pkg-changes	2024-05-23
03:05:49.000000000 +0200
+++ 490.status-pkg-changes	2024-07-14 14:50:22.429206000 +0200
@@ -20,7 +20,8 @@
     rc=3D$?

     cmp -sz $bak/$bak_file $bak/${bak_file}2
-    if [ $? -eq 1 ]; then
+    rc=3D$?
+    if [ $rc -eq 1 ]; then
	diff -U 0 $bak/${bak_file}2 $bak/${bak_file} | \
	    grep '^[-+][^-+]' | sort -k 1.2
     fi
@@ -32,6 +33,7 @@
     local rc
     local jails
     local bak_file
+    local list_rc
     local rc=3D0

     : ${daily_status_pkg_changes_chroots=3D$pkg_chroots}
@@ -48,7 +50,8 @@
     fi

     list_pkgs '' pkg.bak
-    [ $? -ne 0 ] && rc=3D1
+    list_rc=3D$?
+    [ $list_rc -gt $rc ] && rc=3D$list_rc

     for c in $daily_status_pkg_changes_chroots ; do
	echo
@@ -56,7 +59,8 @@
	bak_file=3D"pkg.chroot-$(echo $c | tr -C a-zA-Z0-9.- _).bak"

	list_pkgs "-c $c" $bak_file
-	[ $? -ne 0 ] && rc=3D1
+	list_rc=3D$?
+	[ $list_rc -gt $rc ] && rc=3D$list_rc
     done

     case $daily_status_pkg_changes_jails in
@@ -77,7 +81,8 @@
	bak_file=3D"pkg.jail-$(echo $j | tr -C a-zA-Z0-9.- _).bak"

	list_pkgs "-j $j" $bak_file
-	[ $? -ne 0 ] && rc=3D1
+	list_rc=3D$?
+	[ $list_rc -gt $rc ] && rc=3D$list_rc
     done

     return $rc



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-280275-32340-zJS1bY7NSU>