| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
| |
Use decl-after-stmt where applicable.
|
|
|
|
|
| |
Port to `glnx_autofd` tree wide, and add one missed `glnx_close_fd()` use in the
tmpfile code.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
Followup to similar commits in the ostree stack recently.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
Not everything, but a good chunk of the remaining bits.
|
|
|
|
| |
There's a lot more fdio code, starting with some of the easier ones.
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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);
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
I swear I tested it...
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
Create a temporary directory using mkdirat.
https://bugzilla.gnome.org/show_bug.cgi?id=757611
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
We want to honor `-1 == AT_FDCWD`.
|
|
|
|
| |
This allows reusing an iterator struct.
|
| |
|
| |
|
|
|