Skip to content

Commit

Permalink
dhcpcd: stdout output sometimes empty when redirected to a file
Browse files Browse the repository at this point in the history
Running dhpcd --dumplease with input from stdin and redirecting stdout
to a file outputs nothing to the output. The reason is that printf /
fprintf is used to write the output but it is not explicitly flushed
when done, or before exiting, and stdout to files is fully buffered by
default while stdout to terminals is line buffered by default.

This adds calls to fflush() at the end of dhcp_print_option_encoding()
and script_dump(), plus one just before exiting dhcpcd.

Signed-off-by: Diego Santa Cruz <[email protected]>
  • Loading branch information
diego-santacruz committed Aug 27, 2024
1 parent ab5ec18 commit 20579b4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/dhcp-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ dhcp_print_option_encoding(const struct dhcp_opt *opt, int cols)
if (opt->type & OT_NOREQ)
printf(" norequest");
putchar('\n');
fflush(stdout);
}

struct dhcp_opt *
Expand Down
1 change: 1 addition & 0 deletions src/dhcpcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2719,6 +2719,7 @@ main(int argc, char **argv, char **envp)
eloop_free(ctx.eloop);
logclose();
free(ctx.logfile);
fflush(stdout);
free(ctx.ctl_buf);
#ifdef SETPROCTITLE_H
setproctitle_fini();
Expand Down
1 change: 1 addition & 0 deletions src/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ script_dump(const char *env, size_t len)
env += 4;
printf("%s\n", env);
}
fflush(stdout);
return 0;
}

Expand Down

0 comments on commit 20579b4

Please sign in to comment.