summaryrefslogtreecommitdiff
path: root/glnx-fdio.h
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2017-05-15 16:07:32 -0400
committerColin Walters <walters@verbum.org>2017-05-15 17:15:12 -0400
commit9929adcd99d15dc4f5a925f9b7ec2318f646f1bf (patch)
treeb4b37192bd5a619e660ad7533e58b9b720bc206e /glnx-fdio.h
parent32231fdb5273dd2a812c61549d6c0e681c0f5d59 (diff)
downloadlibglnx-9929adcd99d15dc4f5a925f9b7ec2318f646f1bf.tar.gz
fdio: Redo tmpfile API with GLnxTmpfile struct
The core problem with the previous tmpfile code is we don't have an autocleanup that calls `unlinkat` in the non-`O_TMPFILE` case. And even if we did, it'd be awkward still since the `glnx_link_tmpfile_at()` call *consumes* the tmpfile. Fix this by introducing a struct with a cleanup macro. This simplifies a number of the callers in libostree - a notable case is where we had two arrays, one of fds, one of paths. It makes other places in libostree a bit more complex, but that's because some of the commit code paths want to deal with temporary *symlinks* too. Most callers are better though - in libglnx itself, `glnx_file_copy_at()` now correctly unlinks on failure for example.
Diffstat (limited to 'glnx-fdio.h')
-rw-r--r--glnx-fdio.h16
1 files changed, 11 insertions, 5 deletions
diff --git a/glnx-fdio.h b/glnx-fdio.h
index deff22b..cc36ca4 100644
--- a/glnx-fdio.h
+++ b/glnx-fdio.h
@@ -48,12 +48,20 @@ const char *glnx_basename (const char *path)
return (basename) (path);
}
+typedef struct {
+ int src_dfd;
+ int fd;
+ char *path;
+} GLnxTmpfile;
+#define GLNX_TMPFILE_INIT { .src_dfd = -1 };
+void glnx_tmpfile_clear (GLnxTmpfile *tmpf);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GLnxTmpfile, glnx_tmpfile_clear);
+
gboolean
glnx_open_tmpfile_linkable_at (int dfd,
const char *subpath,
int flags,
- int *out_fd,
- char **out_path,
+ GLnxTmpfile *out_tmpf,
GError **error);
typedef enum {
@@ -63,10 +71,8 @@ typedef enum {
} GLnxLinkTmpfileReplaceMode;
gboolean
-glnx_link_tmpfile_at (int dfd,
+glnx_link_tmpfile_at (GLnxTmpfile *tmpf,
GLnxLinkTmpfileReplaceMode flags,
- int fd,
- const char *tmpfile_path,
int target_dfd,
const char *target,
GError **error);