Skip to content
Snippets Groups Projects
  1. Sep 13, 2017
    • Colin Walters's avatar
      tests: Add macro for auto-error checking · c2bcca04
      Colin Walters authored
      Having our tests forced into a `goto out` style is seriously annoying
      since we can't write tests like we write production code.  Add
      a macro that checks for the error being NULL.
      
      This doesn't fully solve the problem since the test functions are
      still forced into `void` returns; at some point I may extend
      GLib to have `g_test_add_err_func()`.
      c2bcca04
  2. Sep 12, 2017
    • Colin Walters's avatar
      fdio: Use O_TMPFILE + rename-overwrite for regfile copies · 673f48f6
      Colin Walters authored
      I was working on rpm-ostree unified core, and hit the fact that
      `glnx_file_copy_at()` had the same bug with `fsetxattr()` and files whose mode
      is <= `0400` (e.g. `000` in the case of `/etc/shadow`) that libostree did a
      while ago.  Basically, Linux currently allows `write()` on non-writable open files
      but not `fsetxattr()`.  This situation is masked for privileged (i.e.
      `CAP_DAC_OVERRIDE`) code.
      
      Looking at this, I think it's cleaner to convert to `O_TMPFILE` here,
      since that code already handles setting the tmpfile to mode `0600`.  Now,
      this *is* a behavior change in the corner case of existing files which
      are symbolic links.  Previously we'd do an `open(O_TRUNC)` which would follow
      the link.
      
      But in the big picture, I think the use cases for `open(O_TRUNC)` are really
      rare - I audited all callers of this in ostree/rpm-ostree/flatpak, and all of
      them will be fine with this behavior change. For example, the ostree `/etc`
      merge code already explicitly unlinks the target beforehand. Other cases like
      supporting `repo/pubring.gpg` in an ostree repo being a symlink...eh, just no.
      
      Making this change allows us to convert to new style, and brings all of the
      general benefits of using `O_TMPFILE` too.
      673f48f6
    • Colin Walters's avatar
      fdio: Support taking ownership of tmpfile fd · 9d995a36
      Colin Walters authored
      While reading a strace I noticed a double close in the tests; this was because
      we were missing an assignment to `-1` in the tests. However, let's make
      supporting this clearer by explicitly supporting the fd being `-1` while still
      setting the `initialized` variable to `FALSE`. We also add the `EBADF` assertion
      checking.
      9d995a36
  3. Sep 07, 2017
    • Colin Walters's avatar
      fdio: Add glnx_fstatat_allow_noent() · 627d4e2f
      Colin Walters authored
      This is a very common pattern in both ostree/rpm-ostree. Make a better API for
      this. I thought a lot about simply zeroing out `struct stat` but that feels
      dangerous; none of the values have seem obviously `cannot be zero`.
      627d4e2f
  4. Jul 24, 2017
  5. Jul 17, 2017
    • Colin Walters's avatar
      fdio: Add cleanup+flush API for FILE* · e30a773f
      Colin Walters authored
      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.
      e30a773f
  6. Jul 10, 2017
  7. Jun 28, 2017
  8. Jun 26, 2017
  9. Mar 02, 2017
Loading