On Wed, Apr 27, 2022 at 6:55 PM Jason A. Donenfeld <ja...@zx2c4.com> wrote:
> On Wed, Apr 27, 2022 at 06:15:50PM +0200, Denys Vlasenko wrote:
> >         if ((unlink(filename) < 0 || fsync(dfd) < 0) && seed_len) {
> >                 bb_perror_msg("can't%s seed", " remove");
> >                 return -1;
> >         }
> >
> > Why can't the entire above if() be replaced with xunlink(filename) ?
>
> It cannot be replaced with that. The fsync() must happen before other
> operations move forward,

Why? It should be explained in a comment, and explained well enough
so that future developers do not repeatedly try to remove it
because "I don't see why it's necessary".

> and exiting the program isn't necessarily the
> correct course of action.

Let's see.
If we opened the file, read it, and then failed to unlink it,
it means that filesystem is read-only, there is a permission problem
(e.g. SELinux), or there is an I/O error.
All of these cases mean that the system is not in expected state,
and further efforts to "continue as normal" (e.g. try to rewrite
/var/lib/seedrng/seed.credit) do not seem likely to be productive to me.
I think it's better to just complain and exit.
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to