Commit Graph

87 Commits

Author SHA1 Message Date
Colin Walters
4ae5e3beaa libcontainer: Add a fd-relative API
I'm porting rpm-ostree and need this.  Of course all this libcontainer
stuff will be nuked in favor of bubblewrap when everything comes
together.
2016-08-07 07:29:48 -04:00
Simon McVittie
871617d519 Add missing files to libglnx distribution
Signed-off-by: Simon McVittie <smcv@debian.org>
2016-08-05 14:38:18 +01:00
Colin Walters
5ac0d702d7 fdio: Only invoke fallocate() for sizes > 0
In some cases we want to replace with zero size, and `posix_fallocate()`
is documented to return `EINVAL` in this case.

Making this change since I noticed it elsewhere.
2016-08-04 14:42:59 -04:00
Colin Walters
c2ba4d8799 Add --disable-otmpfile
Some systems have bugs with it, so let's allow downstreams to easily
disable it.

https://bugzilla.gnome.org/show_bug.cgi?id=769453
https://github.com/ostreedev/ostree/issues/421
2016-08-03 11:39:16 -04:00
Colin Walters
80e5af9218 shutil: Use new API to iterate ensuring d_type
This drops a lot of duplicate code.
2016-07-29 13:08:17 -04:00
Jonathan Lebon
c072ef1eba text_percent_internal: compare uints before printing
A wild sordid tale of substractions and unsigned integers leads this
team of variables down a loonng path...

Reported-by: Gatis Paeglis <gatis.paeglis@qt.io>
2016-07-22 09:36:51 -04:00
Colin Walters
d2e588d94f fdio: Add unlinkat() in error paths for tmpfiles
This is kind of an ABI change but it's for the better I think; on
error we consistently clean up the temp file.

This is obviously necessary without `O_TMPFILE`.  With it, we still
need an error cleanup in the case where we're trying to replace an
existing file.  I noticed this in ostree's `tests/test-refs.sh` which
intentionally tries to rename a file over a directory path.
2016-07-08 13:10:40 -04:00
Colin Walters
78ae787757 fdio: Use correct dfd with O_TMPFILE in rename case
While auditing this code to figure out why ostree's
`tests/test-refs.sh` was failing, while the bug turned out to be
different, I noticed that in the case where `dfd != target_dfd`, we
failed to do the right `renameat()`.  (No code I'm aware of does this
now).
2016-07-08 13:09:19 -04:00
Colin Walters
113c770dc1 fdio: Add open_tmpfile_linkable() and link_tmpfile_at()
We had a bug previously where we failed to clean up a temporary file
in an error path.  This is a classic case where the new `O_TMPFILE`
API in Linux is nicer.

To implement this, as usual we start with some original bits from
systemd.  But in this case I ended up having to heavily modify it
because systemd doesn't support "link into place and overwrite".  They
don't actually use their tempfile code much at all in fact - as far as
I can tell, just in the coredump code.

Whereas in many apps, ostree included, a very common use case is
atomically updating an existing file, which is
`glnx_file_replace_contents_at()`, including subtleties like doing an
`fdatasync()` if the file already existed.

Implementing this then is slightly weird since we need to link() the
file into place, then rename() after.

It's still better though because if we e.g. hit `ENOSPC` halfway
through, we'll clean up the file automatically.

We still do keep the mode where we error out if the file exists.
Finally, the ostree core though does have a more unusual case where we
want to ignore EEXIST (allow concurrent object writers), so add
support for that now.

Note: One really confusing bug I had here was that `O_TMPFILE` ignores
the provided mode, and this caused ostree to write refs that weren't
world readable.

Rework things so we always call `fchmod()`, but as a consequence we're
no longer honoring umask in the default case.  I doubt anyone will
care, and if they do we should probably fix ostree to consistently use
a mode inherited from the repo or something.
2016-07-01 15:03:01 -04:00
Alexander Larsson
4f83b70f69 glnx_release_lock_file - Don't close fd -1 (i.e. if we never locked)
This happens a lot if you use autocleanup for lock files, and the
function returns early without the lock being taken.
2016-06-28 11:23:47 +02:00
Yu Qi Zhang
a6d08657aa fdio: Delete .tmp file on failure
We noticed the temp files being left over in ostree when (mistakenly)
trying to replace the contents of a subpath that wasn't a directory.

In the future we should look at the systemd code using `O_TMPFILE`
here.
2016-06-16 13:58:55 -04:00
Colin Walters
afe3c3a861 dirfd: Fix inverted precondition in previous tmpname commit
I swear I tested it...
2016-05-31 09:29:08 -04:00
Colin Walters
4919f6ee68 Introduce glnx_gen_temp_name()
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
2016-05-30 11:22:23 -04:00
Jonathan Lebon
40ef5f7400 text_percent_internal: only pad right in the text case
Padding in the percentage case was useless (and actually didn't work
properly) since all the real estate is taken up by the text and the bar.
We only need padding in the text case, in case the new string is
shorter.
2016-05-10 14:01:40 -04:00
Colin Walters
3d162e772d fdio: Add glnx_stream_fstat
Migrated from libgsystem's `gs_stream_fstat()`.  It's a small function
but I end up using it in OSTree a fair bit.
2016-05-03 17:23:17 -04:00
Colin Walters
85c9dd5c07 libcontainer: Always set PATH when running in new root
For rpm-ostree's use we always run in a new root, so we don't want to
inherit the host system's PATH.  For example, NixOS uses PATH for its
software namespacing, but one could be using rpm-ostree to build
CentOS commits.
2016-05-02 10:38:16 -04:00
Colin Walters
47ddbfa563 console: Fix glnx_console_text
Not sure if it ever worked.  We need to not print the bars, etc.
2016-05-01 14:22:25 -04:00
Alexander Larsson
69d8a597f7 Don't touch errno in glnx_fd_close
We're ignoring the result from the close, but it can still affect
errno, which is bad if you use this in functions that sets
errno, because errno can unexpectedly change after you've set it.
2016-03-10 23:12:07 +01:00
Colin Walters
08ae6639e5 console: Add an API to just emit text
We had this internally, just need to expose it.
2016-03-10 13:51:13 -05:00
Colin Walters
8a7943fef6 console: Fix bar progress length
The previous fix added the last character of text, but failed to
account for the space we're adding.
2016-02-08 14:09:13 +01:00
Colin Walters
769522753c console: Don't delete last character of output text
Not sure why we were doing this...I guess people were working around
it by adding their own spaces?
2016-01-26 11:16:56 -05:00
Colin Walters
34a96c03dd console: Fix g_auto() and unlock cleanup
This way, one can unlock the console while still using the cleanup
macro.  Otherwise we miss a lot of the ergonomics of cleanup macros.
2016-01-25 11:25:19 -05:00
Colin Walters
aac5a6cef7 console: g_auto() macro no-ops if console is not locked
Otherwise we miss a lot of the ergonomics of cleanup macros.
2016-01-25 10:23:34 -05:00
Colin Walters
2ca280f012 Introduce glnx-alloca.h with glnx_strjoina()
This is taken from systemd, and is really useful when one has a few
known-to-be-small strings one wants to concatenate without resorting
to malloc.
2016-01-24 12:10:26 -05:00
Alexander Larsson
194eb7a09c Add autoptr support for GZlib* 2016-01-22 15:27:11 +01:00
Colin Walters
3c470803d0 fdio: Export loop_write
I plan to use this in rpm-ostree.  Sad how many times this gets
reinvented.  Should probably stick a copy in `glib-unix.h` or so.
2016-01-10 21:46:45 -05:00
Colin Walters
91e060699f dirfd: Add a public API to ensure a filled dtype
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.
2016-01-02 19:42:53 -05:00
Alexander Larsson
e7f7081054 autocleanups: Fix g_autoptr(GString) with glib 2.44
The g_autoptr support for GString was added in 2.45.8, so we need
to define it on 2.44 for it to work.
2015-12-17 13:29:08 +01:00
Alexander Larsson
0313864129 Add glnx_mkdtempat
Create a temporary directory using mkdirat.

https://bugzilla.gnome.org/show_bug.cgi?id=757611
2015-12-11 16:22:07 +01:00
Alexander Larsson
4e9969998b Add glnx_steal_fd
This is very useful in combination with glnx_close_fd

https://bugzilla.gnome.org/show_bug.cgi?id=757611
2015-12-11 16:22:07 +01:00
Colin Walters
bf4d1504a4 README.md: Add note on contributing 2015-12-02 09:59:10 -05:00
Alexander Larsson
1d65bc0ff7 Add backport of g_set_object 2015-12-01 16:32:59 +01:00
Alexander Larsson
dade12b558 Add g_autoptr support for GSubprocess 2015-12-01 16:32:55 +01:00
Matthew Barnes
7e24c244ff Backport g_autoptr support for GFileOutputStream 2015-11-23 14:47:34 -05:00
Matthew Barnes
825d308b04 Comment typo 2015-11-06 10:31:37 -05:00
Matthew Barnes
c7da81208d Backport g_autoptr support for GCancellable 2015-11-06 09:57:30 -05:00
Alexander Larsson
7310bbdb58 Backport g_autoptr support for GString 2015-09-24 15:28:21 +02:00
Matthew Barnes
e684ef07f0 libcontainer: Set PATH when using execvp()
Set PATH to something sane for a chroot'ed environment rather than
relying on the user's PATH value.
2015-09-16 14:14:43 -04:00
Colin Walters
0cf50c6735 Add a generic glnx-backports.h
Where we can put general functions that come in newer glib.
2015-08-29 09:29:11 -04:00
Colin Walters
dc5702aba9 backport-autocleanups: Add GDBusConnection,GDBusMessage 2015-08-28 13:10:01 -04:00
Colin Walters
fbdb15cd95 libcontainer: Pare down to just "run in root" API
rpm-ostree is going through some awkwardness trying to
support being run both inside and outside of a container.

For now, let's drop all recursive container usage.  There is still
some value in readding this in the future - for example, downloading
packages requires networking, but `%post` scripts do not.  But we
should really solve that when we return to running unprivileged or the
like.
2015-08-24 14:29:45 -04:00
Colin Walters
58a9a5c50e libcontainer: Fall back to noop if / is not a mountpoint
Trying to change the mount namespace was breaking in mock, which just
uses plain chroot.
2015-07-28 16:40:29 -04:00
Colin Walters
91875459cd libcontainer: Search $PATH for exec() if argv[0] is not absolute
In Fedora rawhide, dracut switched from `/usr/sbin` to `/usr/bin`,
which broke rpm-ostree's hardcoding of the path.

There was no real reason to hardcode it (assume our `$PATH` is sane
and secure), so in order to help support that, this change in libglnx
will automatically search $PATH if the input is not absolute.

(This is a sane default for a process spawning library IMO)
2015-06-15 13:38:43 -04:00
Colin Walters
900b25f701 backport-autocleanups: GTask
For OSTree.
2015-05-08 22:02:44 -04:00
Giuseppe Scrivano
cf8ae27bab glnx-fdio: always initialize buf
It can be used without initialization if condition causing a "goto
error" fails before buf is initialized.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-05 16:39:12 +02:00
Matthew Barnes
013aa4fead Backport all the GIO object types used by OSTree 2015-05-05 10:26:33 -04:00
Colin Walters
be6bc2d75d lockfile: New code to lock files, massaged from systemd
Will be used by OSTree to lock the sysroot against concurrent
manipulation.  Taken from current systemd git master, tweaked to
GLibify.
2015-05-05 08:49:00 -04:00
Colin Walters
fda8f26625 README.md: Some more rationale 2015-05-04 16:10:28 -04:00
Matthew Barnes
dfe77be2d5 Backport more autocleanup types from GLib
GStrv, GFile, GOutputStream
2015-05-04 11:58:09 -04:00
Colin Walters
90390949f2 fdio: glnx_file_copy_at: If no stbuf passed, do stat internally
There are some cases where we want to copy with just a filename,
so let's be convenient in that case and do stat for the caller.

This will be used by an ostree commit.
2015-04-20 22:10:07 -04:00