summaryrefslogtreecommitdiff
path: root/glnx-dirfd.c
Commit message (Collapse)AuthorAgeFilesLines
* backports: Add g_steal_fd, from GLib >= 2.70Simon McVittie2022-11-081-2/+2
| | | | | | | | | | This is essentially the same as glnx_steal_fd, so make glnx_steal_fd an alias for it. The unit test is taken from GLib, slightly modified to avoid g_close() and also test the old name glnx_steal_fd(). Signed-off-by: Simon McVittie <smcv@collabora.com>
* Declare copyright and licensing using REUSESimon McVittie2022-02-191-0/+1
| | | | | | | | | | | | | | To fill in some gaps, I've had to make some assumptions: * trivial changes (such as checking for an additional function or header file in libglnx.m4) are assumed to not be copyrightable * Will Thompson and Matthew Leeds are assumed to be contributing on behalf of Endless Mobile Inc. * files with no explicit licensing information are assumed to be under the license found in COPYING Reference: https://reuse.software/ Signed-off-by: Simon McVittie <smcv@debian.org>
* Include libglnx-config.h instead of config.hSimon McVittie2021-06-281-1/+1
| | | | | | | | | | | | | | | | | | | This avoids colliding with a config.h generated by a parent Meson project. In the Meson build system, we generate libglnx-config.h by doing our own checks, so we want to avoid it colliding. In the Autotools build system, we assume that the parent project will generate its own config.h that contains the results of LIBGLNX_CONFIGURE, and create a forwarding header libglnx-config.h in the $(top_builddir) (so that it is next to config.h). Note that after updating libglnx in an Autotools non-recursive-Make project (libostree, flatpak, flatpak-builder) it will be necessary to re-run autogen.sh. Signed-off-by: Simon McVittie <smcv@collabora.com>
* glnx-dirfd: Add a rewinddir() wrapperwip/smcv/rewinddirSimon McVittie2021-04-221-0/+18
| | | | | | | | This is useful in the same situations rewinddir() is. My use-case right now is to remove some of the files from a directory, then go back through the directory removing symlinks that pointed to those files. Signed-off-by: Simon McVittie <smcv@collabora.com>
* tree-wide: Some new style portingColin Walters2017-10-241-14/+7
| | | | Use decl-after-stmt where applicable.
* tree-wide: Use glnx_autofd and glnx_close_fd()Colin Walters2017-10-161-2/+2
| | | | | Port to `glnx_autofd` tree wide, and add one missed `glnx_close_fd()` use in the tmpfile code.
* Add glnx_fd_close() and glnx_autofdColin Walters2017-10-061-2/+1
| | | | | | | | | | | | | I'd like to have the checks for `EBADF` as well as the "assign to -1" in more places. The cleanup function we had for `glnx_fd_close` is actually what we want. Let's rename the cleanup macro to `glnx_autofd` to better match other autocleanups like `g_autofree`. Then we can use `glnx_fd_close()` as a replacement for plain Unix `close()`. I left the `glnx_close_fd` macro, but it's obviously confusing now with the former. We'll eventually remove it.
* tree-wide: Use our own syscall wrappers or error prefixingColin Walters2017-09-131-2/+3
| | | | Followup to similar commits in the ostree stack recently.
* dirfd: Extend tmpdir API to support optional cleaningColin Walters2017-09-131-12/+49
| | | | | | | | | | | | | We have a use case in libostree's staging dirs where we try to reuse them across multiple ostree txns, but we want the fd-relative bits here. Extend the tmpdir API to make deletion optional. While here, also extend the API to support checking for errors when deleting for projects like libostree that want to do so consistently. Also while here, add a change to set the fd to `-1` after clearing to be extra defensive.
* dirfd: New tmpdir APIColin Walters2017-08-181-63/+68
| | | | | | | | | | | Basically all of the ostree/rpm-ostree callers want to both create and open, so let's merge `glnx_mkdtempat()` and `glnx_mkdtempat_open()`. Second, all of them want to do `glnx_shutil_rm_rf_at()` on cleanup, so we do the same thing we did with `GLnxTmpfile` and create `GLnxTmpDir` that has a cleanup attribute. The cleanup this results in for rpm-ostree is pretty substantial.
* dirfd: Fix typo in commentMatthew Leeds2017-08-151-1/+1
|
* dirfd: Add filename to glnx_opendirat()Colin Walters2017-07-191-3/+1
| | | | | | This showed up in https://github.com/projectatomic/rpm-ostree/issues/883 We'll have to audit callers to be sure to avoid double-prefixing.
* dirfd: Have dfd iter _take_fd() take a pointer and do a stealColin Walters2017-05-311-5/+5
| | | | | | | | | | | | | | This avoids callers having to use `glnx_steal_fd()` on their own; in general, I think we should implement move semantics like this at the callee level. Another reason to do this is there's a subtle problem with doing: ``` somefunction (steal_value (&v), ..., error); ``` in that if `somefunction` throws, it may not have taken ownership of the value. At least `glnx_dirfd_iterator_init_take_fd()` didn't.
* dirfd,xattrs: Port mostly to new code styleColin Walters2017-05-301-29/+10
| | | | Not everything, but a good chunk of the remaining bits.
* Port most code (except fdio) to new styleColin Walters2017-04-251-9/+3
| | | | There's a lot more fdio code, starting with some of the easier ones.
* glnx-dirfd: Add variants of glnx_mkdtempat() which open the directoryPhilip Withnall2017-04-211-0/+67
| | | | | | | | At the moment, it’s not possible for them to do this race-free (since openat(O_DIRECTORY | O_CREAT | O_EXCL) doesn’t work), but in future this could be possible. In any case, it’s a useful thing to want to do. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* errors: Add new glnx_throw_errno{,_prefix}() APIsColin Walters2017-03-221-4/+2
| | | | | | | | | | | | | | | | | | | | We have a *lot* of code of the form: ``` if (unlinkat (fd, pathname) < 0) { glnx_set_error_from_errno (error); goto out; } ``` After conversion to `return FALSE style` which is in progress, it's way shorter, and clearer like this: ``` if (unlinkat (fd, pathname) < 0) return glnx_throw_errno (error); ```
* dirfd: Use better and faster random algorithm for gen_temp_name()Colin Walters2017-01-261-26/+4
| | | | | | | | | | | | | | | | I was looking at ostree performance, and a surprising amount of time was spent in `glnx_gen_temp_name()`. We end up calling it from the main loop, and the iteration here shows up in my perf profiles. The glibc algorithm here that we adopted is *very* dated; let's switch to use `GRand`, which gives us a better algorithm. It'd be even better of course to use `getrandom()`, but we should do that in glib at some point. While I had the patient open, I extended the charset with lowercase, to better avoid collisions.
* dirfd: Set initialized flag for itersColin Walters2016-10-271-0/+4
| | | | | | | | | And use it when deinitializing, to avoid calling `closedir(NULL)`. In practice, this doesn't matter, because `closedir` *does* handle `NULL` in glibc. However, I'm playing with the GCC `-fsanitize=undefined`, and it aborts because `closedir` is tagged as requiring a non-`NULL` pointer.
* dirfd: Fix inverted precondition in previous tmpname commitColin Walters2016-05-311-1/+1
| | | | I swear I tested it...
* Introduce glnx_gen_temp_name()Colin Walters2016-05-301-21/+37
| | | | | | | We have multiple copies growing again of this code. glibc has this API internally and uses it in multiple places, let's do the same. Closes: #14
* dirfd: Add a public API to ensure a filled dtypeColin Walters2016-01-021-0/+49
| | | | | | | | It's quite common to iterate over a directory recursively, only caring about the file type, but not other bits returned by `stat()`. Good file systems fill in `dt_type`, but not all do. This function papers over that in userspace conveniently.
* Add glnx_mkdtempatAlexander Larsson2015-12-111-0/+77
| | | | | | Create a temporary directory using mkdirat. https://bugzilla.gnome.org/show_bug.cgi?id=757611
* dirfd: Add API to get an absolute path from a dfd/relpathColin Walters2015-04-171-0/+22
| | | | | | | | There are a lot of APIs that still only take absolute paths, such as librpm (and everything above it). I plan to use this in rpm-ostree to convert temporary directories that I'm accessing fd-relative back into absolutes until such time as fd-relative APIs are plumbed through the stack more.
* Add glnx_dirfd_canonicalize()Colin Walters2015-03-171-0/+3
| | | | We want to honor `-1 == AT_FDCWD`.
* dfditer: Unset initialized variable when clearedColin Walters2015-03-031-0/+1
| | | | This allows reusing an iterator struct.
* dirfd: Fix two typosColin Walters2015-02-171-2/+2
|
* dirfd: Add some gtk-docColin Walters2015-02-151-11/+48
|
* Import directory iteration, errno handling, and shutil from libgsystemColin Walters2015-02-151-0/+165