Commit Graph

2119 Commits

Author SHA1 Message Date
Jonathan Lebon
4624c3bdf8 app/db: Add db diff --advisories
This will be used by at least coreos-assembler to store in `meta.json`
so it's easy to tell new advisories that appeared in a given build.
2021-04-06 17:04:51 -04:00
Jonathan Lebon
136a3ea7e9 app/db: Add db list --advisories
This makes it easy to see the advisories stored in commit metadata.
2021-04-06 17:04:51 -04:00
Jonathan Lebon
427fe683a8 compose: Bake advisory information into commit metadata
There are a lot of use cases for this, notably:
- This allows us to display advisories without fetching updateinfo
  metadata in the pure OSTree case.
- It allows pipelines to fetch and display this information to
  sanity-check builds.
- It makes it much easier to fix the "intermediate CVEs" issue described
  in https://github.com/coreos/rpm-ostree/issues/1696#issuecomment-443861107.

This patch just adds the advisory information to the commit metadata.
There's follow-up work to make the client-side of rpm-ostree use this
data.

Also, remove the newly added metadata from the output of `rpm-ostree
status --json` for the same reason we remove the rpmdb. A follow-up
patch will teach `rpm-ostree db list/diff` to output advisories.

Closes: #1696
2021-04-06 17:04:51 -04:00
Luca BRUNO
d922f46bfd libpriv/json-parsing: remove dead code
This removes some JSON-handling helper methods which are not used
anymore. All the consumers have been moved to directly use the
treefile logic in Rust in the meanwhile.
2021-04-05 13:43:58 -04:00
Jonathan Lebon
b7a27e2328 app/clientlib: Support printing advisories without padding 2021-04-05 13:31:25 -04:00
Jonathan Lebon
4185178be7 app/clientlib: Make function for printing advisories public
We'll use this in a future patch.
2021-04-05 13:31:25 -04:00
Jonathan Lebon
6df0efb0c6 libpriv/util: Add g_variant_byteswap helpers
Will use these in a future patch.
2021-04-05 13:31:25 -04:00
Jonathan Lebon
4c5436e666 daemon: Move advisory GVariant generation to libpriv
Prep for future patch.
2021-04-05 13:31:25 -04:00
Ukpai Ugochi
695312fc43 Help text on error: Transaction in progress #2341
This is a feature request, to add help text to get new users unblocked.
2021-03-30 08:37:35 -04:00
Colin Walters
eba911c00a Migrate depmod helper to core.rs
Since it's called from both client and compose side, it should be
in core.  Migrate to Rust too.
2021-03-29 16:43:19 +00:00
Jonathan Lebon
be4fe77ebb
Merge pull request #2692 from cgwalters/bwrap-rs 2021-03-29 12:42:18 -04:00
Colin Walters
a07e331eb1 compose: Fix leak of Rust treefile object
I did at one point look at converting this stuff into a C++
object but that led in to a whole rathole around a C++ `GObject<>`
smart pointer like glibmm has.  But that would take over the code
and it's better to just port to Rust.
2021-03-29 14:51:47 +00:00
Colin Walters
fa81456cbf Rewrite bwrap code in Rust
I tried to do this incrementally but it snowballed.
2021-03-29 14:45:35 +00:00
Colin Walters
40dc281e5e bwrap: Initial Rust stub
This compiles and demonstrates moving a little bit of the bwrap
code to Rust.
2021-03-29 14:44:09 +00:00
Colin Walters
a7edfb6293 Add a helper API to detect running in systemd
Use it instead of detecting the journal; we *could* do that
by checking the `JOURNAL_STREAM` variable:
https://www.freedesktop.org/software/systemd/man/systemd.exec.html#%24JOURNAL_STREAM

But, really none of our code cares about this today;
anyone running `rpm-ostree compose tree` under e.g.
`systemd-run` can keep both pieces.
2021-03-26 14:29:53 +00:00
Alexander Wellbrock
a1197d8d93 Fix ambigous compose postprocess man entry
The resulting man-page entry was
'compose postprocess [OPTION…] postprocess ROOTFS [TREEFILE]'
2021-03-25 08:32:10 -04:00
Jonathan Lebon
3dda1a33b4
Merge pull request #2689 from cgwalters/bwrap-rs-prep2
bwrap,scripts: Add and use cleaner APIs for standard descriptors
2021-03-23 11:54:09 -04:00
Jonathan Lebon
0fd82990c7
Merge pull request #2691 from cgwalters/strip-remote-error
clientlib: Strip GDBus remote error before throwing exception
2021-03-23 10:49:45 -04:00
Colin Walters
7ec7e3eb28 clientlib: Strip GDBus remote error before throwing exception
In general our error handling philosophy is "errors are strings".
Previously (before C++) we were relying on calling this API
to strip out the GDBus remote error message.

In the recent refactoring of clientlib to expose the txn APIs
to Rust via C++, we implicitly lost that because the C++
wrapper API throws an exception.

Add a copy of the remote error stripping here.  Eventually
it will likely make sense for it to *only* be here instead
of also in `main.cxx`, but one thing at a time.
2021-03-22 19:30:49 +00:00
Colin Walters
df6c916808 bwrap,scripts: Add and use cleaner APIs for standard descriptors
Port away from a generic child setup function towards more standard
APIs for setting up fd streams.  Prep for oxidizing rpmostree-bwrap.cxx
because cxx-rs doesn't support passing callbacks from C++ to Rust.
2021-03-22 19:11:54 +00:00
Jonathan Lebon
7979e250ee lockfile: Allow locking by source RPM EVR
Right now if we want to lock e.g. systemd, we need to specify every
subpackage of systemd that we use. This is a lot of duplication because
in the majority of cases, what we really mean is "lock at this build of
systemd".

Since RPMs bake in the source RPM they were built from, we can use this
to lock packages more succinctly. See the testcase and #2676 for
examples of how this looks.

Closes: https://github.com/coreos/rpm-ostree/issues/2676
2021-03-22 12:57:49 -04:00
Jonathan Lebon
9dee0962a1
Merge pull request #2685 from cgwalters/bwrap-rs-prep
kernel: Avoid using bwrap child setup
2021-03-22 12:15:31 -04:00
Colin Walters
61e7d6a37f postprocess: Migrate mutate-os-release to Rust
Required binding a bit more of the bwrap bits.
2021-03-22 13:06:46 +00:00
Luca BRUNO
42d86d6895 libpriv/passwd: move pre-commit validation hooks to Rust
This moves the users/groups validation logic to Rust, taking care of
all the treefile check-passwd/check-groups knobs.
As all the passwd-handling logic has been ported to Rust, it also
drops the stale C source/headers/imports.
2021-03-22 09:02:01 -04:00
Colin Walters
ae881b991b kernel: Avoid using bwrap child setup
Prep for porting rpmostree-bwrap.cxx to Rust; cxx-rs doesn't
expose passing a function pointer from C++ to Rust.  There's
a simpler API for this anyways.
2021-03-22 13:00:27 +00:00
Colin Walters
ae3c1bc9a7 compose: Move remove-files code to Rust
More oxidation.
2021-03-18 18:05:34 +00:00
Colin Walters
7f9129d67d compose: Move mutate-os-release string code to Rust
More classic C string manipulation which is much nicer in Rust
2021-03-18 18:05:34 +00:00
Luca Bruno
b5d6b8266c
Merge pull request #2669 from cgwalters/more-postprocess-rs-2
More postprocess rs 2
2021-03-17 09:01:29 +00:00
Colin Walters
4c5bb4f216 Move units and default-target processing to Rust
More oxidation.
2021-03-16 23:44:55 +00:00
Colin Walters
1c5c8fa9c5 postprocess: Remove redundant renames of etc -> usr/etc
Now that we've shrunk this code, two bits that
require renaming `etc` are adjacent and we don't need to rename
it twice.
2021-03-16 23:24:22 +00:00
Colin Walters
9ee27a61ca postprocess: Move rpmdb symlink to Rust
More oxidation.
2021-03-16 23:20:02 +00:00
Timothée Ravier
5d5ccf019f Install a temporary copy of rpm-ostree for unprivileged use
Install a copy of rpm-ostree as rpm-ostree-unpriv to get a `bin_t`
labeled binary as a temporary workaround for:
https://bugzilla.redhat.com/show_bug.cgi?id=1937404

Also modify the rpm-ostree count me service to use that binary.
2021-03-16 19:07:20 -04:00
Timothée Ravier
f7fd114f11 rpm-ostree-countme.timer: Fix AccuracySec and add OnBootSec
* Use OnBootSec=5m to give a chance for the timer to trigger on the
    first week the system is booted up.
  * Use '1s' for AccuracySec as this is accurate enough for this use
    case.
2021-03-16 19:07:20 -04:00
Timothée Ravier
3929e38ac0 Remove rpm-ostree sysusers config 2021-03-16 19:07:20 -04:00
Colin Walters
fad4ff66c3 postprocess: Use a single entrypoint to Rust
It's a bit silly to have a two bridged functions here; instead
have just a single one on the C++ side that calls multiple
on the Rust side.

Prep for moving more to Rust.
2021-03-16 22:19:53 +00:00
Luca Bruno
35c31205a6
Merge pull request #2664 from cgwalters/postprocess-rs-more
Various postprocess oxidation patches
2021-03-16 08:47:11 +00:00
Luca BRUNO
efb50f5cc1 passwd: minor cleanups
This contains a couple of minor code cleanups, left over from previous
reviews.
2021-03-15 15:32:44 -04:00
Jonathan Lebon
c41adb0ad2
Merge pull request #2648 from cgwalters/deployment-status-cleanup
Move some small daemon layering lookup into Rust
2021-03-15 14:11:56 -04:00
Colin Walters
a0acdb596d Move writing /usr/share/rpm-ostree/treefile.json to Rust
More oxidation.  Also with a quick unit test now.
2021-03-15 13:18:57 +00:00
Colin Walters
9ad499ffd3 Move units/machineid-compat checking to treefile in Rust
More oxidation.
2021-03-15 13:18:57 +00:00
Colin Walters
3e856cb3be postprocess: Move treefile externals sanitycheck to Rust
This code really makes sense as a method on the treefile.

And when that's done, we no longer need to expose
`get_postprocess_script()` via cxx, so we can return a nicely
Rust native `Option<&mut File>`.
2021-03-15 13:18:57 +00:00
Colin Walters
62b47c64c6 postprocess: Move add-files handling to Rust
Port add-files handling to Rust.

Note that there's one very magical line of diff here worth calling out:
We dropped an interface from the cxxrs bridge, because both sides
are now Rust!  The treefile code can directly return an `&mut File` reference
instead of needing to pass the raw fd as `i32`.
2021-03-15 13:18:57 +00:00
Colin Walters
ac92456bdd postprocess: Move script execution to Rust
Continuing oxidation.
2021-03-15 13:18:57 +00:00
Colin Walters
1b3bdc243e Move high level bwrap postprocess interface to C++
A future patch will then expose this interface via cxxrs, allowing
us to port more of the postprocess.cxx code to Rust.
2021-03-15 13:18:57 +00:00
Colin Walters
c675b385c7 Oxidize postprocessing altfiles addition to /etc/nsswitch.conf
The ugly C code for this turns into shorter Rust with a unit
test, a lot less allocation (notice how we don't malloc `NUL` terminated
strings in so many places).
2021-03-12 23:10:33 +00:00
Jonathan Lebon
5f17bc5c87 lockfile: Return LockfileConfig rather than Vec<StringMapping>
I don't like the use of `HY_GLOB` in the lockfile package matching. We
have all the information in the Rust object, so it's silly to condense
that to a single string in a hashmap.

Fix this by returning the `LockfileConfig` object itself and then adding
a function to fetch the list of locked packages. This allows the C++
side to see all the individual fields which makes filtering trivial.

The next step is moving all the code which needs the lockfile to Rust.
Then we can drop the shared `LockedPackage` type.

(I did start on converting `find_locked_packages`, though it requires
adding bindings for all the `HyQuery` stuff, which...  isn't great (and
also runs into the fact that `hy_query_run` needs to return a
GPtrArray). I think instead of a 1:1 mapping, we'll probably want the
libdnf-sys API wrappers to provide some sugar for the common paths.)
2021-03-11 00:01:46 +01:00
Jonathan Lebon
c03f5d50a3 lockfile: Drop ror_ prefix
That's a cbindgen-era thing.
2021-03-11 00:01:46 +01:00
Jonathan Lebon
2fedc3b0ac lockfile: Allow specifying EVR rather than EVRA
In FCOS, we use "override" lockfiles to pin packages to certain
versions. Right now, we have separate overrides for each base arch we
(eventually want to) support. But that makes maintaining the overrides
cumbersome because of all the duplication.

Let's allow lockfiles to specify only the `evr` of a package, which is
just as good for FCOS, and means that we'll only have to maintain a
single override file for all the architectures.
2021-03-11 00:01:46 +01:00
Colin Walters
e02fff3d5a Move some small daemon layering lookup into Rust
Prep for more oxidation work.  One notable improvement here is that about half
of the callers of the mega function `rpmostree_deployment_get_layered_info`
only wanted the base information, not the layered package lists
for example - so we were passing 4 `NULL`s to ignore those.

This Rust API returns a simple shared struct instead for those
cases.  I also changed things so that `base_commit` is always
set, avoiding the callers needing to do that.
2021-03-08 23:01:50 +00:00
Colin Walters
3041d648bb install: Add --apply-live
OK I think it's time.  This exposes the `apply-live` functionality
as implicitly stable, but specific to the package install case.

I'd like to add more intelligence to `apply-live` around separating
pure "additions" (as in this case) versus package (file) changes.

The change here doesn't try to do that; the implementation is
incredibly simple, we just have the client chain together the two
distinct transactions.
2021-03-08 20:54:18 +01:00
Colin Walters
b0eccadb22 live: Pass options GVariant down
I have no idea why I didn't do this originally, it's much
cleaner than parsing the options in C.
2021-03-08 20:54:18 +01:00
Colin Walters
01b59f20ba daemon: Move a bit more deployment-variant code to Rust
These are "base ostree" things we can move into the Rust
function.
2021-03-08 19:58:18 +01:00
Jonathan Lebon
175de36732 compose/extensions: Handle no --base-rev
In this case, let's default to the tip of the tree ref.

Closes: #2633
2021-03-07 19:46:52 -05:00
Jonathan Lebon
0f8dd0344d app/override: Hint at rpm-ostree override reset
It's always nice when apps provide useful hints about other commands you
may be interested in.

For instance, if they've done `rpm-ostree override replace/remove`,
let's be helpful and tell users that they can use `rpm-ostree override
reset` to unpin packages.
2021-03-05 19:04:06 -05:00
Colin Walters
13804d84a1 Add more client Rust bindings, port apply-live builtin
This adds sufficient infrastructure to fully port the
`rpmostree-builtin-applylive.cxx` client code to Rust.
We just keep a stub entrypoint for now until we port
the rest of `rpmostree-builtin-ex.cxx`, at which point
a lot of C++ files go away.

The "finish" bits move from the daemon-oriented `live.rs`
into a new `rust/src/builtins` directory.  I'd like
to try to more cleanly split up the Rust sources along
core(shared)/client/daemon directories in the future.
2021-03-04 09:17:21 -05:00
Colin Walters
6fd9db246a Add basic Rust CLI bindings for DBus
This stubs out sufficient infrastructure for us to register
as a client and call the Moo API.

A glaring problem here is the lack of extensive `glib::Variant`
bindings; that's covered in the next gtk-rs release.

My real goal was to try porting the `rpmostree-builtin-apply-live.cxx`
code entirely to Rust, but there's more to do to expose the
transaction helper APIs we have.
2021-03-04 09:17:21 -05:00
Colin Walters
283824c6cb app: Factor out a helper function to register as a client
Prep for exposing just this functionality via cxxrs so we
can more easily write CLI entrypoints in Rust.
2021-03-04 09:17:21 -05:00
Colin Walters
e21914f677 app: Rename dbus-helpers to clientlib
Originally it was dbus helpers, but it grew into "shared code for client",
so let's name the file better.
2021-03-04 09:17:21 -05:00
Colin Walters
8dd5583ae9 Remove cbindgen
We have fully transitioned to cxx-rs!  This drops a lot of now
dead code; only one binding system to think about generating
source code.  For example, a notable advantage of cxx-rs
is it doesn't scan the whole source code, so running `make`
doesn't spew errors from cbindgen not understanding bits.
2021-03-03 16:51:38 -05:00
Colin Walters
60e605b34e Introduce CxxGObjectArray, use in lockfile code
cxx-rs only supports a few basic types in `Vec<T>`/`CxxVector<T>`
and we need to pass an array of GObjects in a few cases.
Add a wrapper class hack instead of using `u64` so we at least
have some basic safety here and have a convenient place to
grep for later when we want to improve this.
2021-03-02 16:25:32 -08:00
Jonathan Lebon
5c1911445c Finish moving lockfile to cxx.rs
This moves the `ror_lockfile_write` to cxx.rs, which brings us closer to
getting rid of cbindgen now.

There's one massive hack this uses, which is that we pass an array of
pointers to `DnfPackage` and `DnfRepo` objects as u64. We'll want to
circle back and fix that up once either cxx.rs supports natively arrays
of pointers, or we just come up with our own wrapper type for it.

But for now at least, this unblocks the cbindgen transition and hacking
on the lockfile code.
2021-03-02 16:25:32 -08:00
Colin Walters
b0780f0efd ex: Drop erroneous REQUIRES_ROOT flag on apply-live, initramfs-etc
These commands use DBus so fall under the usual polkit usage,
there's no reason to hard require root.  I think this was a copy-pasta.
2021-03-01 19:53:50 +01:00
Colin Walters
2b294d68bd client: Remove peer_pid value from option parsing
Instead of passing the pid back up the stack and using a cleanup
function on it to invoke `kill()`, use `PR_SET_PDEATHSIG` which
has the kernel take care of this for us.

(In practice we don't actually use this peer functionality anymore
 because all of the client/daemon code kind of requires being run under systemd
 on a real system now)

This shrinks the API surface and is much less repetitive in
the codebase.

Prep for moving more of the CLI code to Rust.
2021-03-01 18:53:50 +01:00
Colin Walters
732e0f232a daemon: Fix crash on upgrade with remote:checksum
The refspec code really needs to be cleaned up and oxidized (and
unit tested more).

The original intention is that if you're pinned to a commit, we say
"No upgrade available" but we were crashing if one (understandably)
rebased to the combination of `remote:checksum` instead of just `checksum`.

But, we can't change the classifier to call this `CHECKSUM` and
output an error, because that just conflicts with us accepting
the syntax `rpm-ostree rebase :<checksum>`.

I'm actually coming around to the idea that this `remote:checksum` syntax means
"no upgrade available" is correct, whereas pinning to just `checksum`
is more of an error when you try to upgrade.

Closes: https://github.com/coreos/rpm-ostree/issues/2603
2021-03-01 16:57:51 +01:00
Colin Walters
10ad264ecd daemon: Heap allocate GVariantDict to pass to Rust
I was looking at a different problem and noticed a spam of
```
Feb 24 23:06:37 cosa-devsh rpm-ostree[1099]: g_variant_dict_ref: assertion 'is_valid_heap_dict (dict)' failed
Feb 24 23:06:37 cosa-devsh rpm-ostree[1099]: g_variant_dict_unref: assertion 'is_valid_heap_dict (dict)' failed
Feb 24 23:06:37 cosa-devsh rpm-ostree[1099]: g_variant_dict_ref: assertion 'is_valid_heap_dict (dict)' failed
Feb 24 23:06:37 cosa-devsh rpm-ostree[1099]: g_variant_dict_unref: assertion 'is_valid_heap_dict (dict)' failed
```

in the journal.  It turns out that the Rust bindings try to call
`g_variant_ref()`, but that's (understandably) not allowed on
a stack allocated instance.

Since we heap allocate a *ton* here, let's just heap allocate
the dict too.

Now, we also along the way stopped using the bits to inject
```
[Service]
Environment=G_DEBUG=fatal-warnings
```
in our CI.  I'll look at that as a followup.
2021-02-26 16:54:26 +01:00
Luca BRUNO
de7d20e43b libpriv/passwd: move UID/GID checker to Rust
This ports to Rust the logic for checking whether a directory tree
contains content owned by a given UID/GID.
2021-02-26 00:34:56 +01:00
Timothée Ravier
101d531f3b Install rpm-ostree sysusers config and countme units
Install the systemd unit, timer and sysusers configuration for Count Me
support. We do not enable or pull as a dependency those units by default
as this is a decision that should be taken at the distribution level and
needs support on the infrastructure side.

To enable those units in a disctribution package, you can add the
following symlink:
$ ln -snf /usr/lib/systemd/system/rpm-ostree-countme.timer /usr/lib/systemd/system/rpm-ostreed.service.wants/

or add the following config snippet to the rpm-ostreed.service unit:
Wants=rpm-ostree-countme.timer
2021-02-25 16:58:14 +01:00
Kelvin Fan
1c826e993b app/dbus-helpers: Don't error out if caller is updates driver
If the systemd unit associated with the client's PID is the updates
driver's unit, don't require the --bypass-driver option for operations
like upgrade, deploy, and rebase.
This is useful for updates drivers that shell out to rpm-ostree's
binary (e.g. Zincati, currently).
Also refactor some helper functions to make them more general and
reusable.
2021-02-25 06:44:53 +01:00
Kelvin Fan
705b22df28 app/{deploy,rebase}: Do not deploy/rebase if updates driver registered
Follow up to https://github.com/coreos/rpm-ostree/pull/2566.
Error out if users try to manually do a deploy/rebase if an updates
driver is registered. Provide `--bypass-driver` option to proceed
anyway.
2021-02-25 06:44:53 +01:00
Kelvin Fan
e10df33e88 app/dbus-helpers: Factor out updates driver-related functions
Following https://github.com/coreos/rpm-ostree/pull/2566, we would
like to give other commands (deploy and rebase) the same treatment.

Factor out functions to retrieve systemd unit docs and a function
that detects updates drivers so they can be reused elsewhere.
2021-02-25 06:44:53 +01:00
Colin Walters
5a79ca9035 apply-live: Rework to use refs to store state
Came out of discussion in https://github.com/coreos/rpm-ostree/pull/2581
around some racy code for checking for the live commit object.

The reliability of apply-live depends on the
underlying commits not being garbage collected.  Our diff logic
is in terms of ostree commits, not the physical filesystem (this
allows us to make various optimizations too).

Ultimately I think we should drive some of the live-apply
logic into libostree itself; we can more easily have an atomic
state file instead of the two split refs.

(Or perhaps what we should add to ostree is like a refs.d model
 where a single atomic file can refer to multiple commits)

For now though let's rework the code here to write refs.  We
retain the file in `/run` as just a "stamp file" that signals
that a deployment has had `apply-live` run.
2021-02-23 21:51:22 -05:00
Colin Walters
d8230bfb6d daemon: Move some "deployment variant" generation to Rust
More prep for https://github.com/coreos/rpm-ostree/pull/2388

This was actually also my first time really trying out the
latest gtk-rs `glib::Variant` API, which is one of the major
things we need to use to progress oxidation more.
2021-02-23 13:56:26 -05:00
Luca BRUNO
7283aef8af libpriv/passwd: remove unused functions
This drops some functions that used to be part of C unit-tests but
are currently dead code.
2021-02-22 13:24:41 -05:00
Luca BRUNO
9b94e85e5b libpriv/passwd: move compose preparation to Rust
This moves passwd/group compose preparation logic to Rust,
dropping all the remaining minor helpers related to JSON parsing,
file stream creation, and entries deduplication.
2021-02-22 11:44:13 -05:00
Colin Walters
246f02fd47 apply-live: Move client-side finish to Rust
Now that we have an RPM diff+printing binding, we can
move the client side postprocessing for `apply-live`
to Rust.
2021-02-19 09:08:22 -05:00
Colin Walters
04e0c4e01a Fix progress API to have "output message" separate from task
A lot of our output is outside of a "task"; the Rust binding
incorrectly made it a method on `Progress`.  This is really
just a `println!()` that is backed by our dispatch system.
2021-02-19 09:08:22 -05:00
Colin Walters
1d242ddb59 Add a C++ rpmdb-diff API wrapping the C one, bind in Rust
I'd like to compute diffs in apply-live to differentiate
between "pure layering" versus modifications/removals.
2021-02-19 09:08:22 -05:00
Colin Walters
29a2304fe2 daemon: Rename transaction_livefs → transaction_apply_live
Continuing the renaming.
2021-02-19 09:08:22 -05:00
Colin Walters
ffe72d28ec app: Rename livefs.cxx → apply-live.cxx
Continuing the renaming.
2021-02-19 09:08:22 -05:00
Timothée Ravier
790e709360 countme: Persist last timer trigger to handle system suspends
Set `Persistent=yes` in the timer unit to make sure that systems that
are not running 24/7 gets counted when they wake up if they missed the
previous timer run / counting window.

This is mostly for Fedora Silverblue and IoT like systems as Fedora
CoreOS systems usually run 24/7.

https://www.freedesktop.org/software/systemd/man/systemd.timer.html#Persistent=
2021-02-18 15:14:34 -05:00
Colin Walters
0c9f7ab7eb Add daemon.rs with one helper function, use it from C++
Trying to port to use origin Rust code, I think actually
it gets simpler if we move more to Rust to start.
2021-02-18 10:22:39 -05:00
Colin Walters
3910e77ae8 daemon: Refactor deployment variant generation code
Changes to this ad-hoc `a{sv}` code have been scattered
around over time.  Move the "core" bits to the top of
the function, then have the more complex stuff that depends
on the origin (and refspec/layering status) later.

Prep for further cleanups.
2021-02-18 10:22:39 -05:00
Colin Walters
8a62ad9f3d Add gobj_rewrap() API to pass glib-rs objects back to C++
When we started using cxxrs, most of the glib-rs objects like
`OstreeRepo`/`OstreeSysroot` were owned by C++ and passed
down into Rust.  That motivated the addition of the special
bridging infrastructure to re-create a glib-rs wrapper
type from what cxxrs wants (a `Pin<&mut T>`).

But now that we're adding more in Rust, we have the need
to pass these objects back into C++.  In fact this will
hopefully soon because the default case as more of the
binary entrypoint becomes Rust.

Add another trait with a method `gobj_rewrap()` that converts
in the other direction.  This implementation took me a number
of tries before I finally settled on simply using `mem::transmute()`.
There are a *lot* of caveats listed on the docs for that function,
but I think it really is what we want here.  See the link for pending work
on a Rust RFC to enable safe transmutes for some cases, and I believe
that would cover this use case:
https://internals.rust-lang.org/t/pre-rfc-v2-safe-transmute/11431

I've verified this works in a separate patch, but this commit
also adds a simple test case - this goes all the way from:
   Rust glib-rs `ostree::Repo` (holding strong ref)
   -> Rust `Pin<&mut ostree_sys::OstreeRepo>`
   -> (internal cxx-rs C bridge)
   -> C++ `OstreeRepo&` reference
   -> C `OstreeRepo*` pointer
Which is quite the dance if you think about it!
2021-02-18 06:29:41 -05:00
Colin Walters
f8dc856aa9 compose: Add missing #include <optional>
This only fails on newer gcc/libstdc++ apparently in current
Fedora rawhide: https://kojipkgs.fedoraproject.org//work/tasks/4372/62164372/build.log
2021-02-17 14:02:34 -05:00
Kelvin Fan
626d021edb app/upgrade: Do not upgrade if updates driver registered
Do not perform an upgrade if detected that an updates driver has
been registered.

Add --bypass-driver option to force an upgrade regardless of whether an
updates driver has been registered.
2021-02-17 11:43:34 -05:00
Kelvin Fan
261b9cbb87 app/status: factor out get_sd_unit_objpath() function
Factor out a `get_sd_unit_objpath()` function into `libbuiltin`
so we can reuse the code in `builtin_upgrade`.
2021-02-17 11:43:34 -05:00
Colin Walters
118178cef1 tree-wide: Fix C++ range iteration to use references
This is actually a perfect example of the tradeoffs involved
in our team of C/Rust programmers trying to use C++ so we
can use cxx-rs =)

It turns out that "for (auto foo : bar)" is really yet another
one of those C++ sharp edges just waiting to cut.  That
version does a copy of each value; one almost always wants to use
"for (auto & foo : bar)" which like Rust's `.iter()`.

In most of our code we were OK making copies, they were just
a performance hit, but in another place I was relying on the
"side effect" of `.c_str()` but that meant our value got
destroyed.
2021-02-12 12:50:02 -05:00
Colin Walters
764de41cc6 Switch to using cxx-rs for treefile
This is one half of https://github.com/coreos/rpm-ostree/issues/2544
which aims to drop our use of `cbindgen`.
2021-02-11 15:44:38 -05:00
Colin Walters
20178bb25a tree-wide: Include GLib headers before libdnf
Alternative fix to https://github.com/rpm-software-management/libdnf/pull/1139
aka https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1935

This way libdnf's `extern "C"` over the glib headers doesn't apply
because we already processed that header.
2021-02-10 17:05:42 -05:00
Jonathan Lebon
49fe650124 lockfile: Move ror_lockfile_read to cxx.rs
Pretty straightforward. Haven't moved `ror_lockfile_write` yet because
that's trickier to do and I'm still figuring out the most elegant way to
do this within cxx.rs' constraints.
2021-02-10 13:39:38 -05:00
Jonathan Lebon
56f95cc5c1 extensions: Don't try to chown RPM packages
We don't need it and it won't work in the unprivileged path where we're
running this in a cosa supermin (of course, this is all a bit silly
because we don't actually need privileges to begin with for this, but
there's a lot of momentum in sticking with that workflow).

Update submodule: libglnx
2021-02-10 10:20:38 -05:00
Colin Walters
6886e44425 scripts: Bind /usr/share/empty over /usr/share/rpm
Now that we inject the `%_dbpath /usr/share/rpm` macro, `rpm -q`
will start using it.  But in RPM script invocation, we don't
want them to see any RPM database at all - trying to query it
should be a clean failure.
2021-02-09 18:36:35 -05:00
Jonathan Lebon
667fdc9ff4 libpriv/rpm-util: Use /usr/share/rpm for base rpmdb query
Follow-up to previous commit: we had another path where we made a
temporary rootfs and symlinked `/var/lib/rpm` to the base rpmdb. That of
course broke now that we inject a macro to point the rpmdb to
`/usr/share/rpm`.

Rework this to use `/usr/share/rpm` since that's our canonical location
for now, but also add the compat symlinks so that this logic should keep
working even on trees without the injected macro yet.
2021-02-09 18:36:35 -05:00
Jonathan Lebon
60215ae865 libpriv/rpm-util: Add /usr/lib/sysimage/rpm symlink in rpmdb checkout
We don't technically need this yet, but it mirrors how it's set up in
our composes so that if there's code that wants to use the new location
too, it'll just work.
2021-02-09 18:36:35 -05:00
Jonathan Lebon
aa1a0f8719 lib/package: Fix comment about rpmdb checkout
We do fallback here.
2021-02-09 18:36:35 -05:00
Jonathan Lebon
99486a75e8 Add /usr/lib/rpm/macros.d/macros.rpm-ostree to set %_dbpath to /usr/share/rpm
We trigger a librpm macro file load in many of our paths. Since the
default value shipped by rpm's macro file sets `_dbpath` to
`/var/lib/rpm`, we have to explicitly set that back to `/usr/share/rpm`
in those paths.

This became more problematic recently with libsolv v0.7.17 which fully
keys off of `_dbpath` to find the rpmdb path to load:

04d4d036b2

And it's not technically wrong; we really should make that macro not
lie. This is what this patch does by injecting an RPM macro file in our
composes which sets it to /usr/share/rpm. So then e.g. the `rpm` CLI
doesn't actually need the `/var/lib/rpm` backcompat link anymore, though
there's no harm in leaving it.

In the future, we should be able to drop this once we move all of Fedora
to `/usr/lib/sysimage/rpm` (see
https://github.com/coreos/fedora-coreos-tracker/issues/639).

Closes: #2548
2021-02-09 18:36:35 -05:00
Luca BRUNO
8a2f281143 libpriv/postprocess: get rid of goto statements
This removes all goto statements in the postprocess module,
replacing them with an exception catcher instead.
2021-02-09 16:43:32 +01:00
Colin Walters
2f6b5a654d Bind output core into Rust, use in apply-live
Originally the Rust apply-live code was exposed from Rust to C
via bindgen.  But when working on that, I hit the problem
that our output infrastructure was C...and the "reverse direction"
binding stuff was just ugly.

This PR again IMO shows the value of the investment in cxx-rs
because we can now seamlessly call back from the Rust side
into a "C++-ish" progress API, which the C++ side is updated
to use.

The level of indirection here is obviously pretty silly
because the main thing on the C++ output side is basically
a function dispatcher, but...I didn't want to try to rework
that into Rust fully yet.  (But, the moment we do this
whole area will get a *lot* cleaner)

Anyways, in the end this makes it easy for the apply-live
code to output progress to the user which was sorely
needed.
2021-02-09 04:43:29 -05:00
Colin Walters
c9e9269770 Rename internal Rust progress to console_
Our output system is very confusing in that we bridge over
DBus in some cases and not others.  In preparation for allowing
Rust code to call into the C++ progress system which contains
that delegation layer, rename the Rust progress to `console_`
to clearly show that it should only be invoked by code that
knows it's writing to a tty.
2021-02-09 04:43:29 -05:00
Colin Walters
a8fe6cf32b transaction: Fix missing return in error case
Hooray for compiler warnings.
2021-02-08 14:38:31 -05:00