1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-11 05:17:44 +03:00

Merge pull request #25077 from keszybz/completions-optional-components

Fix completions when machinectl is not installed and other fixes
This commit is contained in:
Luca Boccassi 2022-10-20 15:57:46 +02:00 committed by GitHub
commit 701f7f6c8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 67 additions and 52 deletions

View File

@ -800,11 +800,10 @@
<varlistentry> <varlistentry>
<term><option>--max-addresses=</option></term> <term><option>--max-addresses=</option></term>
<listitem><para>When used with the <option>list-machines</option> command, limits the number of ip <listitem><para>When used with the <option>list-machines</option> command, limits the number of IP
addresses output for every machine. Defaults to 1. All addresses can be requested with addresses shown for every machine. Defaults to 1. All addresses can be requested with
<literal>all</literal> as argument to <option>--max-addresses=</option>. If the argument to <literal>all</literal>. If the limit is 0, the address column is not shown. Otherwise, if the machine
<option>--max-addresses=</option> is less than the actual number of addresses, has more addresses than shown, <literal></literal> follows the last address.</para></listitem>
<literal></literal>follows the last address.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View File

@ -25,8 +25,9 @@ __contains_word () {
__get_machines() { __get_machines() {
local a b local a b
machinectl list --full --no-legend --no-pager 2>/dev/null | { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
{ while read a b; do echo " $a"; done; }; { while read a b; do echo " $a"; done; } | \
sort -u
} }
__get_busnames() { __get_busnames() {

View File

@ -27,8 +27,9 @@ __contains_word () {
__get_machines() { __get_machines() {
local a b local a b
(machinectl list-images --full --no-legend --no-pager; machinectl list --full --no-legend --no-pager; echo ".host") | \ { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
{ while read a b; do echo " $a"; done; } | sort -u; { while read a b; do echo " $a"; done; } | \
sort -u
} }
__syslog_priorities=(emerg alert crit err warning notice info debug) __syslog_priorities=(emerg alert crit err warning notice info debug)

View File

@ -31,8 +31,9 @@ __get_all_seats () { loginctl --no-legend list-seats | { while read -r a b
__get_machines() { __get_machines() {
local a b local a b
machinectl list --full --no-legend --no-pager 2>/dev/null | { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
{ while read a b; do echo " $a"; done; }; { while read a b; do echo " $a"; done; } | \
sort -u
} }
_loginctl () { _loginctl () {

View File

@ -25,8 +25,9 @@ __contains_word() {
__get_machines() { __get_machines() {
local a b local a b
(machinectl list-images --full --no-legend --no-pager; machinectl list --full --no-legend --no-pager; echo ".host") | \ { machinectl list-images --full --no-legend --no-pager 2>/dev/null; machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
{ while read a b; do echo " $a"; done; } | sort -u; { while read a b; do echo " $a"; done; } | \
sort -u
} }
_machinectl() { _machinectl() {

View File

@ -25,8 +25,9 @@ __contains_word () {
__get_machines() { __get_machines() {
local a b local a b
machinectl list --full --no-legend --no-pager 2>/dev/null | { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
{ while read a b; do echo " $a"; done; }; { while read a b; do echo " $a"; done; } | \
sort -u
} }
_portablectl() { _portablectl() {

View File

@ -115,8 +115,9 @@ __get_all_unit_files () { { __systemctl $1 list-unit-files "$2*"; } | { while re
__get_machines() { __get_machines() {
local a b local a b
{ machinectl list-images --full --no-legend --no-pager; machinectl list --full --no-legend --no-pager; } | \ { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
{ while read a b; do echo " $a"; done; } { while read a b; do echo " $a"; done; } | \
sort -u
} }
_systemctl () { _systemctl () {

View File

@ -27,7 +27,9 @@ __contains_word () {
__get_machines() { __get_machines() {
local a b local a b
machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; }; { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
{ while read a b; do echo " $a"; done; } | \
sort -u
} }
__get_units_all() { __get_units_all() {

View File

@ -25,7 +25,9 @@ __contains_word() {
__get_machines() { __get_machines() {
local a b local a b
machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; }; { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
{ while read a b; do echo " $a"; done; } | \
sort -u
} }
__get_units_have_cgroup() { __get_units_have_cgroup() {

View File

@ -25,7 +25,9 @@ __contains_word() {
__get_machines() { __get_machines() {
local a b local a b
machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; }; { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
{ while read a b; do echo " $a"; done; } | \
sort -u
} }
_systemd_cgtop() { _systemd_cgtop() {

View File

@ -35,7 +35,9 @@ __get_slices() {
__get_machines() { __get_machines() {
local a b local a b
machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; }; { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
{ while read a b; do echo " $a"; done; } | \
sort -u
} }
__get_env() { __get_env() {

View File

@ -26,7 +26,9 @@ __get_slice_units () { __systemctl $1 list-units --all -t slice \
__get_machines() { __get_machines() {
local a b local a b
machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; }; { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
{ while read a b; do echo " $a"; done; } | \
sort -u
} }
_systemd_run() { _systemd_run() {

View File

@ -27,7 +27,9 @@ __contains_word () {
__get_machines() { __get_machines() {
local a b local a b
machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; }; { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
{ while read a b; do echo " $a"; done; } | \
sort -u
} }
__get_interfaces(){ __get_interfaces(){

View File

@ -1,15 +1,15 @@
#compdef machinectl #compdef machinectl
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
(( $+functions[__machinectl_get_machines] )) || (( $+functions[__machinectl_get_images] )) ||
__machinectl_get_machines () { __machinectl_get_images () {
machinectl --no-legend list-images | {while read -r a b; do echo $a; done;} machinectl --no-legend list-images | {while read -r a b; do echo $a; done;}
} }
(( $+functions[_machinectl_machines] )) || (( $+functions[_machinectl_images] )) ||
_machinectl_machines() { _machinectl_images() {
local -a _machines local -a _machines
_machines=("${(fo)$(__machinectl_get_machines)}") _machines=("${(fo)$(__machinectl_get_images)}")
typeset -U _machines typeset -U _machines
if [[ -n "$_machines" ]]; then if [[ -n "$_machines" ]]; then
_describe 'machines' _machines _describe 'machines' _machines
@ -64,9 +64,9 @@
list*|cancel-transfer|pull-tar|pull-raw) list*|cancel-transfer|pull-tar|pull-raw)
msg="no options" ;; msg="no options" ;;
clone) clone)
_machinectl_machines ;; _machinectl_images ;;
start) start)
_machinectl_machines ;; _machinectl_images ;;
*) *)
_sd_machines _sd_machines
esac esac

View File

@ -3,7 +3,10 @@
(( $+functions[__sd_machines_get_machines] )) || (( $+functions[__sd_machines_get_machines] )) ||
__sd_machines_get_machines () { __sd_machines_get_machines () {
machinectl --full --no-legend --no-pager list | {while read -r a b; do echo $a; done;};
{ machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
{ while read a b; do echo "$a"; done; } | \
sort -u
} }
local -a _machines local -a _machines

View File

@ -60,8 +60,6 @@
#include "verbs.h" #include "verbs.h"
#include "web-util.h" #include "web-util.h"
#define ALL_ADDRESSES -1
static char **arg_property = NULL; static char **arg_property = NULL;
static bool arg_all = false; static bool arg_all = false;
static BusPrintPropertyFlags arg_print_flags = 0; static BusPrintPropertyFlags arg_print_flags = 0;
@ -83,7 +81,7 @@ static ImportVerify arg_verify = IMPORT_VERIFY_SIGNATURE;
static const char* arg_format = NULL; static const char* arg_format = NULL;
static const char *arg_uid = NULL; static const char *arg_uid = NULL;
static char **arg_setenv = NULL; static char **arg_setenv = NULL;
static int arg_max_addresses = 1; static unsigned arg_max_addresses = 1;
STATIC_DESTRUCTOR_REGISTER(arg_property, strv_freep); STATIC_DESTRUCTOR_REGISTER(arg_property, strv_freep);
STATIC_DESTRUCTOR_REGISTER(arg_setenv, strv_freep); STATIC_DESTRUCTOR_REGISTER(arg_setenv, strv_freep);
@ -260,7 +258,6 @@ static int show_table(Table *table, const char *word) {
} }
static int list_machines(int argc, char *argv[], void *userdata) { static int list_machines(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_(table_unrefp) Table *table = NULL; _cleanup_(table_unrefp) Table *table = NULL;
@ -273,12 +270,13 @@ static int list_machines(int argc, char *argv[], void *userdata) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Could not get machines: %s", bus_error_message(&error, r)); return log_error_errno(r, "Could not get machines: %s", bus_error_message(&error, r));
table = table_new("machine", "class", "service", "os", "version", "addresses"); table = table_new("machine", "class", "service", "os", "version",
arg_max_addresses > 0 ? "addresses" : NULL);
if (!table) if (!table)
return log_oom(); return log_oom();
table_set_ersatz_string(table, TABLE_ERSATZ_DASH); table_set_ersatz_string(table, TABLE_ERSATZ_DASH);
if (!arg_full && arg_max_addresses != ALL_ADDRESSES) if (!arg_full && arg_max_addresses > 0 && arg_max_addresses < UINT_MAX)
table_set_cell_height_max(table, arg_max_addresses); table_set_cell_height_max(table, arg_max_addresses);
if (arg_full) if (arg_full)
@ -310,23 +308,23 @@ static int list_machines(int argc, char *argv[], void *userdata) {
&os, &os,
&version_id); &version_id);
(void) call_get_addresses(
bus,
name,
0,
"",
"\n",
&addresses);
r = table_add_many(table, r = table_add_many(table,
TABLE_STRING, empty_to_null(name), TABLE_STRING, empty_to_null(name),
TABLE_STRING, empty_to_null(class), TABLE_STRING, empty_to_null(class),
TABLE_STRING, empty_to_null(service), TABLE_STRING, empty_to_null(service),
TABLE_STRING, empty_to_null(os), TABLE_STRING, empty_to_null(os),
TABLE_STRING, empty_to_null(version_id), TABLE_STRING, empty_to_null(version_id));
TABLE_STRING, empty_to_null(addresses));
if (r < 0) if (r < 0)
return table_log_add_error(r); return table_log_add_error(r);
if (arg_max_addresses > 0) {
(void) call_get_addresses(bus, name, 0, "", "\n", &addresses);
r = table_add_many(table,
TABLE_STRING, empty_to_null(addresses));
if (r < 0)
return table_log_add_error(r);
}
} }
r = sd_bus_message_exit_container(reply); r = sd_bus_message_exit_container(reply);
@ -2717,13 +2715,10 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_MAX_ADDRESSES: case ARG_MAX_ADDRESSES:
if (streq(optarg, "all")) if (streq(optarg, "all"))
arg_max_addresses = ALL_ADDRESSES; arg_max_addresses = UINT_MAX;
else if (safe_atoi(optarg, &arg_max_addresses) < 0) else if (safe_atou(optarg, &arg_max_addresses) < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Invalid number of addresses: %s", optarg); "Invalid number of addresses: %s", optarg);
else if (arg_max_addresses <= 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Number of IPs cannot be negative or zero: %s", optarg);
break; break;
case '?': case '?':