mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 08:25:20 +09:00
Merge pull request #34079 from AdrianVovk/sysupdate-fixups
systemd-sysupdated follow-ups
This commit is contained in:
@@ -170,61 +170,60 @@ node /org/freedesktop/sysupdate1/target/host {
|
||||
<refsect2>
|
||||
<title>Methods</title>
|
||||
|
||||
<para><function>List()</function> returns a list of versions available for this target. The
|
||||
<varname>flags</varname> argument can be used to pass additional options, with bit 0 mapping to
|
||||
<option>offline</option>. When <option>offline</option> is true, this method returns only the versions
|
||||
installed locally. Otherwise, this method pulls metadata from the network and returns all versions
|
||||
<para><function>List()</function> returns a list of versions available for this target. Additional
|
||||
options may be passed through the <varname>flags</varname> argument. Valid flags are defined as follows:
|
||||
</para>
|
||||
|
||||
<programlisting>
|
||||
#define SD_SYSUPDATE_OFFLINE (UINT64_C(1) << 0)
|
||||
</programlisting>
|
||||
|
||||
<para>When <constant>SD_SYSUPDATE_OFFLINE</constant> is set, this method returns only the versions
|
||||
installed locally. Otherwise, this method pulls metadata from the network and returns all versions
|
||||
available for this target. Use <function>Describe()</function> to query more information about each
|
||||
version returned by this method.</para>
|
||||
|
||||
<para><function>Describe()</function> returns all known information about a given version as a JSON
|
||||
object. The <varname>version</varname> argument is used to pass the version to be described. Additional
|
||||
options may be passed through the <varname>flags</varname> argument. The only supported value currently
|
||||
is <varname>SD_SYSTEMD_SYSUPDATE_OFFLINE</varname>, which prevents the call from accessing the network
|
||||
and restricts results to locally installed versions. This flag is defined as follows:</para>
|
||||
|
||||
<programlisting>
|
||||
#define SD_SYSTEMD_SYSUPDATE_OFFLINE (UINT64_C(1) << 0)
|
||||
</programlisting>
|
||||
|
||||
<para>The returned JSON object contains several known keys. More keys may be added in the future. The
|
||||
currently known keys are as follows:</para>
|
||||
options may be passed through the <varname>flags</varname> argument. This method supports the same flags
|
||||
as <function>List()</function>. The returned JSON object contains several known keys. More keys may be
|
||||
added in the future. The currently known keys are as follows:</para>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>version</term>
|
||||
<term><literal>version</literal></term>
|
||||
<listitem><para>A string containing the version number.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>newest</term>
|
||||
<term><literal>newest</literal></term>
|
||||
<listitem><para>A boolean indicating whether this version is the latest available for the target.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>available</term>
|
||||
<term><literal>available</literal></term>
|
||||
<listitem><para>A boolean indicating whether this version is available for download.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>installed</term>
|
||||
<term><literal>installed</literal></term>
|
||||
<listitem><para>A boolean indicating whether this version is installed locally.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>obsolete</term>
|
||||
<term><literal>obsolete</literal></term>
|
||||
<listitem><para>A boolean indicating whether this version is considered obsolete by the service,
|
||||
and is therefore disallowed from being installed.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>protected</term>
|
||||
<term><literal>protected</literal></term>
|
||||
<listitem><para>A boolean indicating whether this version is exempt from deletion by a
|
||||
<function>Vacuum()</function> operation.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>changelog_urls</term>
|
||||
<term><literal>changelog_urls</literal></term>
|
||||
<listitem><para>A list of strings that contain user-presentable URLs to ChangeLogs associated with
|
||||
this version.</para></listitem>
|
||||
</varlistentry>
|
||||
@@ -326,9 +325,12 @@ node /org/freedesktop/sysupdate1/target/host {
|
||||
<para>All methods called on this interface expose additional variables to the polkit rules.
|
||||
<literal>class</literal> contains the class of the Target being acted upon, and <literal>name</literal>
|
||||
contains the name of the same Target. Additionally, each method exposes its arguments to the
|
||||
rule. Arguments containing flags are unwrapped into a variable-per-flag; for example, the
|
||||
<literal>SD_SYSTEMD_SYSUPDATE_OFFLINE</literal> flag is exposed as a variable named
|
||||
<literal>offline</literal>.</para>
|
||||
rule. Flags are mapped as follows:</para>
|
||||
|
||||
<itemizedlist>
|
||||
<listitem><para><constant>SD_SYSUPDATE_OFFLINE</constant> → <literal>update</literal></para></listitem>
|
||||
</itemizedlist>
|
||||
|
||||
</refsect2>
|
||||
</refsect1>
|
||||
|
||||
|
||||
@@ -4,4 +4,5 @@
|
||||
|
||||
int reboot_now(void);
|
||||
|
||||
#define SD_SYSTEMD_SYSUPDATE_OFFLINE (UINT64_C(1) << 0)
|
||||
#define SD_SYSUPDATE_OFFLINE (UINT64_C(1) << 0)
|
||||
#define SD_SYSUPDATE_FLAGS_ALL (SD_SYSUPDATE_OFFLINE)
|
||||
|
||||
@@ -163,7 +163,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Job*, job_free);
|
||||
DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(job_hash_ops, uint64_t, uint64_hash_func, uint64_compare_func,
|
||||
Job, job_free);
|
||||
|
||||
static int job_new(JobType type, Target *t, sd_bus_message *msg, JobComplete complete_cb, Job **ret) {
|
||||
static int job_new(JobType type, Target *t, sd_bus_message *msg, JobComplete complete_cb, Job **ret) {
|
||||
_cleanup_(job_freep) Job *j = NULL;
|
||||
int r;
|
||||
|
||||
@@ -725,13 +725,20 @@ static int target_new(Manager *m, TargetClass class, const char *name, const cha
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sysupdate_run_simple(sd_json_variant **ret, ...) {
|
||||
static int sysupdate_run_simple(sd_json_variant **ret, Target *t, ...) {
|
||||
_cleanup_close_pair_ int pipe[2] = EBADF_PAIR;
|
||||
_cleanup_(pidref_done_sigkill_wait) PidRef pid = PIDREF_NULL;
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_free_ char *target_arg = NULL;
|
||||
int r;
|
||||
|
||||
if (t) {
|
||||
r = target_get_argument(t, &target_arg);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = pipe2(pipe, O_CLOEXEC);
|
||||
if (r < 0)
|
||||
return -errno;
|
||||
@@ -760,7 +767,12 @@ static int sysupdate_run_simple(sd_json_variant **ret, ...) {
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
va_start(ap, ret);
|
||||
if (target_arg && strv_extend(&args, target_arg) < 0) {
|
||||
log_oom();
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
va_start(ap, t);
|
||||
while ((arg = va_arg(ap, char*))) {
|
||||
r = strv_extend(&args, arg);
|
||||
if (r < 0)
|
||||
@@ -844,8 +856,8 @@ static int target_method_list_finish(
|
||||
static int target_method_list(sd_bus_message *msg, void *userdata, sd_bus_error *error) {
|
||||
Target *t = ASSERT_PTR(userdata);
|
||||
_cleanup_(job_freep) Job *j = NULL;
|
||||
int r;
|
||||
uint64_t flags;
|
||||
int r;
|
||||
|
||||
assert(msg);
|
||||
|
||||
@@ -853,10 +865,13 @@ static int target_method_list(sd_bus_message *msg, void *userdata, sd_bus_error
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if ((flags & ~SD_SYSUPDATE_FLAGS_ALL) != 0)
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid flags specified");
|
||||
|
||||
const char *details[] = {
|
||||
"class", target_class_to_string(t->class),
|
||||
"name", t->name,
|
||||
"offline", one_zero(FLAGS_SET(flags, SD_SYSTEMD_SYSUPDATE_OFFLINE)),
|
||||
"offline", one_zero(FLAGS_SET(flags, SD_SYSUPDATE_OFFLINE)),
|
||||
NULL
|
||||
};
|
||||
|
||||
@@ -875,7 +890,7 @@ static int target_method_list(sd_bus_message *msg, void *userdata, sd_bus_error
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
j->offline = FLAGS_SET(flags, SD_SYSTEMD_SYSUPDATE_OFFLINE);
|
||||
j->offline = FLAGS_SET(flags, SD_SYSUPDATE_OFFLINE);
|
||||
|
||||
r = job_start(j);
|
||||
if (r < 0)
|
||||
@@ -906,8 +921,8 @@ static int target_method_describe(sd_bus_message *msg, void *userdata, sd_bus_er
|
||||
Target *t = ASSERT_PTR(userdata);
|
||||
_cleanup_(job_freep) Job *j = NULL;
|
||||
const char *version;
|
||||
int r;
|
||||
uint64_t flags;
|
||||
int r;
|
||||
|
||||
assert(msg);
|
||||
|
||||
@@ -916,13 +931,16 @@ static int target_method_describe(sd_bus_message *msg, void *userdata, sd_bus_er
|
||||
return r;
|
||||
|
||||
if (isempty(version))
|
||||
return -EINVAL;
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Version must be specified");
|
||||
|
||||
if ((flags & ~SD_SYSUPDATE_FLAGS_ALL) != 0)
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid flags specified");
|
||||
|
||||
const char *details[] = {
|
||||
"class", target_class_to_string(t->class),
|
||||
"name", t->name,
|
||||
"version", version,
|
||||
"offline", one_zero(FLAGS_SET(flags, SD_SYSTEMD_SYSUPDATE_OFFLINE)),
|
||||
"offline", one_zero(FLAGS_SET(flags, SD_SYSUPDATE_OFFLINE)),
|
||||
NULL
|
||||
};
|
||||
|
||||
@@ -945,7 +963,7 @@ static int target_method_describe(sd_bus_message *msg, void *userdata, sd_bus_er
|
||||
if (!j->version)
|
||||
return log_oom();
|
||||
|
||||
j->offline = FLAGS_SET(flags, SD_SYSTEMD_SYSUPDATE_OFFLINE);
|
||||
j->offline = FLAGS_SET(flags, SD_SYSUPDATE_OFFLINE);
|
||||
|
||||
r = job_start(j);
|
||||
if (r < 0)
|
||||
@@ -1057,7 +1075,7 @@ static int target_method_update(sd_bus_message *msg, void *userdata, sd_bus_erro
|
||||
return r;
|
||||
|
||||
if (flags != 0)
|
||||
return sd_bus_error_set_errnof(error, SYNTHETIC_ERRNO(EINVAL), "Flags argument must be 0: %m");
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Flags must be 0");
|
||||
|
||||
if (isempty(version))
|
||||
action = "org.freedesktop.sysupdate1.update";
|
||||
@@ -1152,16 +1170,11 @@ static int target_method_vacuum(sd_bus_message *msg, void *userdata, sd_bus_erro
|
||||
|
||||
static int target_method_get_version(sd_bus_message *msg, void *userdata, sd_bus_error *error) {
|
||||
Target *t = ASSERT_PTR(userdata);
|
||||
_cleanup_free_ char *target_arg = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
sd_json_variant *version_json;
|
||||
int r;
|
||||
|
||||
r = target_get_argument(t, &target_arg);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sysupdate_run_simple(&v, "--offline", "list", target_arg, NULL);
|
||||
r = sysupdate_run_simple(&v, t, "--offline", "list", NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -1183,16 +1196,11 @@ static int target_method_get_version(sd_bus_message *msg, void *userdata, sd_bus
|
||||
}
|
||||
|
||||
static int target_get_appstream(Target *t, char ***ret) {
|
||||
_cleanup_free_ char *target_arg = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
sd_json_variant *appstream_url_json;
|
||||
int r;
|
||||
|
||||
r = target_get_argument(t, &target_arg);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sysupdate_run_simple(&v, "--offline", "list", target_arg, NULL);
|
||||
r = sysupdate_run_simple(&v, t, "--offline", "list", NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -1235,18 +1243,11 @@ static int target_method_get_appstream(sd_bus_message *msg, void *userdata, sd_b
|
||||
static int target_list_components(Target *t, char ***ret_components, bool *ret_have_default) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *json = NULL;
|
||||
_cleanup_strv_free_ char **components = NULL;
|
||||
_cleanup_free_ char *target_arg = NULL;
|
||||
sd_json_variant *v;
|
||||
bool have_default;
|
||||
int r;
|
||||
|
||||
if (t) {
|
||||
r = target_get_argument(t, &target_arg);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sysupdate_run_simple(&json, "components", target_arg, NULL);
|
||||
r = sysupdate_run_simple(&json, t, "components", NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -430,7 +430,7 @@ static int list_versions(sd_bus *bus, const char *target_path) {
|
||||
&error,
|
||||
&reply,
|
||||
"t",
|
||||
arg_offline ? SD_SYSTEMD_SYSUPDATE_OFFLINE : 0);
|
||||
arg_offline ? SD_SYSUPDATE_OFFLINE : 0);
|
||||
if (r < 0)
|
||||
return log_bus_error(r, &error, NULL, "call List");
|
||||
|
||||
@@ -473,7 +473,7 @@ static int list_versions(sd_bus *bus, const char *target_path) {
|
||||
op,
|
||||
"st",
|
||||
*version,
|
||||
arg_offline ? SD_SYSTEMD_SYSUPDATE_OFFLINE : 0);
|
||||
arg_offline ? SD_SYSUPDATE_OFFLINE : 0);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to call Describe: %m");
|
||||
TAKE_PTR(op);
|
||||
@@ -508,7 +508,7 @@ static int describe(sd_bus *bus, const char *target_path, const char *version) {
|
||||
&reply,
|
||||
"st",
|
||||
version,
|
||||
arg_offline ? SD_SYSTEMD_SYSUPDATE_OFFLINE : 0);
|
||||
arg_offline ? SD_SYSUPDATE_OFFLINE : 0);
|
||||
if (r < 0)
|
||||
return log_bus_error(r, &error, NULL, "call Describe");
|
||||
|
||||
@@ -707,7 +707,7 @@ static int check_finished(sd_bus_message *reply, void *userdata, sd_bus_error *r
|
||||
op,
|
||||
"st",
|
||||
new_version,
|
||||
arg_offline ? SD_SYSTEMD_SYSUPDATE_OFFLINE : 0);
|
||||
arg_offline ? SD_SYSUPDATE_OFFLINE : 0);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to call Describe: %m");
|
||||
TAKE_PTR(op);
|
||||
|
||||
Reference in New Issue
Block a user