Skip to contentSkip to conversation

resolve_btfids: Fix the --fatal_warnings exit status

PATCH In review Petr Pavlu 2 participants 2 messages Oct 8 BPF

lore
Share & tools
lore

Petr Pavlu

author
#0 lore raw

PATCH 1/1 resolve_btfids: Fix the --fatal_warnings exit status

The resolve_btfids --fatal_warnings option is intended to make the tool exit with a non-zero status if any warnings are reported. main() initializes err to -1 and uses 'goto out' to return this status when a sub-operation fails. If no error occurs,
'if (!(fatal_warnings && warnings)) err = 0;' modifies the final status depending on whether any warnings have been reported.

Commit 522397d05e7d ("resolve_btfids: Change in-place update with raw binary output") broke this logic by assigning the return values of newly added sub-operations to err. As a result, successful sub-operations overwrite the initial err value of -1 with 0, causing the tool to exit successfully even when --fatal_warnings is enabled and warnings have been reported.

Fix the issue by setting the final value of err unconditionally, so the code doesn't depend on its previous value.

Fixes 522397d05e7d ("resolve_btfids: Change in-place update with raw binary output")
---
 tools/bpf/resolve_btfids/main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/bpf/resolve_btfids/main.c +1 -2
index 37d7e7224207..2a93517ca9ec 100644
@@ -1842,8 +1842,7 @@ int main(int argc, const char **argv)
 			goto out;
 	}
 
-	if (!(fatal_warnings && warnings))
-		err = 0;
+	err = fatal_warnings && warnings ? -1 : 0;
 out:
 	btf__free(obj.base_btf);
 	btf__free(obj.btf);

---
base-commit: a90ee4305c4a5df72c11b31dacfdc76e00fcf78a
change-id: 20261008-resolve_btfids-warnings-a356edc7a5c6

reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 14 lines · Petr Pavlu

The resolve_btfids --fatal_warnings option is intended to make the tool exit with a non-zero status if any warnings are reported. main() initializes err to -1 and uses 'goto out' to return this status when a sub-operation fails. If no error occurs,
'if (!(fatal_warnings && warnings)) err = 0;' modifies the final status depending on whether any warnings have been reported.

Commit 522397d05e7d ("resolve_btfids: Change in-place update with raw binary output") broke this logic by assigning the return values of newly added sub-operations to err. As a result, successful sub-operations overwrite the initial err value of -1 with 0, causing the tool to exit successfully even when --fatal_warnings is enabled and warnings have been reported.

Quoted 5 lines

Fix the issue by setting the final value of err unconditionally, so the code doesn't depend on its previous value.

Fixes 522397d05e7d ("resolve_btfids: Change in-place update with raw binary output")

Thanks!

Quoted 22 lines
---
 tools/bpf/resolve_btfids/main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/bpf/resolve_btfids/main.c +1 -3
index 37d7e7224207..2a93517ca9ec 100644
@@ -1842,8 +1842,7 @@ int main(int argc, const char **argv)
 			goto out;
 	}
 
-	if (!(fatal_warnings && warnings))
-		err = 0;
+	err = fatal_warnings && warnings ? -1 : 0;
 out:
 	btf__free(obj.base_btf);
 	btf__free(obj.btf);
 
---

base-commit: a90ee4305c4a5df72c11b31dacfdc76e00fcf78a
change-id: 20261008-resolve_btfids-warnings-a356edc7a5c6