From 6af105391cea3c6501ede02ffe937af26b544ba8 Mon Sep 17 00:00:00 2001 From: Hayato Kiwata Date: Wed, 25 Nov 2026 22:38:07 +0900 Subject: pesto: Drop exit_status, use status to select the exit code Commit 885c39e8b999 ("conf, pesto: Notify client of the result of rule updates") added an exit_status variable to exit with a non-zero status if the server reports a failure. However, the status read from the server already tells us whether the update failed. Drop exit_status, broaden the scope of status, and select the exit code from it when we call exit(). Initialize status to PESTO_STATUS_OK, since it is not read from the server when pesto only shows the current rules or the server uses a protocol version older than 3. Link: https://archives.passt.top/passt-dev/20261120235844.75da1afa@elisabeth/ Suggested-by: Stefano Brivio Signed-off-by: Hayato Kiwata Signed-off-by: Stefano Brivio --- pesto.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pesto.c b/pesto.c index 03edc29..fe5a536 100644 --- a/pesto.c +++ b/pesto.c @@ -318,7 +318,7 @@ int main(int argc, char **argv) struct sockaddr_un a = { AF_UNIX, "" }; struct configuration conf = { 0 }; bool update = false, show = false; - int exit_status = EXIT_SUCCESS; + uint8_t status = PESTO_STATUS_OK; struct pesto_hello hello; struct sock_fprog prog; int optname, ret, s; @@ -515,8 +515,6 @@ int main(int argc, char **argv) send_conf(s, &conf); if (s_version >= PESTO_VERSION_STATUS) { - uint8_t status; - if (read_u8(s, &status) < 0) die_perror("Couldn't read configuration status"); @@ -524,16 +522,13 @@ int main(int argc, char **argv) case PESTO_STATUS_OK: break; case PESTO_STATUS_ROLLBACK: - exit_status = EXIT_FAILURE; warn("Failed to apply new rules, old rules restored"); break; case PESTO_STATUS_FAILED: - exit_status = EXIT_FAILURE; warn( "Failed to apply new rules, couldn't restore old ones"); break; default: - exit_status = EXIT_FAILURE; warn("Unknown configuration status %"PRIu8, status); } } @@ -542,5 +537,5 @@ noupdate: if (shutdown(s, SHUT_RDWR) < 0 || close(s) < 0) die_perror("Error shutting down control socket"); - exit(exit_status); + exit(status == PESTO_STATUS_OK ? EXIT_SUCCESS : EXIT_FAILURE); } -- cgit v1.2.3