Skip to content

Options variables converted to a structure#469

Open
gsnw-sebast wants to merge 2 commits intoschweikert:developfrom
gsnw:flags-variable-to-struct
Open

Options variables converted to a structure#469
gsnw-sebast wants to merge 2 commits intoschweikert:developfrom
gsnw:flags-variable-to-struct

Conversation

@gsnw-sebast
Copy link
Copy Markdown
Collaborator

I've wrapped the option variables in a structure.
This improves the following:

  • Encapsulation and namespace
  • Easy initialization and copyability
  • Extensibility and maintainability

@coveralls
Copy link
Copy Markdown

coveralls commented May 1, 2026

Coverage Status

coverage: 87.937% (-0.06%) from 88.0% — gsnw:flags-variable-to-struct into schweikert:develop

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the configuration system by consolidating global option variables into a centralized Options structure. It includes the definition of the struct, an initialization function for default values, and updates to all references throughout the source code. The review feedback highlights a potential breaking change in debug log formats and suggests further encapsulating remaining debug flags within the new structure for consistency.

Comment thread src/fping.c
Comment thread src/flags.h
@gsnw-sebast
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the configuration system by grouping global option variables into Options and DebugOptions structures, introducing initialization functions, and updating all references throughout the codebase. The review feedback identifies an opportunity to correct inconsistent indentation in the new initialization logic, suggests refining debug output strings to hide internal struct prefixes for better readability, and recommends including flags.h within fping.h to ensure the header is self-contained.

Comment thread src/flags.c
Comment thread src/fping.c
Comment on lines +1049 to 1096
if (dbg_opt.trace_on) {
fprintf(stderr, "%s:\n opt.count: %u, opt.retry: %u, opt.interval: %.0f ms\n",
prog, opt.count, opt.retry, opt.interval / 1e6);
fprintf(stderr, " opt.perhost_interval: %.0f ms, opt.timeout: %.0f\n",
opt.perhost_interval / 1e6, opt.timeout / 1e6);
fprintf(stderr, " opt.seqmap_timeout: %.0f\n", opt.seqmap_timeout / 1e6);
fprintf(stderr, " opt.ping_data_size = %u, trials = %u\n",
opt.ping_data_size, trials);

if (opt.verbose_on)
fprintf(stderr, " opt.verbose_on set\n");
if (opt.multif_on)
fprintf(stderr, " opt.multif_on set\n");
if (opt.name_on)
fprintf(stderr, " opt.name_on set\n");
if (opt.addr_on)
fprintf(stderr, " opt.addr_on set\n");
if (opt.stats_on)
fprintf(stderr, " opt.stats_on set\n");
if (opt.unreachable_on)
fprintf(stderr, " opt.unreachable_on set\n");
if (opt.alive_on)
fprintf(stderr, " opt.alive_on set\n");
if (opt.elapsed_on)
fprintf(stderr, " opt.elapsed_on set\n");
if (opt.version_on)
fprintf(stderr, " opt.version_on set\n");
if (opt.count_on)
fprintf(stderr, " opt.count_on set\n");
if (opt.loop_on)
fprintf(stderr, " opt.loop_on set\n");
if (opt.backoff_on)
fprintf(stderr, " opt.backoff_on set\n");
if (opt.per_recv_on)
fprintf(stderr, " opt.per_recv_on set\n");
if (opt.report_all_rtts_on)
fprintf(stderr, " opt.report_all_rtts_on set\n");
if (dbg_opt.randomly_lose_on)
fprintf(stderr, " dbg_opt.randomly_lose_on set\n");
if (dbg_opt.print_per_system_on)
fprintf(stderr, " dbg_opt.print_per_system_on set\n");
if (opt.outage_on)
fprintf(stderr, " opt.outage_on set\n");
if (opt.print_netdata_on)
fprintf(stderr, " opt.print_netdata_on set\n");
if (opt.print_json_on)
fprintf(stderr, " opt.print_json_on set\n");
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The debug messages in this block now print variable names with their struct prefixes (e.g., opt.count, dbg_opt.randomly_lose_on). This exposes implementation details in the debug output, making it less clean and harder to read.

Please consider removing the opt. and dbg_opt. prefixes from the format strings to only print the option names.

For example:

// Before
fprintf(stderr, "%s:\n  opt.count: %u, opt.retry: %u, opt.interval: %.0f ms\n",
    prog, opt.count, opt.retry, opt.interval / 1e6);
if (dbg_opt.randomly_lose_on)
    fprintf(stderr, "  dbg_opt.randomly_lose_on set\n");

// After
fprintf(stderr, "%s:\n  count: %u, retry: %u, interval: %.0f ms\n",
    prog, opt.count, opt.retry, opt.interval / 1e6);
if (dbg_opt.randomly_lose_on)
    fprintf(stderr, "  randomly_lose_on set\n");

This should be applied to all the fprintf calls in this debug block.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

In my opinion, the current issue is a good fit.

Comment thread src/fping.h
@gsnw-sebast gsnw-sebast force-pushed the flags-variable-to-struct branch from e0217dc to 3f3849a Compare May 2, 2026 06:15
@gsnw-sebast gsnw-sebast force-pushed the flags-variable-to-struct branch from 3f3849a to cd00560 Compare May 2, 2026 06:20
@gsnw-sebast gsnw-sebast requested a review from schweikert May 2, 2026 06:24
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.

2 participants