Skip to content
Snippets Groups Projects
Commit 371172bc authored by Colin Walters's avatar Colin Walters
Browse files

fdio: Fix errno handling from posix_fallocate() and loop_write()

For extra fun, both of these functions have different error handling
schemes.  `posix_fallocate` does *not* set `errno` because...  I'm not
sure.  Maybe POSIX was trying a new function design?

`loop_write` uses the systemd error handling style which returns
`-errno`, so we need to set errno back so that the macro can propagate
it into the `GError`.
parent c36ea3ea
No related branches found
No related tags found
No related merge requests found
...@@ -647,6 +647,7 @@ glnx_file_replace_contents_with_perms_at (int dfd, ...@@ -647,6 +647,7 @@ glnx_file_replace_contents_with_perms_at (int dfd,
GError **error) GError **error)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
int r;
/* We use the /proc/self trick as there's no mkostemp_at() yet */ /* We use the /proc/self trick as there's no mkostemp_at() yet */
g_autofree char *tmppath = g_strdup_printf ("/proc/self/fd/%d/.tmpXXXXXX", dfd); g_autofree char *tmppath = g_strdup_printf ("/proc/self/fd/%d/.tmpXXXXXX", dfd);
glnx_fd_close int fd = -1; glnx_fd_close int fd = -1;
...@@ -663,14 +664,18 @@ glnx_file_replace_contents_with_perms_at (int dfd, ...@@ -663,14 +664,18 @@ glnx_file_replace_contents_with_perms_at (int dfd,
if (len == -1) if (len == -1)
len = strlen ((char*)buf); len = strlen ((char*)buf);
if (posix_fallocate (fd, 0, len)) /* Note that posix_fallocate does *not* set errno but returns it. */
r = posix_fallocate (fd, 0, len);
if (r != 0)
{ {
errno = r;
glnx_set_error_from_errno (error); glnx_set_error_from_errno (error);
goto out; goto out;
} }
if (loop_write (fd, buf, len) != 0) if ((r = loop_write (fd, buf, len)) != 0)
{ {
errno = -r;
glnx_set_error_from_errno (error); glnx_set_error_from_errno (error);
goto out; goto out;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment