Skip to content

Commit

Permalink
anacron: Use xclose() instead of fclose()
Browse files Browse the repository at this point in the history
When replacing standard descriptors we use
xclose() elsewhere and it is less error-prone.

Fixes #156
  • Loading branch information
t8m committed Oct 13, 2023
1 parent 7f59da7 commit 880489e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions anacron/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ go_background(void)

/* stdin is already closed */

if (fclose(stdout)) die_e("Can't close stdout");
xclose(STDOUT_FILENO);
/* coverity[leaked_handle] – fd 1 closed automatically */
xopen(1, "/dev/null", O_WRONLY);
xopen(STDOUT_FILENO, "/dev/null", O_WRONLY);

if (fclose(stderr)) die_e("Can't close stderr");
xclose(STDERR_FILENO);
/* coverity[leaked_handle] – fd 2 closed automatically */
xopen(2, "/dev/null", O_WRONLY);
xopen(STDERR_FILENO, "/dev/null", O_WRONLY);

pid = xfork();
if (pid != 0)
Expand Down Expand Up @@ -476,7 +476,7 @@ main(int argc, char *argv[])

if (sigprocmask(0, NULL, &old_sigmask)) die_e("sigset error");

if (fclose(stdin)) die_e("Can't close stdin");
xclose(STDIN_FILENO);
xopen(STDIN_FILENO, "/dev/null", O_RDONLY);

if (!no_daemon && !testing_only)
Expand Down

0 comments on commit 880489e

Please sign in to comment.