summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* 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.
* errors: Add GLNX_AUTO_PREFIX_ERRORColin Walters2017-07-172-0/+73
| | | | | | | | | | | | In a lot of places in ostree, we end up prefixing errors in the *caller*. Often we only have 1-2 callers, and doing the error prefixing isn't too duplicative. But there are definitely cases where it's cleaner to do the prefixing in the callee. We have functions that aren't ported to new style for this reason (they still do the prefixing in `out:`). Introduce a cleanup-oriented version of error prefixing so we can port those functions too.
* fdio: Add string prefix for glnx_fstat()Colin Walters2017-07-171-2/+1
| | | | For consistency.
* fdio: Add a fchmod wrapperColin Walters2017-07-171-0/+22
| | | | | There are a number of versions of this in ostree at least, might as well wrap it.
* Remove glnx_stream_fstat()Colin Walters2017-07-172-30/+0
| | | | | There are only two users of this in ostree, and one of them is fairly bogus; we can just use `fstat()`.
* fdio: Add cleanup+flush API for FILE*Colin Walters2017-07-173-0/+49
| | | | | | | | | | | | | | | | | Mostly in ostree/rpm-ostree, we work in either raw `int fd`, or `G{Input,Output}Stream`. One exception is the rpm-ostree `/etc/passwd` handling, which uses `FILE*` since that's what glibc exposes. And in general, there are use cases for `FILE*`; the raw `GUnixOutputStream` for example isn't buffered, and doing so via e.g. `GBufferedOutputStream` means allocating *two* GObjects and even worse going through multiple vfuncs for every write. `FILE*` is used heavily in systemd, and provides buffering. It is a bit cheaper than gobjects, but has its own trap; by default every operation locks a mutex. For more information on that, see `unlocked_stdio(3)`. However, callers can avoid that by using e.g. `fwrite_unlocked`, which I plan to do for most users of `FILE*` that aren't writing to one of the standard streams like `stdout` etc.
* README.md: Change xdg-app to flatpakMatthew Leeds2017-07-131-1/+1
|
* fdio: Ensure O_TMPFILE is mode 0600Colin Walters2017-07-102-6/+35
| | | | Work around an older glibc bug.
* macros: Add a size check for hashtable itersColin Walters2017-06-301-0/+2
| | | | | | | If the user provides a less than pointer-sized type, we'll clobber other things on the stack. See https://github.com/ostreedev/ostree/pull/990/
* tests: Fix compilation of fdio testColin Walters2017-06-281-1/+1
| | | | Not sure how I missed this before.
* fdio: Remove extra ';' in headerColin Walters2017-06-281-1/+1
| | | | This was confusing `g-ir-scanner`.
* macros: Avoid scanning macrosColin Walters2017-06-281-0/+5
| | | | | `g-ir-scanner` is confused by some of the syntax extensions in `G_IN_SET()`; none of this is applicable to bindings, so just skip it.
* fdio: Introduce glnx_open_anonymous_tmpfile()Colin Walters2017-06-282-0/+29
| | | | There was a user of this in the libostree static delta code.
* fdio: Be sure to unset tmpfile's initialized state on cleanupColin Walters2017-06-281-1/+8
| | | | | | | I'm not aware of a problem in practice here, but we should do this on general principle. Writing this patch now because I hit a fd leak in the ostree static delta processing that was introduced in the tmpfile prep code, but fixed in the final port.
* macros: add GLNX_HASH_TABLE_FOREACH_VJonathan Lebon2017-06-282-1/+18
| | | | | | | Looking at converting the ostree codebase, iterating over only the values of a hash table (while ignoring the key) is actually a more common pattern than I thought. So let's give it its own macro as well so users don't have to resort to the _KV variant.
* fdio: Add wrappers for renameat(), unlinkat()Colin Walters2017-06-263-10/+40
| | | | | Besides doing `TEMP_FAILURE_RETRY` and `GError` conversion, these also prefix the error with arguments.
* glnx-macros.h: add GLNX_HASH_TABLE_FOREACH macrosJonathan Lebon2017-06-172-0/+111
| | | | | | | | These macros make it much easier to iterate over a GHashTable. It takes care of initializing an iterator and casting keys and values to their proper types. See the example usage in the docstring for more info.
* test-libglnx-macros.c: fix missing semicolonJonathan Lebon2017-06-171-1/+1
|
* Add G_IN_SET, patch our internal users via spatchColin Walters2017-06-148-57/+178
| | | | | | | | | | | | | | I originally tried to get this into GLib: https://bugzilla.gnome.org/show_bug.cgi?id=783751 But that looks like it's going to fail due to MSVC. Let's add it here at least so I can start using it tomorrow and not wait for the MSVC team to catch up. I renamed `glnx-alloca.h` to `glnx-macros.h` as a more natural collective home for things from systemd's `macro.h`. Finally, I used a Coccinelle spatch similar to the one referenced in the above BZ to patch our uses.
* fdio: Add glnx_try_fallocate()Colin Walters2017-06-132-11/+34
| | | | | | The glibc `posix_fallocate()` implementation has a bad fallback, and further we need to handle `EOPNOTSUPP` for musl. https://github.com/flatpak/flatpak/issues/802
* dirfd: Have dfd iter _take_fd() take a pointer and do a stealColin Walters2017-05-313-8/+7
| | | | | | | | | | | | | | 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-302-126/+42
| | | | Not everything, but a good chunk of the remaining bits.
* fdio: Allow using AT_FDCWD with GlnxTmpfileAlexander Larsson2017-05-192-8/+12
| | | | | | | | | | | Add an `initialized` member which means we work by default in structs allocated with `g_new0` etc. and don't need a special initializer. This also fixes a bug where we need to support `src_dfd == -1` or `AT_FDCWD`. This fixes flatpak which uses AT_FDCWD. Modified-by: Colin Walters <walters@verbum.org>
* fdio: Add missing return in tmpfile error caseColin Walters2017-05-171-0/+1
| | | | Just noticed this while reading the code.
* fdio: Redo tmpfile API with GLnxTmpfile structColin Walters2017-05-152-44/+68
| | | | | | | | | | | | | | | | | 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.
* glnx-errors.h: add a glnx_throw_prefix() variantJonathan Lebon2017-05-113-9/+59
| | | | | | For completeness. It just looks much cleaner than doing the `, FALSE` trick. It also takes care of appending the ': ' for you like its errno version.
* fdio: Expose glnx_regfile_copy_bytes(), rewrite: GNU style, POSIX errnov2017.1Colin Walters2017-04-282-91/+114
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | NOTE: This changes the error handling API of `glnx_loop_write()` to be "old school POSIX" instead of "systemd". In ostree in a few places we use `g_output_stream_splice()`. I thought this would use `splice()`, but actually it doesn't today. They also, if a cancellable is provided, end up dropping into `poll()` for every read and write. (In addition to copying data to/from userspace). My opinion on this is - for *local files* that's dumb. In the big picture, you really only need cancellation when copying gigabytes. Down the line, we could perhaps add a `glnx_copy_bytes_cancellable()` that only did that check e.g. every gigabyte of copied data. And when we do that we should use `g_cancellable_set_error_if_cancelled()` rather than a `poll()` with the regular file FD, since regular files are *always* readable and writable. For my use case with rpm-ostree though, we don't have gigabyte sized files, and seeing all of the `poll()` calls in strace is annoying. So let's have the non-cancellable file copying API that's modern and uses both reflink and `sendfile()` if available, in that order. My plan at some point once this is tested more is to migrate this code into GLib. Note that in order to keep our APIs consistent, I switched the systemd-imported code to "old school POSIX" error conventions. Otherwise we'd have *3* (POSIX, systemd, and GError) and particularly given the first two are easily confused, it'd be a recipe for bugs.
* fdio: Mostly port to new code styleColin Walters2017-04-251-149/+59
| | | | | | | | | | There's one function that did `unlinkat()` in the cleanup section, not doing that yet. Note I uncovered a few bugs in a few places where we didn't preserve errno before doing an `unlinkat()` in error paths in a few cases. I also tried to prefix a few more error cases with the system call name.
* Port most code (except fdio) to new styleColin Walters2017-04-253-80/+31
| | | | There's a lot more fdio code, starting with some of the easier ones.
* tests/xattrs: Skip on filesystems with no user xattr supportColin Walters2017-04-211-0/+15
| | | | | | Like tmpfs. See: https://github.com/flatpak/flatpak/issues/686
* glnx-fdio: Add wrappers around fstat() and fstatat() to handle errorsPhilip Withnall2017-04-211-0/+51
| | | | | | | | Add two inline wrappers around fstat() and fstatat() which handle retrying on EINTR and return other errors using GError, to be consistent with other glnx functions. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* glnx-dirfd: Add variants of glnx_mkdtempat() which open the directoryPhilip Withnall2017-04-212-0/+78
| | | | | | | | 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>
* glnx-shutil: Add glnx_shutil_mkdir_p_at_open()Philip Withnall2017-04-212-0/+45
| | | | | | | | | 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: Philip Withnall <withnall@endlessm.com>
* glnx-local-alloc: Make check for invalid FDs more generalPhilip Withnall2017-04-211-2/+2
| | | | | | | | In general, all FDs < 0 are invalid (and should not have close() called on them), so check that. This could have caused problems if a function returned an error value < -1. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* errors: Fix legacy set_prefix_error_from_errno()Colin Walters2017-03-242-4/+8
| | | | | | | We were missing the previous automatic `: ` addition; noticed in a failing ostree test. Fix this by just calling the new API as the non-prefix case does too.
* glnx-errors.h: add glnx_null_throw[_*] variantsJonathan Lebon2017-03-233-8/+62
| | | | | | | | | | | | | | | | | | | | | | | These are equivalent to the non-null throw, except that the returned value is a NULL pointer. They can be used in functions where one wants to return a pointer. E.g.: GKeyFile *foo(GError **error) { return glnx_null_throw (error, "foobar"); } The function call redirections are wrapped around a compound statement expression[1] so that they represent a single top-level expression. This allows us to avoid -Wunused-value warnings vs using a comma operator if the return value isn't used. I made the 'args...' absorb the fmt argument as well so that callers can still use it without always having to specify at least one additional variadic argument. I had to check to be sure that the expansion is all done by the preprocessor, so we don't need to worry about stack intricacies. [1] https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
* errors: Add glnx_throw() and testsColin Walters2017-03-223-1/+109
| | | | | | | | Following up to the previous commit, also shorten our use of `g_set_error (..., G_IO_ERROR_FAILED, ...)`. There's a lot of this in libostree at least. See also https://bugzilla.gnome.org/show_bug.cgi?id=774061
* errors: Add new glnx_throw_errno{,_prefix}() APIsColin Walters2017-03-223-40/+80
| | | | | | | | | | | | | | | | | | | | 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); ```
* fdio: Expose wrappers for renameat2() EXCHANGE and NOREPLACEColin Walters2017-03-025-22/+236
| | | | | | | | | | | I want the `RENAME_EXCHANGE` version for rpm-ostree, to atomically swap `/usr/share/rpm` (a directory) with a new verison. While we're here we might as well expose `RENAME_NOREPLACE` in case something else wants it. These both have fallbacks to the non-atomic version. Closes: https://github.com/GNOME/libglnx/pull/36
* fix bug found by -Wmaybe-uninitializedJonathan Lebon2017-03-021-1/+1
|
* tests/xattrs: Fix possible NULL allocationColin Walters2017-02-211-1/+1
| | | | | | | | This showed up in the ostree runs with `-fsanitize=undefined` - if we happened to get `0` then `g_malloc` would return `NULL`. However, what's interesting is it seemed to happen *consistently*. I think what's going on is GCC proved that the value *could* be zero, and hence it *could* return NULL, and hence it was undefined behavior. Hooray for `-fsanitize=undefined`.
* COPYING: Bump to LGPL 2.1 due to systemd importColin Walters2017-02-111-91/+112
| | | | | | | | | | | We originally inherited LGPL 2.0 from glib I think. But I didn't notice when importing systemd code it's LGPL 2.1. While individual file licenses still apply; I'm not going to bother bumping all of them to 2.1, the complete module should be viewed as under 2.1. Bump the master COPYING file accordingly.
* xattrs: Add a test case for previous commitsColin Walters2017-01-292-0/+289
| | | | | This is actually the first test case in libglnx 🙌; hopefully the consumers are prepared for us injecting into `TESTS`.
* xattrs: Handle ERANGEColin Walters2017-01-291-0/+6
| | | | | This is symmetric with an earlier commit which handled a transition from `size != 0` -> `size = 0`. Now if xattrs are added we retry.
* xattrs: Dedup fd reading codeColin Walters2017-01-291-57/+18
| | | | | | | By taking both fd and path into one copy of the reader func, exactly like we do in `read_xattr_name_array`, we can abstract over the difference. Preparatory cleanup for more work here.
* xattrs: Handle xattrs changing size concurrentlyColin Walters2017-01-291-11/+18
| | | | | | We should be robust in the face of this and return a snapshot of the current value we saw, not transiently fail. This is the semantics we expect with ostree upgrades for `/etc` for example.
* listxattr: Don't assume that first call to listxattr gives correct sizeWilliam Manley2017-01-291-12/+20
| | | | | | | | | | | | | | | To get the right sized buffer to pass to `flistattr` and `llistattr` we first call them with a zero byte buffer. They then return the number of bytes they'll actually need to operate. We would `malloc` and then call again assuming that the size we got originally was correct. On my computer at least this isn't always the case. I've seen instances where the first call returns 23B, but then on the second one returns no data at all. Getting these non-existant xattrs would then cause ostree to fail. I'm not sure why it's behaving this way on my machine. I suspect its some interaction with overlayfs but I haven't proven this.
* 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.
* fdio: Make GLnxFileCopyFlags actually flagsColin Walters2016-10-251-3/+3
| | | | | | | | | I wanted to add a new one, and realized it was wrong. Luckily, I think we were safe until now, since the set of bits for `(0, 1, 2)` is actually distinct. Although, hm, callers specifying `GLNX_FILE_COPY_OVERWRITE` may have not actually been getting that.