diff --git a/man/org.freedesktop.sysupdate1.xml b/man/org.freedesktop.sysupdate1.xml index ac0e9152a1..66c21fab3d 100644 --- a/man/org.freedesktop.sysupdate1.xml +++ b/man/org.freedesktop.sysupdate1.xml @@ -170,61 +170,60 @@ node /org/freedesktop/sysupdate1/target/host { Methods - List() returns a list of versions available for this target. The - flags argument can be used to pass additional options, with bit 0 mapping to - . When is true, this method returns only the versions - installed locally. Otherwise, this method pulls metadata from the network and returns all versions + List() returns a list of versions available for this target. Additional + options may be passed through the flags argument. Valid flags are defined as follows: + + + +#define SD_SYSUPDATE_OFFLINE (UINT64_C(1) << 0) + + + When SD_SYSUPDATE_OFFLINE 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 Describe() to query more information about each version returned by this method. Describe() returns all known information about a given version as a JSON object. The version argument is used to pass the version to be described. Additional - options may be passed through the flags argument. The only supported value currently - is SD_SYSTEMD_SYSUPDATE_OFFLINE, which prevents the call from accessing the network - and restricts results to locally installed versions. This flag is defined as follows: - - -#define SD_SYSTEMD_SYSUPDATE_OFFLINE (UINT64_C(1) << 0) - - - The returned JSON object contains several known keys. More keys may be added in the future. The - currently known keys are as follows: + options may be passed through the flags argument. This method supports the same flags + as List(). The returned JSON object contains several known keys. More keys may be + added in the future. The currently known keys are as follows: - version + version A string containing the version number. - newest + newest A boolean indicating whether this version is the latest available for the target. - available + available A boolean indicating whether this version is available for download. - installed + installed A boolean indicating whether this version is installed locally. - obsolete + obsolete A boolean indicating whether this version is considered obsolete by the service, and is therefore disallowed from being installed. - protected + protected A boolean indicating whether this version is exempt from deletion by a Vacuum() operation. - changelog_urls + changelog_urls A list of strings that contain user-presentable URLs to ChangeLogs associated with this version. @@ -326,9 +325,12 @@ node /org/freedesktop/sysupdate1/target/host { All methods called on this interface expose additional variables to the polkit rules. class contains the class of the Target being acted upon, and name 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 - SD_SYSTEMD_SYSUPDATE_OFFLINE flag is exposed as a variable named - offline. + rule. Flags are mapped as follows: + + + SD_SYSUPDATE_OFFLINEupdate + + diff --git a/src/sysupdate/sysupdate-util.h b/src/sysupdate/sysupdate-util.h index 56339a87b1..8504fd24b7 100644 --- a/src/sysupdate/sysupdate-util.h +++ b/src/sysupdate/sysupdate-util.h @@ -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) diff --git a/src/sysupdate/sysupdated.c b/src/sysupdate/sysupdated.c index e2c3d7e102..4edfea937e 100644 --- a/src/sysupdate/sysupdated.c +++ b/src/sysupdate/sysupdated.c @@ -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; diff --git a/src/sysupdate/updatectl.c b/src/sysupdate/updatectl.c index 39957ea1a0..151fa9e1d7 100644 --- a/src/sysupdate/updatectl.c +++ b/src/sysupdate/updatectl.c @@ -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);