src/update_handler.c: fix fd handling in copy_raw_image
src/update_handler.c: fix fd handling in copy_raw_image

A failure in copy_raw_image() (e.g. when g_output_stream_splice() returned
an error) would have left the fd on the output device open.

Subsequent install attempts then would have failed like:

| Opening output device /dev/mmcblk0p1 failed: Device or resource busy

This happens, because only some and not all error paths called
close(out_fd) to close the open file descriptor of the output device.

However, it should not be required to close the file descriptor manually in
copy_raw_image(). Conceptually, the file descriptor belongs to the
GUnixOutputStream and should be closed with it by the calling functions.

Why this did not happen has two combined reasons

a) closing the file descriptor when closing the stream was explicitly
   disabled in commit 549d79b5 by adding
   'g_unix_output_stream_set_close_fd(outstream, FALSE);'.

   This was done to allow calling fsync() on the already-closed fd.

b) The fd in turn was already closed because g_output_stream_splice()
   was called with G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET which instantly
   closes the stream after splicing.

So the right approach is to revert both choices. Simply leave the output
stream alive after splicing data (by using G_OUTPUT_STREAM_SPLICE_NONE).
This will give us access to the fd until the stream itself is cleared
and allows us to drop g_unix_output_stream_set_close_fd(outstream,
FALSE). The output stream is then closed in the calling functions to detect any
remaining errors.

Fixes 549d79b5 ("src/update_handler: add fsync call to copy_raw_image()")

Fixes #761

Signed-off-by: Christian Hitz <37594ec2138f03c49f98fc3e37a830e03833b510@bbv.ch>
Signed-off-by: Enrico Joerns <a2e5f936c390f36494e46e71bcfbe365bb1e8c49@pengutronix.de>
Signed-off-by: Jan Luebbe <3a82f1ac4ad59607a20f180f1c67ac8ba31ad0d5@pengutronix.de>

ejoerns/rauc,rauc/rauc,ejoerns/rauc,jluebbe/rauc,jluebbe/rauc,rauc/rauc,jluebbe/rauc,ejoerns/rauc,rauc/rauc