Skip to content

Comments

Fix help/version argument exit codes#2174

Merged
atomicturtle merged 4 commits intoossec:mainfrom
atomicturtle:260124-03
Jan 24, 2026
Merged

Fix help/version argument exit codes#2174
atomicturtle merged 4 commits intoossec:mainfrom
atomicturtle:260124-03

Conversation

@atomicturtle
Copy link
Member

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

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>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 explicit status and exit(status).
  • Adjusted -h call sites to pass 0 and invalid-argument paths to pass 1.
  • Changed print_version() to exit with code 0.

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.

Comment on lines 113 to 117
case 'f':
if (!optarg) {
merror("%s: -u needs an argument", ARGV0);
helpmsg();
helpmsg(1);
}
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +111 to 114
case 'j':
json_output = 1;
csv_output = 0;
csv_output = 0;
break;
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

atomicturtle and others added 3 commits January 24, 2026 12:39
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>
@atomicturtle atomicturtle merged commit 1392ff7 into ossec:main Jan 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant