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

dirfd,xattrs: Port mostly to new code style

Not everything, but a good chunk of the remaining bits.
parent 2f8fdf80
No related branches found
No related tags found
No related merge requests found
...@@ -99,19 +99,14 @@ glnx_dirfd_iterator_init_at (int dfd, ...@@ -99,19 +99,14 @@ glnx_dirfd_iterator_init_at (int dfd,
GLnxDirFdIterator *out_dfd_iter, GLnxDirFdIterator *out_dfd_iter,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
glnx_fd_close int fd = -1; glnx_fd_close int fd = -1;
if (!glnx_opendirat (dfd, path, follow, &fd, error)) if (!glnx_opendirat (dfd, path, follow, &fd, error))
goto out; return FALSE;
if (!glnx_dirfd_iterator_init_take_fd (fd, out_dfd_iter, error)) if (!glnx_dirfd_iterator_init_take_fd (glnx_steal_fd (&fd), out_dfd_iter, error))
goto out; return FALSE;
fd = -1; /* Transfer ownership */
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
...@@ -128,24 +123,16 @@ glnx_dirfd_iterator_init_take_fd (int dfd, ...@@ -128,24 +123,16 @@ glnx_dirfd_iterator_init_take_fd (int dfd,
GLnxDirFdIterator *dfd_iter, GLnxDirFdIterator *dfd_iter,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
GLnxRealDirfdIterator *real_dfd_iter = (GLnxRealDirfdIterator*) dfd_iter; GLnxRealDirfdIterator *real_dfd_iter = (GLnxRealDirfdIterator*) dfd_iter;
DIR *d = NULL; DIR *d = fdopendir (dfd);
d = fdopendir (dfd);
if (!d) if (!d)
{ return glnx_throw_errno_prefix (error, "fdopendir");
glnx_set_prefix_error_from_errno (error, "%s", "fdopendir");
goto out;
}
real_dfd_iter->fd = dfd; real_dfd_iter->fd = dfd;
real_dfd_iter->d = d; real_dfd_iter->d = d;
real_dfd_iter->initialized = TRUE; real_dfd_iter->initialized = TRUE;
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
...@@ -165,31 +152,25 @@ glnx_dirfd_iterator_next_dent (GLnxDirFdIterator *dfd_iter, ...@@ -165,31 +152,25 @@ glnx_dirfd_iterator_next_dent (GLnxDirFdIterator *dfd_iter,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
GLnxRealDirfdIterator *real_dfd_iter = (GLnxRealDirfdIterator*) dfd_iter; GLnxRealDirfdIterator *real_dfd_iter = (GLnxRealDirfdIterator*) dfd_iter;
g_return_val_if_fail (out_dent, FALSE); g_return_val_if_fail (out_dent, FALSE);
g_return_val_if_fail (dfd_iter->initialized, FALSE); g_return_val_if_fail (dfd_iter->initialized, FALSE);
if (g_cancellable_set_error_if_cancelled (cancellable, error)) if (g_cancellable_set_error_if_cancelled (cancellable, error))
goto out; return FALSE;
do do
{ {
errno = 0; errno = 0;
*out_dent = readdir (real_dfd_iter->d); *out_dent = readdir (real_dfd_iter->d);
if (*out_dent == NULL && errno != 0) if (*out_dent == NULL && errno != 0)
{ return glnx_throw_errno_prefix (error, "readdir");
glnx_set_prefix_error_from_errno (error, "%s", "fdopendir");
goto out;
}
} while (*out_dent && } while (*out_dent &&
(strcmp ((*out_dent)->d_name, ".") == 0 || (strcmp ((*out_dent)->d_name, ".") == 0 ||
strcmp ((*out_dent)->d_name, "..") == 0)); strcmp ((*out_dent)->d_name, "..") == 0));
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
......
...@@ -270,31 +270,22 @@ set_all_xattrs_for_path (const char *path, ...@@ -270,31 +270,22 @@ set_all_xattrs_for_path (const char *path,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE; const guint n = g_variant_n_children (xattrs);
int i, n; for (guint i = 0; i < n; i++)
n = g_variant_n_children (xattrs);
for (i = 0; i < n; i++)
{ {
const guint8* name; const guint8* name;
g_autoptr(GVariant) value = NULL; g_autoptr(GVariant) value = NULL;
const guint8* value_data;
gsize value_len;
g_variant_get_child (xattrs, i, "(^&ay@ay)", g_variant_get_child (xattrs, i, "(^&ay@ay)",
&name, &value); &name, &value);
value_data = g_variant_get_fixed_array (value, &value_len, 1);
gsize value_len;
const guint8* value_data = g_variant_get_fixed_array (value, &value_len, 1);
if (lsetxattr (path, (char*)name, (char*)value_data, value_len, 0) < 0) if (lsetxattr (path, (char*)name, (char*)value_data, value_len, 0) < 0)
{ return glnx_throw_errno_prefix (error, "lsetxattr");
glnx_set_prefix_error_from_errno (error, "%s", "lsetxattr");
goto out;
}
} }
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
...@@ -347,35 +338,22 @@ glnx_fd_set_all_xattrs (int fd, ...@@ -347,35 +338,22 @@ glnx_fd_set_all_xattrs (int fd,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE; const guint n = g_variant_n_children (xattrs);
int i, n; for (guint i = 0; i < n; i++)
n = g_variant_n_children (xattrs);
for (i = 0; i < n; i++)
{ {
const guint8* name; const guint8* name;
const guint8* value_data;
g_autoptr(GVariant) value = NULL; g_autoptr(GVariant) value = NULL;
gsize value_len;
int res;
g_variant_get_child (xattrs, i, "(^&ay@ay)", g_variant_get_child (xattrs, i, "(^&ay@ay)",
&name, &value); &name, &value);
value_data = g_variant_get_fixed_array (value, &value_len, 1);
gsize value_len;
do const guint8* value_data = g_variant_get_fixed_array (value, &value_len, 1);
res = fsetxattr (fd, (char*)name, (char*)value_data, value_len, 0);
while (G_UNLIKELY (res == -1 && errno == EINTR)); if (TEMP_FAILURE_RETRY (fsetxattr (fd, (char*)name, (char*)value_data, value_len, 0)) < 0)
if (G_UNLIKELY (res == -1)) return glnx_throw_errno_prefix (error, "fsetxattr");
{
glnx_set_prefix_error_from_errno (error, "%s", "fsetxattr");
goto out;
}
} }
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
...@@ -395,35 +373,17 @@ glnx_lgetxattrat (int dfd, ...@@ -395,35 +373,17 @@ glnx_lgetxattrat (int dfd,
GError **error) GError **error)
{ {
char pathbuf[PATH_MAX]; char pathbuf[PATH_MAX];
GBytes *bytes = NULL;
ssize_t bytes_read, real_size;
guint8 *buf;
snprintf (pathbuf, sizeof (pathbuf), "/proc/self/fd/%d/%s", dfd, subpath); snprintf (pathbuf, sizeof (pathbuf), "/proc/self/fd/%d/%s", dfd, subpath);
do ssize_t bytes_read, real_size;
bytes_read = lgetxattr (pathbuf, attribute, NULL, 0); if (TEMP_FAILURE_RETRY (bytes_read = lgetxattr (pathbuf, attribute, NULL, 0)) < 0)
while (G_UNLIKELY (bytes_read < 0 && errno == EINTR)); return glnx_null_throw_errno_prefix (error, "lgetxattr");
if (G_UNLIKELY (bytes_read < 0))
{
glnx_set_error_from_errno (error);
goto out;
}
buf = g_malloc (bytes_read); g_autofree guint8 *buf = g_malloc (bytes_read);
do if (TEMP_FAILURE_RETRY (real_size = lgetxattr (pathbuf, attribute, buf, bytes_read)) < 0)
real_size = lgetxattr (pathbuf, attribute, buf, bytes_read); return glnx_null_throw_errno_prefix (error, "lgetxattr");
while (G_UNLIKELY (real_size < 0 && errno == EINTR));
if (G_UNLIKELY (real_size < 0))
{
glnx_set_error_from_errno (error);
g_free (buf);
goto out;
}
bytes = g_bytes_new_take (buf, real_size); return g_bytes_new_take (g_steal_pointer (&buf), real_size);
out:
return bytes;
} }
/** /**
...@@ -439,33 +399,16 @@ glnx_fgetxattr_bytes (int fd, ...@@ -439,33 +399,16 @@ glnx_fgetxattr_bytes (int fd,
const char *attribute, const char *attribute,
GError **error) GError **error)
{ {
GBytes *bytes = NULL;
ssize_t bytes_read, real_size; ssize_t bytes_read, real_size;
guint8 *buf;
do if (TEMP_FAILURE_RETRY (bytes_read = fgetxattr (fd, attribute, NULL, 0)) < 0)
bytes_read = fgetxattr (fd, attribute, NULL, 0); return glnx_null_throw_errno_prefix (error, "fgetxattr");
while (G_UNLIKELY (bytes_read < 0 && errno == EINTR));
if (G_UNLIKELY (bytes_read < 0))
{
glnx_set_error_from_errno (error);
goto out;
}
buf = g_malloc (bytes_read); g_autofree guint8 *buf = g_malloc (bytes_read);
do if (TEMP_FAILURE_RETRY (real_size = fgetxattr (fd, attribute, buf, bytes_read)) < 0)
real_size = fgetxattr (fd, attribute, buf, bytes_read); return glnx_null_throw_errno_prefix (error, "fgetxattr");
while (G_UNLIKELY (real_size < 0 && errno == EINTR));
if (G_UNLIKELY (real_size < 0))
{
glnx_set_error_from_errno (error);
g_free (buf);
goto out;
}
bytes = g_bytes_new_take (buf, real_size); return g_bytes_new_take (g_steal_pointer (&buf), real_size);
out:
return bytes;
} }
/** /**
...@@ -490,18 +433,10 @@ glnx_lsetxattrat (int dfd, ...@@ -490,18 +433,10 @@ glnx_lsetxattrat (int dfd,
GError **error) GError **error)
{ {
char pathbuf[PATH_MAX]; char pathbuf[PATH_MAX];
int res;
snprintf (pathbuf, sizeof (pathbuf), "/proc/self/fd/%d/%s", dfd, subpath); snprintf (pathbuf, sizeof (pathbuf), "/proc/self/fd/%d/%s", dfd, subpath);
do if (TEMP_FAILURE_RETRY (lsetxattr (subpath, attribute, value, len, flags)) < 0)
res = lsetxattr (subpath, attribute, value, len, flags); return glnx_throw_errno_prefix (error, "lsetxattr");
while (G_UNLIKELY (res == -1 && errno == EINTR));
if (G_UNLIKELY (res == -1))
{
glnx_set_error_from_errno (error);
return FALSE;
}
return TRUE; return TRUE;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment