Skip to content
Snippets Groups Projects
Commit 9307f518 authored by Philip Withnall's avatar Philip Withnall
Browse files

glnx-shutil: Add glnx_shutil_mkdir_p_at_open()


This is a variant of glnx_shutil_mkdir_p_at() which opens the given
directory and returns a dirfd to it. Currently, the implementation
cannot be race-free (due to a kernel bug), but it could eventually be
made race-free.

Signed-off-by: default avatarPhilip Withnall <withnall@endlessm.com>
parent 2576a07e
No related branches found
No related tags found
No related merge requests found
...@@ -246,3 +246,40 @@ glnx_shutil_mkdir_p_at (int dfd, ...@@ -246,3 +246,40 @@ glnx_shutil_mkdir_p_at (int dfd,
out: out:
return ret; return ret;
} }
/**
* glnx_shutil_mkdir_p_at_open:
* @dfd: Directory fd
* @path: Directory path to be created
* @mode: Mode for newly created directories
* @out_dfd: (out caller-allocates): Return location for an FD to @dfd/@path,
* or `-1` on error
* @cancellable: (nullable): Cancellable, or %NULL
* @error: Return location for a #GError, or %NULL
*
* Similar to glnx_shutil_mkdir_p_at(), except it opens the resulting directory
* and returns a directory FD to it. Currently, this is not guaranteed to be
* race-free.
*
* Returns: %TRUE on success, %FALSE otherwise
* Since: UNRELEASED
*/
gboolean
glnx_shutil_mkdir_p_at_open (int dfd,
const char *path,
int mode,
int *out_dfd,
GCancellable *cancellable,
GError **error)
{
/* FIXME: It’s not possible to eliminate the race here until
* openat(O_DIRECTORY | O_CREAT) works (and returns a directory rather than a
* file). It appears to be not supported in current kernels. (Tested with
* 4.10.10-200.fc25.x86_64.) */
*out_dfd = -1;
if (!glnx_shutil_mkdir_p_at (dfd, path, mode, cancellable, error))
return FALSE;
return glnx_opendirat (dfd, path, TRUE, out_dfd, error);
}
...@@ -37,4 +37,12 @@ glnx_shutil_mkdir_p_at (int dfd, ...@@ -37,4 +37,12 @@ glnx_shutil_mkdir_p_at (int dfd,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);
gboolean
glnx_shutil_mkdir_p_at_open (int dfd,
const char *path,
int mode,
int *out_dfd,
GCancellable *cancellable,
GError **error);
G_END_DECLS G_END_DECLS
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