]> git.corax.cc Git - toolbox/commitdiff
include/queue: queue_foreach: Return failure if callback fails
authorMatthias Kruk <matthias.kruk@miraclelinux.com>
Wed, 26 May 2021 04:31:15 +0000 (13:31 +0900)
committerMatthias Kruk <matthias.kruk@miraclelinux.com>
Wed, 26 May 2021 04:31:15 +0000 (13:31 +0900)
The queue_foreach() function always returns success, even if one of
the callbacks failed. This makes it hard to handle errors that occur
inside the callbacks.
This commit changes the function to return failure if a callback has
failed.

include/queue.sh

index b5bc03e7204511e52263030b22cc42924e5e385b..868d61be12b528d769f23c09b9c4962104e2302a 100644 (file)
@@ -500,9 +500,11 @@ queue_foreach() {
        local data
        local mutex
        local item
+       local err
 
        data=$(_queue_get_data "$name")
        mutex=$(_queue_get_mutex "$name")
+       err=0
 
        if ! mutex_lock "$mutex"; then
                return 1
@@ -511,6 +513,7 @@ queue_foreach() {
        if [ -f "$data" ]; then
                while read -r item; do
                        if ! "$func" "$item" "${args[@]}"; then
+                               err=1
                                break
                        fi
                done < "$data"
@@ -518,5 +521,5 @@ queue_foreach() {
 
        mutex_unlock "$mutex"
 
-       return 0
+       return "$err"
 }