Fix help/version argument exit codes#2174
Conversation
Updated all daemons and utilities to return exit code 0 when help (-h) or version (-V) flags are used, and exit code 1 for invalid arguments. This standardizes the behavior across the codebase. Signed-off-by: Scott R. Shinn <scott@atomicorp.com>
There was a problem hiding this comment.
Pull request overview
Standardizes CLI exit codes across OSSEC daemons/utilities so -h (help) and -V (version) exit successfully (0), while invalid arguments exit with error (1), addressing issue #1965.
Changes:
- Updated many
help*()/helpmsg()functions to accept an explicitstatusandexit(status). - Adjusted
-hcall sites to pass0and invalid-argument paths to pass1. - Changed
print_version()to exit with code0.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/util/verify-agent-conf.c | Help function now exits with explicit status; -h => 0, invalid args => 1. |
| src/util/syscheck_update.c | Help exit codes standardized for -h and invalid usage. |
| src/util/syscheck_control.c | Help exit codes standardized for -h and invalid getopt paths. |
| src/util/rootcheck_control.c | Help exit codes standardized for -h and invalid getopt paths. |
| src/util/ossec-regex.c | Help exit codes standardized (-h => 0; bad args => 1). |
| src/util/list_agents.c | Help exit codes standardized (-h => 0; bad args => 1). |
| src/util/clear_stats.c | Help exit codes standardized (-h => 0; bad args => 1). |
| src/util/agent_control.c | Help exit codes standardized; minor CSV/JSON option handling formatting touched. |
| src/syscheckd/syscheck.c | Daemon help now exits with explicit status (-h => 0; default => 1). |
| src/shared/help.c | print_version() now exits 0 to make -V successful globally. |
| src/rootcheck/rootcheck.c | Rootcheck help now exits with explicit status (-h => 0; default => 1). |
| src/reportd/report.c | Report daemon help now exits with explicit status. |
| src/remoted/main.c | Remoted help now exits with explicit status. |
| src/os_maild/maild.c | Mail daemon help now exits with explicit status. |
| src/os_execd/execd.c | Execd help now exits with explicit status. |
| src/os_dbd/main.c | DBD help now exits with explicit status. |
| src/os_csyslogd/main.c | Csyslogd help now exits with explicit status. |
| src/os_auth/main-server.c | Auth server help now exits with explicit status. |
| src/os_auth/main-client.c | Auth client help now exits with explicit status. |
| src/monitord/main.c | Monitord help now exits with explicit status. |
| src/logcollector/main.c | Logcollector help now exits with explicit status. |
| src/client-agent/main.c | Agent daemon help now exits with explicit status. |
| src/analysisd/testrule.c | Logtest help now exits with explicit status. |
| src/analysisd/makelists.c | Makelists help now exits with explicit status. |
| src/analysisd/analysisd.c | Analysisd help now exits with explicit status. |
| src/agentlessd/main.c | Agentlessd help now exits with explicit status. |
| src/addagent/main.c | Addagent help now exits with explicit status. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| case 'f': | ||
| if (!optarg) { | ||
| merror("%s: -u needs an argument", ARGV0); | ||
| helpmsg(); | ||
| helpmsg(1); | ||
| } |
There was a problem hiding this comment.
In the 'f' option handler, the missing-argument error message says "-u needs an argument". This branch is for -f, so the message should reference -f to avoid misleading output.
| case 'j': | ||
| json_output = 1; | ||
| csv_output = 0; | ||
| csv_output = 0; | ||
| break; |
There was a problem hiding this comment.
The indentation of the 'j' case is inconsistent with the rest of the switch, and csv_output = 0; is visually aligned with the case label. This makes it easy to misread and could hide logic mistakes. Re-indent this case to match the surrounding style.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Updated all daemons and utilities to return exit code 0 when help (-h) or version (-V) flags are used, and exit code 1 for invalid arguments. This standardizes the behavior across the codebase. Closes issue #1965