Compare commits

..

26 Commits

Author SHA1 Message Date
Lennart Poettering cd6cf81b3f
Merge pull request #14533 from poettering/swap-prio-fixes
Fix Priority= parsing in .swap units
2020-01-10 17:06:16 +01:00
Lennart Poettering a5292dfdf7
Merge pull request #14508 from poettering/namespace-ro-fix
core: be nicer to read-only images
2020-01-10 17:03:01 +01:00
Lennart Poettering 4504f59fbd
Merge pull request #14538 from yuwata/xyzctl-full
use table_set_width(table, 0) if --full is specified
2020-01-10 16:40:31 +01:00
Yu Watanabe 12845a91b5 machinectl: do not truncate addresses when --full is specified 2020-01-10 19:19:15 +09:00
Yu Watanabe bd17fa8cd8 tree-wide: use table_log_add_error() 2020-01-10 18:28:30 +09:00
Yu Watanabe 964a7745de portablectl: optimize table creation 2020-01-10 18:28:23 +09:00
Yu Watanabe 679c7c7a67 machinectl: optimize table creation 2020-01-10 18:28:17 +09:00
Yu Watanabe 9c46b437fc analyze: optimize table creation by using table_add_many() 2020-01-10 18:28:09 +09:00
Yu Watanabe d8aedafb57 format-table: add table_log_add_error() 2020-01-10 18:23:20 +09:00
Yu Watanabe e2268fa437 bash-completion: do not ellipsize machine name 2020-01-10 12:29:02 +09:00
Yu Watanabe a65e34ccb0 machinectl: do not ellipsize table when --full is specified 2020-01-10 12:24:51 +09:00
Yu Watanabe 2a6c483b8c bash-completion: busctrl: support --full command line option 2020-01-10 12:22:08 +09:00
Yu Watanabe b683b82fe7 busctl: introduce --full command line option 2020-01-10 12:19:47 +09:00
Yu Watanabe 6c64cf8859 bash-completion: networkctl: do not show ellipsized link name 2020-01-10 12:13:12 +09:00
Yu Watanabe a42d949080 networkctl: set table width 0 when --full is specified 2020-01-10 12:12:00 +09:00
Yu Watanabe a362c069a9 systemd-mount: add --full command line option 2020-01-10 12:07:28 +09:00
Lennart Poettering 6fca66a7f1 core: set error value correctly 2020-01-09 17:08:40 +01:00
Lennart Poettering af4454cb17 core: use unit-based logging instead of generic logging where appropriate 2020-01-09 17:08:36 +01:00
Lennart Poettering eb34a981d6 core: initialize priority_set when parsing swap unit files
Fixes: #14524
2020-01-09 17:08:31 +01:00
Lennart Poettering 6afc31615e core: no need to initialize swap structure fields if all zeroes anyway 2020-01-09 17:08:27 +01:00
Lennart Poettering 6d9e0ca400 core: expose swap priority value via dbus only if it is set 2020-01-09 17:08:10 +01:00
Lennart Poettering b0a94268f8 core: when we cannot open an image file for write, try read-only
Closes: #14442
2020-01-09 11:18:06 +01:00
Lennart Poettering c8c535d589 namespace: tweak checks whether we can mount image read-only
So far we set up a loopback file read-only iff ProtectSystem= and
ProtectHome= both where set to values that mark these dirs read-only.
Let's extend that and also be happy if /home and the root dir are marked
read-only by some other means.

Fixes: #14442
2020-01-09 11:18:02 +01:00
Lennart Poettering 9a2ec8f7a6 install: use path_strv_contains() where appropriate 2020-01-09 11:17:59 +01:00
Lennart Poettering 3593fa60f2 path-util: express PATH_IN_SET() through path_strv_contains() 2020-01-09 11:17:47 +01:00
Lennart Poettering 3841fee822 path-util: introduce path_strv_contains() helper
it's like strv_contains() but uses path_equal() rather than streq() to
compare strings.
2020-01-09 11:17:21 +01:00
38 changed files with 431 additions and 333 deletions

View File

@ -388,6 +388,15 @@
<xi:include href="user-system-options.xml" xpointer="host" />
<xi:include href="user-system-options.xml" xpointer="machine" />
<varlistentry>
<term><option>-l</option></term>
<term><option>--full</option></term>
<listitem>
<para>Do not ellipsize the output in <command>list</command> command.</para>
</listitem>
</varlistentry>
<xi:include href="standard-options.xml" xpointer="no-pager" />
<xi:include href="standard-options.xml" xpointer="no-legend" />
<xi:include href="standard-options.xml" xpointer="help" />

View File

@ -680,7 +680,8 @@
<term><option>-l</option></term>
<term><option>--full</option></term>
<listitem><para>Do not ellipsize process tree entries.</para>
<listitem><para>Do not ellipsize process tree entries or table. This implies
<option>--max-addresses=full</option>.</para>
</listitem>
</varlistentry>

View File

@ -316,7 +316,7 @@ s - Service VLAN, m - Two-port MAC Relay (TPMR)
<term><option>--full</option></term>
<listitem>
<para>Do not ellipsize the logs in <command>status</command> command.</para>
<para>Do not ellipsize the output.</para>
</listitem>
</varlistentry>

View File

@ -95,6 +95,15 @@
</listitem>
</varlistentry>
<varlistentry>
<term><option>-l</option></term>
<term><option>--full</option></term>
<listitem>
<para>Do not ellipsize the output when <option>--list</option> is specified.</para>
</listitem>
</varlistentry>
<xi:include href="standard-options.xml" xpointer="no-pager"/>
<xi:include href="standard-options.xml" xpointer="no-legend" />
<xi:include href="standard-options.xml" xpointer="no-ask-password"/>

View File

@ -25,14 +25,14 @@ __contains_word () {
__get_machines() {
local a b
machinectl list --no-legend --no-pager 2>/dev/null |
machinectl list --full --no-legend --no-pager 2>/dev/null |
{ while read a b; do echo " $a"; done; };
}
__get_busnames() {
local mode=$1
local a b
COLUMNS=65535 busctl $mode list --no-legend --no-pager 2>/dev/null |
busctl $mode list --no-legend --no-pager --full 2>/dev/null |
{ while read a b; do echo " $a"; done; };
}
@ -85,7 +85,7 @@ _busctl() {
--show-machine --unique --acquired --activatable --list
-q --quiet --verbose --expect-reply=no --auto-start=no
--allow-interactive-authorization=no --augment-creds=no
--watch-bind=yes -j'
--watch-bind=yes -j -l --full'
[ARG]='--address -H --host -M --machine --match --timeout --size --json
--destination'
)

View File

@ -27,7 +27,7 @@ __contains_word () {
__get_machines() {
local a b
(machinectl list-images --no-legend --no-pager; machinectl list --no-legend --no-pager; echo ".host") | \
(machinectl list-images --full --no-legend --no-pager; machinectl list --full --no-legend --no-pager; echo ".host") | \
{ while read a b; do echo " $a"; done; } | sort -u;
}

View File

@ -31,7 +31,7 @@ __get_all_seats () { loginctl --no-legend list-seats | { while read -r a b
__get_machines() {
local a b
machinectl list --no-legend --no-pager 2>/dev/null |
machinectl list --full --no-legend --no-pager 2>/dev/null |
{ while read a b; do echo " $a"; done; };
}

View File

@ -25,7 +25,7 @@ __contains_word() {
__get_machines() {
local a b
(machinectl list-images --no-legend --no-pager; machinectl list --no-legend --no-pager; echo ".host") | \
(machinectl list-images --full --no-legend --no-pager; machinectl list --full --no-legend --no-pager; echo ".host") | \
{ while read a b; do echo " $a"; done; } | sort -u;
}

View File

@ -25,7 +25,7 @@ __contains_word () {
}
__get_links() {
networkctl list --no-legend --no-pager --all | { while read -r a b c; do echo " $b"; done; };
networkctl list --no-legend --no-pager --all --full | { while read -r a b c; do echo " $b"; done; };
}
_networkctl() {

View File

@ -25,7 +25,7 @@ __contains_word () {
__get_machines() {
local a b
machinectl list --no-legend --no-pager 2>/dev/null |
machinectl list --full --no-legend --no-pager 2>/dev/null |
{ while read a b; do echo " $a"; done; };
}

View File

@ -113,7 +113,7 @@ __get_all_unit_files () { { __systemctl $1 list-unit-files "$2*"; } | { while re
__get_machines() {
local a b
{ machinectl list-images --no-legend --no-pager; machinectl list --no-legend --no-pager; } | \
{ machinectl list-images --full --no-legend --no-pager; machinectl list --full --no-legend --no-pager; } | \
{ while read a b; do echo " $a"; done; }
}

View File

@ -27,7 +27,7 @@ __contains_word () {
__get_machines() {
local a b
machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
}
__get_services() {

View File

@ -25,7 +25,7 @@ __contains_word() {
__get_machines() {
local a b
machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
}
__get_units_have_cgroup() {

View File

@ -25,7 +25,7 @@ __contains_word() {
__get_machines() {
local a b
machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
}
_systemd_cgtop() {

View File

@ -35,7 +35,7 @@ __get_slices() {
__get_machines() {
local a b
machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
}
__get_env() {

View File

@ -26,7 +26,7 @@ __get_slice_units () { __systemctl $1 list-units --all -t slice \
__get_machines() {
local a b
machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
}
_systemd_run() {

View File

@ -27,7 +27,7 @@ __contains_word () {
__get_machines() {
local a b
machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
}
__get_interfaces(){

View File

@ -1484,7 +1484,6 @@ static int assess(const struct security_info *info, Table *overview_table, Analy
if (details_table) {
const char *checkmark, *description, *color = NULL;
TableCell *cell;
if (badness == UINT64_MAX) {
checkmark = " ";
@ -1507,13 +1506,12 @@ static int assess(const struct security_info *info, Table *overview_table, Analy
if (d)
description = d;
r = table_add_cell_full(details_table, &cell, TABLE_STRING, checkmark, 1, 1, 0, 0, 0);
if (r < 0)
return log_error_errno(r, "Failed to add cell to table: %m");
if (color)
(void) table_set_color(details_table, cell, color);
r = table_add_many(details_table,
TABLE_STRING, checkmark,
TABLE_SET_MINIMUM_WIDTH, 1,
TABLE_SET_MAXIMUM_WIDTH, 1,
TABLE_SET_ELLIPSIZE_PERCENT, 0,
TABLE_SET_COLOR, color,
TABLE_STRING, a->id, TABLE_SET_URL, a->url,
TABLE_STRING, description,
TABLE_UINT64, a->weight, TABLE_SET_ALIGN_PERCENT, 100,
@ -1521,7 +1519,7 @@ static int assess(const struct security_info *info, Table *overview_table, Analy
TABLE_UINT64, a->range, TABLE_SET_ALIGN_PERCENT, 100,
TABLE_EMPTY, TABLE_SET_ALIGN_PERCENT, 100);
if (r < 0)
return log_error_errno(r, "Failed to add cells to table: %m");
return table_log_add_error(r);
}
}
@ -1597,35 +1595,26 @@ static int assess(const struct security_info *info, Table *overview_table, Analy
if (overview_table) {
char buf[DECIMAL_STR_MAX(uint64_t) + 1 + DECIMAL_STR_MAX(uint64_t) + 1];
TableCell *cell;
_cleanup_free_ char *url = NULL;
r = table_add_cell(overview_table, &cell, TABLE_STRING, info->id);
if (r < 0)
return log_error_errno(r, "Failed to add cell to table: %m");
if (info->fragment_path) {
_cleanup_free_ char *url = NULL;
r = file_url_from_path(info->fragment_path, &url);
if (r < 0)
return log_error_errno(r, "Failed to generate URL from path: %m");
(void) table_set_url(overview_table, cell, url);
}
xsprintf(buf, "%" PRIu64 ".%" PRIu64, exposure / 10, exposure % 10);
r = table_add_cell(overview_table, &cell, TABLE_STRING, buf);
if (r < 0)
return log_error_errno(r, "Failed to add cell to table: %m");
(void) table_set_align_percent(overview_table, cell, 100);
r = table_add_cell(overview_table, &cell, TABLE_STRING, badness_table[i].name);
r = table_add_many(overview_table,
TABLE_STRING, info->id,
TABLE_SET_URL, url,
TABLE_STRING, buf,
TABLE_SET_ALIGN_PERCENT, 100,
TABLE_STRING, badness_table[i].name,
TABLE_SET_COLOR, strempty(badness_table[i].color),
TABLE_STRING, special_glyph(badness_table[i].smiley));
if (r < 0)
return log_error_errno(r, "Failed to add cell to table: %m");
(void) table_set_color(overview_table, cell, strempty(badness_table[i].color));
r = table_add_cell(overview_table, NULL, TABLE_STRING, special_glyph(badness_table[i].smiley));
if (r < 0)
return log_error_errno(r, "Failed to add cell to table: %m");
return table_log_add_error(r);
}
return 0;

View File

@ -1113,13 +1113,11 @@ static int analyze_blame(int argc, char *argv[], void *userdata) {
if (u->time <= 0)
continue;
r = table_add_cell(table, NULL, TABLE_TIMESPAN_MSEC, &u->time);
r = table_add_many(table,
TABLE_TIMESPAN_MSEC, &u->time,
TABLE_STRING, u->name);
if (r < 0)
return r;
r = table_add_cell(table, NULL, TABLE_STRING, u->name);
if (r < 0)
return r;
return table_log_add_error(r);
}
(void) pager_open(arg_pager_flags);
@ -1630,7 +1628,7 @@ static int dump_exit_status(int argc, char *argv[], void *userdata) {
TABLE_INT, (int) i,
TABLE_STRING, exit_status_class(i));
if (r < 0)
return r;
return table_log_add_error(r);
}
else
for (int i = 1; i < argc; i++) {
@ -1646,7 +1644,7 @@ static int dump_exit_status(int argc, char *argv[], void *userdata) {
TABLE_INT, status,
TABLE_STRING, exit_status_class(status) ?: "-");
if (r < 0)
return r;
return table_log_add_error(r);
}
(void) pager_open(arg_pager_flags);
@ -1853,33 +1851,23 @@ static int dump_timespan(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
r = table_add_cell(table, NULL, TABLE_STRING, "Original:");
r = table_add_many(table,
TABLE_STRING, "Original:",
TABLE_STRING, *input_timespan);
if (r < 0)
return r;
r = table_add_cell(table, NULL, TABLE_STRING, *input_timespan);
if (r < 0)
return r;
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%ss:", special_glyph(SPECIAL_GLYPH_MU));
if (r < 0)
return r;
return table_log_add_error(r);
r = table_add_cell(table, NULL, TABLE_UINT64, &output_usecs);
r = table_add_many(table,
TABLE_UINT64, &output_usecs,
TABLE_STRING, "Human:",
TABLE_TIMESPAN, &output_usecs,
TABLE_SET_COLOR, ansi_highlight());
if (r < 0)
return r;
r = table_add_cell(table, NULL, TABLE_STRING, "Human:");
if (r < 0)
return r;
r = table_add_cell(table, &cell, TABLE_TIMESPAN, &output_usecs);
if (r < 0)
return r;
r = table_set_color(table, cell, ansi_highlight());
if (r < 0)
return r;
return table_log_add_error(r);
r = table_print(table, NULL);
if (r < 0)
@ -1925,57 +1913,42 @@ static int test_timestamp_one(const char *p) {
if (r < 0)
return r;
r = table_add_cell(table, NULL, TABLE_STRING, "Original form:");
r = table_add_many(table,
TABLE_STRING, "Original form:",
TABLE_STRING, p,
TABLE_STRING, "Normalized form:",
TABLE_TIMESTAMP, &usec,
TABLE_SET_COLOR, ansi_highlight_blue());
if (r < 0)
return r;
r = table_add_cell(table, NULL, TABLE_STRING, p);
if (r < 0)
return r;
r = table_add_cell(table, NULL, TABLE_STRING, "Normalized form:");
if (r < 0)
return r;
r = table_add_cell(table, &cell, TABLE_TIMESTAMP, &usec);
if (r < 0)
return r;
r = table_set_color(table, cell, ansi_highlight_blue());
if (r < 0)
return r;
return table_log_add_error(r);
if (!in_utc_timezone()) {
r = table_add_cell(table, NULL, TABLE_STRING, "(in UTC):");
r = table_add_many(table,
TABLE_STRING, "(in UTC):",
TABLE_TIMESTAMP_UTC, &usec);
if (r < 0)
return r;
r = table_add_cell(table, &cell, TABLE_TIMESTAMP_UTC, &usec);
if (r < 0)
return r;
return table_log_add_error(r);
}
r = table_add_cell(table, NULL, TABLE_STRING, "UNIX seconds:");
if (r < 0)
return r;
return table_log_add_error(r);
if (usec % USEC_PER_SEC == 0)
r = table_add_cell_stringf(table, &cell, "@%"PRI_USEC,
r = table_add_cell_stringf(table, NULL, "@%"PRI_USEC,
usec / USEC_PER_SEC);
else
r = table_add_cell_stringf(table, &cell, "@%"PRI_USEC".%06"PRI_USEC"",
r = table_add_cell_stringf(table, NULL, "@%"PRI_USEC".%06"PRI_USEC"",
usec / USEC_PER_SEC,
usec % USEC_PER_SEC);
if (r < 0)
return r;
r = table_add_cell(table, NULL, TABLE_STRING, "From now:");
r = table_add_many(table,
TABLE_STRING, "From now:",
TABLE_TIMESTAMP_RELATIVE, &usec);
if (r < 0)
return r;
r = table_add_cell(table, &cell, TABLE_TIMESTAMP_RELATIVE, &usec);
if (r < 0)
return r;
return table_log_add_error(r);
return table_print(table, NULL);
}
@ -2035,22 +2008,18 @@ static int test_calendar_one(usec_t n, const char *p) {
return r;
if (!streq(t, p)) {
r = table_add_cell(table, NULL, TABLE_STRING, "Original form:");
r = table_add_many(table,
TABLE_STRING, "Original form:",
TABLE_STRING, p);
if (r < 0)
return r;
r = table_add_cell(table, NULL, TABLE_STRING, p);
if (r < 0)
return r;
return table_log_add_error(r);
}
r = table_add_cell(table, NULL, TABLE_STRING, "Normalized form:");
r = table_add_many(table,
TABLE_STRING, "Normalized form:",
TABLE_STRING, t);
if (r < 0)
return r;
r = table_add_cell(table, NULL, TABLE_STRING, t);
if (r < 0)
return r;
return table_log_add_error(r);
for (unsigned i = 0; i < arg_iterations; i++) {
usec_t next;
@ -2058,17 +2027,12 @@ static int test_calendar_one(usec_t n, const char *p) {
r = calendar_spec_next_usec(spec, n, &next);
if (r == -ENOENT) {
if (i == 0) {
r = table_add_cell(table, NULL, TABLE_STRING, "Next elapse:");
r = table_add_many(table,
TABLE_STRING, "Next elapse:",
TABLE_STRING, "never",
TABLE_SET_COLOR, ansi_highlight_yellow());
if (r < 0)
return r;
r = table_add_cell(table, &cell, TABLE_STRING, "never");
if (r < 0)
return r;
r = table_set_color(table, cell, ansi_highlight_yellow());
if (r < 0)
return r;
return table_log_add_error(r);
}
break;
}
@ -2076,17 +2040,12 @@ static int test_calendar_one(usec_t n, const char *p) {
return log_error_errno(r, "Failed to determine next elapse for '%s': %m", p);
if (i == 0) {
r = table_add_cell(table, NULL, TABLE_STRING, "Next elapse:");
r = table_add_many(table,
TABLE_STRING, "Next elapse:",
TABLE_TIMESTAMP, &next,
TABLE_SET_COLOR, ansi_highlight_blue());
if (r < 0)
return r;
r = table_add_cell(table, &cell, TABLE_TIMESTAMP, &next);
if (r < 0)
return r;
r = table_set_color(table, cell, ansi_highlight_blue());
if (r < 0)
return r;
return table_log_add_error(r);
} else {
int k = DECIMAL_STR_WIDTH(i + 1);
@ -2097,34 +2056,28 @@ static int test_calendar_one(usec_t n, const char *p) {
r = table_add_cell_stringf(table, NULL, "Iter. #%u:", i+1);
if (r < 0)
return r;
return table_log_add_error(r);
r = table_add_cell(table, &cell, TABLE_TIMESTAMP, &next);
r = table_add_many(table,
TABLE_TIMESTAMP, &next,
TABLE_SET_COLOR, ansi_highlight_blue());
if (r < 0)
return r;
r = table_set_color(table, cell, ansi_highlight_blue());
if (r < 0)
return r;
return table_log_add_error(r);
}
if (!in_utc_timezone()) {
r = table_add_cell(table, NULL, TABLE_STRING, "(in UTC):");
r = table_add_many(table,
TABLE_STRING, "(in UTC):",
TABLE_TIMESTAMP_UTC, &next);
if (r < 0)
return r;
r = table_add_cell(table, NULL, TABLE_TIMESTAMP_UTC, &next);
if (r < 0)
return r;
return table_log_add_error(r);
}
r = table_add_cell(table, NULL, TABLE_STRING, "From now:");
r = table_add_many(table,
TABLE_STRING, "From now:",
TABLE_TIMESTAMP_RELATIVE, &next);
if (r < 0)
return r;
r = table_add_cell(table, NULL, TABLE_TIMESTAMP_RELATIVE, &next);
if (r < 0)
return r;
return table_log_add_error(r);
n = next;
}

View File

@ -1115,3 +1115,13 @@ bool empty_or_root(const char *root) {
return root[strspn(root, "/")] == 0;
}
bool path_strv_contains(char **l, const char *path) {
char **i;
STRV_FOREACH(i, l)
if (path_equal(*i, path))
return true;
return false;
}

View File

@ -71,17 +71,7 @@ static inline bool path_equal_ptr(const char *a, const char *b) {
}
/* Note: the search terminates on the first NULL item. */
#define PATH_IN_SET(p, ...) \
({ \
char **_s; \
bool _found = false; \
STRV_FOREACH(_s, STRV_MAKE(__VA_ARGS__)) \
if (path_equal(p, *_s)) { \
_found = true; \
break; \
} \
_found; \
})
#define PATH_IN_SET(p, ...) path_strv_contains(STRV_MAKE(__VA_ARGS__), p)
char* path_startswith_strv(const char *p, char **set);
#define PATH_STARTSWITH_SET(p, ...) path_startswith_strv(p, STRV_MAKE(__VA_ARGS__))
@ -181,3 +171,5 @@ bool empty_or_root(const char *root);
static inline const char *empty_to_root(const char *path) {
return isempty(path) ? "/" : path;
}
bool path_strv_contains(char **l, const char *path);

View File

@ -38,6 +38,7 @@ static enum {
} arg_json = JSON_OFF;
static PagerFlags arg_pager_flags = 0;
static bool arg_legend = true;
static bool arg_full = false;
static const char *arg_address = NULL;
static bool arg_unique = false;
static bool arg_acquired = false;
@ -195,6 +196,9 @@ static int list_bus_names(int argc, char **argv, void *userdata) {
if (!table)
return log_oom();
if (arg_full)
table_set_width(table, 0);
r = table_set_align_percent(table, table_get_cell(table, 0, COLUMN_PID), 100);
if (r < 0)
return log_error_errno(r, "Failed to set alignment: %m");
@ -233,7 +237,7 @@ static int list_bus_names(int argc, char **argv, void *userdata) {
TABLE_EMPTY,
TABLE_EMPTY);
if (r < 0)
return log_error_errno(r, "Failed to fill line: %m");
return table_log_add_error(r);
continue;
}
@ -250,7 +254,7 @@ static int list_bus_names(int argc, char **argv, void *userdata) {
TABLE_INT, PTR_TO_INT(v),
TABLE_STRING, k);
if (r < 0)
return log_error_errno(r, "Failed to add name %s to table: %m", k);
return table_log_add_error(r);
r = sd_bus_get_name_creds(
bus, k,
@ -279,7 +283,7 @@ static int list_bus_names(int argc, char **argv, void *userdata) {
} else
r = table_add_many(table, TABLE_EMPTY, TABLE_EMPTY);
if (r < 0)
return log_error_errno(r, "Failed to add fields to table: %m");
return table_log_add_error(r);
r = sd_bus_creds_get_euid(creds, &uid);
if (r >= 0) {
@ -293,7 +297,7 @@ static int list_bus_names(int argc, char **argv, void *userdata) {
} else
r = table_add_cell(table, NULL, TABLE_EMPTY, NULL);
if (r < 0)
return log_error_errno(r, "Failed to add field to table: %m");
return table_log_add_error(r);
(void) sd_bus_creds_get_unique_name(creds, &unique);
(void) sd_bus_creds_get_unit(creds, &unit);
@ -308,7 +312,7 @@ static int list_bus_names(int argc, char **argv, void *userdata) {
TABLE_STRING, cn);
}
if (r < 0)
return log_error_errno(r, "Failed to add fields to table: %m");
return table_log_add_error(r);
if (arg_show_machine) {
sd_id128_t mid;
@ -321,7 +325,7 @@ static int list_bus_names(int argc, char **argv, void *userdata) {
r = table_add_cell(table, NULL, TABLE_STRING, sd_id128_to_string(mid, m));
if (r < 0)
return log_error_errno(r, "Failed to add field to table: %m");
return table_log_add_error(r);
continue; /* line fully filled, no need to fill the remainder below */
}
@ -2251,6 +2255,7 @@ static int help(void) {
" --version Show package version\n"
" --no-pager Do not pipe output into a pager\n"
" --no-legend Do not show the headers and footers\n"
" -l --full Do not ellipsize output\n"
" --system Connect to system bus\n"
" --user Connect to user bus\n"
" -H --host=[USER@]HOST Operate on remote host\n"
@ -2323,6 +2328,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "version", no_argument, NULL, ARG_VERSION },
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
{ "no-legend", no_argument, NULL, ARG_NO_LEGEND },
{ "full", no_argument, NULL, 'l' },
{ "system", no_argument, NULL, ARG_SYSTEM },
{ "user", no_argument, NULL, ARG_USER },
{ "address", required_argument, NULL, ARG_ADDRESS },
@ -2372,6 +2378,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_legend = false;
break;
case 'l':
arg_full = true;
break;
case ARG_USER:
arg_user = true;
break;

View File

@ -12,16 +12,23 @@
#include "unit.h"
static int swap_get_priority(Swap *s) {
if (s->from_proc_swaps)
assert(s);
if (s->from_proc_swaps && s->parameters_proc_swaps.priority_set)
return s->parameters_proc_swaps.priority;
if (s->from_fragment)
if (s->from_fragment && s->parameters_fragment.priority_set)
return s->parameters_fragment.priority;
return -1;
}
static const char *swap_get_options(Swap *s) {
assert(s);
if (s->from_fragment)
return s->parameters_fragment.options;
return NULL;
}

View File

@ -435,7 +435,7 @@ Automount.DirectoryMode, config_parse_mode, 0,
Automount.TimeoutIdleSec, config_parse_sec_fix_0, 0, offsetof(Automount, timeout_idle_usec)
m4_dnl
Swap.What, config_parse_unit_path_printf, 0, offsetof(Swap, parameters_fragment.what)
Swap.Priority, config_parse_int, 0, offsetof(Swap, parameters_fragment.priority)
Swap.Priority, config_parse_swap_priority, 0, 0
Swap.Options, config_parse_unit_string_printf, 0, offsetof(Swap, parameters_fragment.options)
Swap.TimeoutSec, config_parse_sec_fix_0, 0, offsetof(Swap, timeout_usec)
EXEC_CONTEXT_CONFIG_ITEMS(Swap)m4_dnl

View File

@ -5002,3 +5002,51 @@ int config_parse_crash_chvt(
return 0;
}
int config_parse_swap_priority(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
Swap *s = userdata;
int r, priority;
assert(s);
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
if (isempty(rvalue)) {
s->parameters_fragment.priority = -1;
s->parameters_fragment.priority_set = false;
return 0;
}
r = safe_atoi(rvalue, &priority);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Invalid swap pririty '%s', ignoring.", rvalue);
return 0;
}
if (priority < -1) {
log_syntax(unit, LOG_ERR, filename, line, 0, "Sorry, swap priorities smaller than -1 may only be assigned by the kernel itself, ignoring: %s", rvalue);
return 0;
}
if (priority > 32767) {
log_syntax(unit, LOG_ERR, filename, line, 0, "Swap priority out of range, ignoring: %s", rvalue);
return 0;
}
s->parameters_fragment.priority = priority;
s->parameters_fragment.priority_set = true;
return 0;
}

View File

@ -121,6 +121,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_status_unit_format);
CONFIG_PARSER_PROTOTYPE(config_parse_output_restricted);
CONFIG_PARSER_PROTOTYPE(config_parse_crash_chvt);
CONFIG_PARSER_PROTOTYPE(config_parse_timeout_abort);
CONFIG_PARSER_PROTOTYPE(config_parse_swap_priority);
/* gperf prototypes */
const struct ConfigPerfItem* load_fragment_gperf_lookup(const char *key, GPERF_LEN_TYPE length);

View File

@ -1190,6 +1190,57 @@ static void normalize_mounts(const char *root_directory, MountEntry *mounts, siz
drop_nop(mounts, n_mounts);
}
static bool root_read_only(
char **read_only_paths,
ProtectSystem protect_system) {
/* Determine whether the root directory is going to be read-only given the configured settings. */
if (protect_system == PROTECT_SYSTEM_STRICT)
return true;
if (path_strv_contains(read_only_paths, "/"))
return true;
return false;
}
static bool home_read_only(
char** read_only_paths,
char** inaccessible_paths,
char** empty_directories,
const BindMount *bind_mounts,
size_t n_bind_mounts,
const TemporaryFileSystem *temporary_filesystems,
size_t n_temporary_filesystems,
ProtectHome protect_home) {
size_t i;
/* Determine whether the /home directory is going to be read-only given the configured settings. Yes,
* this is a bit sloppy, since we don't bother checking for cases where / is affected by multiple
* settings. */
if (protect_home != PROTECT_HOME_NO)
return true;
if (path_strv_contains(read_only_paths, "/home") ||
path_strv_contains(inaccessible_paths, "/home") ||
path_strv_contains(empty_directories, "/home"))
return true;
for (i = 0; i < n_temporary_filesystems; i++)
if (path_equal(temporary_filesystems[i].path, "/home"))
return true;
/* If /home is overmounted with some dir from the host it's not writable. */
for (i = 0; i < n_bind_mounts; i++)
if (path_equal(bind_mounts[i].destination, "/home"))
return true;
return false;
}
int setup_namespace(
const char* root_directory,
const char* root_image,
@ -1228,13 +1279,17 @@ int setup_namespace(
if (root_image) {
dissect_image_flags |= DISSECT_IMAGE_REQUIRE_ROOT;
if (protect_system == PROTECT_SYSTEM_STRICT &&
protect_home != PROTECT_HOME_NO &&
/* Make the whole image read-only if we can determine that we only access it in a read-only fashion. */
if (root_read_only(read_only_paths,
protect_system) &&
home_read_only(read_only_paths, inaccessible_paths, empty_directories,
bind_mounts, n_bind_mounts, temporary_filesystems, n_temporary_filesystems,
protect_home) &&
strv_isempty(read_write_paths))
dissect_image_flags |= DISSECT_IMAGE_READ_ONLY;
r = loop_device_make_by_path(root_image,
dissect_image_flags & DISSECT_IMAGE_READ_ONLY ? O_RDONLY : O_RDWR,
FLAGS_SET(dissect_image_flags, DISSECT_IMAGE_READ_ONLY) ? O_RDONLY : -1 /* < 0 means writable if possible, read-only as fallback */,
LO_FLAGS_PARTSCAN,
&loop_device);
if (r < 0)

View File

@ -63,7 +63,6 @@ static void swap_unset_proc_swaps(Swap *s) {
return;
s->parameters_proc_swaps.what = mfree(s->parameters_proc_swaps.what);
s->from_proc_swaps = false;
}
@ -117,9 +116,6 @@ static void swap_init(Unit *u) {
s->exec_context.std_output = u->manager->default_std_output;
s->exec_context.std_error = u->manager->default_std_error;
s->parameters_proc_swaps.priority = s->parameters_fragment.priority = 0;
s->parameters_fragment.priority_set = false;
s->control_command_id = _SWAP_EXEC_COMMAND_INVALID;
u->ignore_on_isolate = true;
@ -772,17 +768,19 @@ static void swap_enter_activating(Swap *s) {
r = fstab_find_pri(s->parameters_fragment.options, &priority);
if (r < 0)
log_warning_errno(r, "Failed to parse swap priority \"%s\", ignoring: %m", s->parameters_fragment.options);
else if (r == 1 && s->parameters_fragment.priority_set)
log_warning("Duplicate swap priority configuration by Priority and Options fields.");
log_unit_warning_errno(UNIT(s), r, "Failed to parse swap priority \"%s\", ignoring: %m", s->parameters_fragment.options);
else if (r > 0 && s->parameters_fragment.priority_set)
log_unit_warning(UNIT(s), "Duplicate swap priority configuration by Priority= and Options= fields.");
if (r <= 0 && s->parameters_fragment.priority_set) {
if (s->parameters_fragment.options)
r = asprintf(&opts, "%s,pri=%i", s->parameters_fragment.options, s->parameters_fragment.priority);
else
r = asprintf(&opts, "pri=%i", s->parameters_fragment.priority);
if (r < 0)
if (r < 0) {
r = -ENOMEM;
goto fail;
}
}
}
@ -792,7 +790,7 @@ static void swap_enter_activating(Swap *s) {
if (s->parameters_fragment.options || opts) {
r = exec_command_append(s->control_command, "-o",
opts ? : s->parameters_fragment.options, NULL);
opts ?: s->parameters_fragment.options, NULL);
if (r < 0)
goto fail;
}
@ -808,7 +806,6 @@ static void swap_enter_activating(Swap *s) {
goto fail;
swap_set_state(s, SWAP_ACTIVATING);
return;
fail:

View File

@ -122,7 +122,7 @@ static int print_inhibitors(sd_bus *bus) {
TABLE_STRING, why,
TABLE_STRING, mode);
if (r < 0)
return log_error_errno(r, "Failed to add table row: %m");
return table_log_add_error(r);
}
r = sd_bus_message_exit_container(reply);

View File

@ -189,7 +189,7 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
TABLE_STRING, seat,
TABLE_STRING, strna(tty));
if (r < 0)
return log_error_errno(r, "Failed to add row to table: %m");
return table_log_add_error(r);
}
r = sd_bus_message_exit_container(reply);
@ -246,7 +246,7 @@ static int list_users(int argc, char *argv[], void *userdata) {
TABLE_UID, (uid_t) uid,
TABLE_STRING, user);
if (r < 0)
return log_error_errno(r, "Failed to add row to table: %m");
return table_log_add_error(r);
}
r = sd_bus_message_exit_container(reply);
@ -298,7 +298,7 @@ static int list_seats(int argc, char *argv[], void *userdata) {
r = table_add_cell(table, NULL, TABLE_STRING, seat);
if (r < 0)
return log_error_errno(r, "Failed to add row to table: %m");
return table_log_add_error(r);
}
r = sd_bus_message_exit_container(reply);

View File

@ -306,6 +306,9 @@ static int list_machines(int argc, char *argv[], void *userdata) {
if (!table)
return log_oom();
if (arg_full)
table_set_width(table, 0);
r = sd_bus_message_enter_container(reply, 'a', "(ssso)");
if (r < 0)
return bus_log_parse_error(r);
@ -338,7 +341,7 @@ static int list_machines(int argc, char *argv[], void *userdata) {
0,
"",
" ",
arg_addrs,
arg_full ? ALL_IP_ADDRESSES : arg_addrs,
&addresses);
r = table_add_many(table,
@ -349,7 +352,7 @@ static int list_machines(int argc, char *argv[], void *userdata) {
TABLE_STRING, empty_to_dash(version_id),
TABLE_STRING, empty_to_dash(addresses));
if (r < 0)
return log_error_errno(r, "Failed to add table row: %m");
return table_log_add_error(r);
}
r = sd_bus_message_exit_container(reply);
@ -386,6 +389,9 @@ static int list_images(int argc, char *argv[], void *userdata) {
if (!table)
return log_oom();
if (arg_full)
table_set_width(table, 0);
(void) table_set_align_percent(table, TABLE_HEADER_CELL(3), 100);
r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssbttto)");
@ -395,8 +401,6 @@ static int list_images(int argc, char *argv[], void *userdata) {
for (;;) {
uint64_t crtime, mtime, size;
const char *name, *type;
TableCell *cell;
bool ro_bool;
int ro_int;
r = sd_bus_message_read(reply, "(ssbttto)", &name, &type, &ro_int, &crtime, &mtime, &size, NULL);
@ -410,27 +414,14 @@ static int list_images(int argc, char *argv[], void *userdata) {
r = table_add_many(table,
TABLE_STRING, name,
TABLE_STRING, type);
if (r < 0)
return log_error_errno(r, "Failed to add table row: %m");
ro_bool = ro_int;
r = table_add_cell(table, &cell, TABLE_BOOLEAN, &ro_bool);
if (r < 0)
return log_error_errno(r, "Failed to add table cell: %m");
if (ro_bool) {
r = table_set_color(table, cell, ansi_highlight_red());
if (r < 0)
return log_error_errno(r, "Failed to set table cell color: %m");
}
r = table_add_many(table,
TABLE_STRING, type,
TABLE_BOOLEAN, ro_int,
TABLE_SET_COLOR, ro_int ? ansi_highlight_red() : NULL,
TABLE_SIZE, size,
TABLE_TIMESTAMP, crtime,
TABLE_TIMESTAMP, mtime);
if (r < 0)
return log_error_errno(r, "Failed to add table row: %m");
return table_log_add_error(r);
}
r = sd_bus_message_exit_container(reply);

View File

@ -46,6 +46,7 @@ enum {
static bool arg_no_block = false;
static PagerFlags arg_pager_flags = 0;
static bool arg_legend = true;
static bool arg_full = false;
static bool arg_ask_password = true;
static bool arg_quiet = false;
static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
@ -92,6 +93,7 @@ static int help(void) {
" --no-block Do not wait until operation finished\n"
" --no-pager Do not pipe output into a pager\n"
" --no-legend Do not show the headers\n"
" -l --full Do not ellipsize output\n"
" --no-ask-password Do not prompt for password\n"
" -q --quiet Suppress information messages during runtime\n"
" --user Run as user unit\n"
@ -150,6 +152,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "no-block", no_argument, NULL, ARG_NO_BLOCK },
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
{ "no-legend", no_argument, NULL, ARG_NO_LEGEND },
{ "full", no_argument, NULL, 'l' },
{ "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD },
{ "quiet", no_argument, NULL, 'q' },
{ "user", no_argument, NULL, ARG_USER },
@ -182,7 +185,7 @@ static int parse_argv(int argc, char *argv[]) {
if (strstr(program_invocation_short_name, "systemd-umount"))
arg_action = ACTION_UMOUNT;
while ((c = getopt_long(argc, argv, "hqH:M:t:o:p:AuG", options, NULL)) >= 0)
while ((c = getopt_long(argc, argv, "hqH:M:t:o:p:AuGl", options, NULL)) >= 0)
switch (c) {
@ -204,6 +207,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_legend = false;
break;
case 'l':
arg_full = true;
break;
case ARG_NO_ASK_PASSWORD:
arg_ask_password = false;
break;
@ -1393,6 +1400,9 @@ static int list_devices(void) {
if (!table)
return log_oom();
if (arg_full)
table_set_width(table, 0);
r = table_set_sort(table, 0, SIZE_MAX);
if (r < 0)
return log_error_errno(r, "Failed to set sort index: %m");
@ -1436,7 +1446,7 @@ static int list_devices(void) {
r = table_add_cell(table, NULL, c == COLUMN_NODE ? TABLE_PATH : TABLE_STRING, strna(x));
if (r < 0)
return log_error_errno(r, "Failed to add cell: %m");
return table_log_add_error(r);
}
}

View File

@ -518,6 +518,9 @@ static int list_links(int argc, char *argv[], void *userdata) {
if (!table)
return log_oom();
if (arg_full)
table_set_width(table, 0);
table_set_header(table, arg_legend);
assert_se(cell = table_get_cell(table, 0, 0));
@ -554,7 +557,7 @@ static int list_links(int argc, char *argv[], void *userdata) {
TABLE_STRING, strna(setup_state),
TABLE_SET_COLOR, on_color_setup);
if (r < 0)
return r;
return table_log_add_error(r);
}
r = table_print(table, NULL);
@ -729,7 +732,7 @@ static int dump_gateways(
TABLE_EMPTY,
TABLE_STRING, i == 0 ? "Gateway:" : "");
if (r < 0)
return r;
return table_log_add_error(r);
r = in_addr_to_string(local[i].family, &local[i].address, &gateway);
if (r < 0)
@ -755,7 +758,7 @@ static int dump_gateways(
} else
r = table_add_cell(table, NULL, TABLE_STRING, with_description ?: gateway);
if (r < 0)
return r;
return table_log_add_error(r);
}
return 0;
@ -786,7 +789,7 @@ static int dump_addresses(
TABLE_EMPTY,
TABLE_STRING, i == 0 ? "Address:" : "");
if (r < 0)
return r;
return table_log_add_error(r);
r = in_addr_to_string(local[i].family, &local[i].address, &pretty);
if (r < 0)
@ -809,7 +812,7 @@ static int dump_addresses(
} else
r = table_add_cell(table, NULL, TABLE_STRING, pretty);
if (r < 0)
return r;
return table_log_add_error(r);
}
return 0;
@ -838,7 +841,10 @@ static int dump_address_labels(sd_netlink *rtnl) {
table = table_new("label", "prefix/prefixlen");
if (!table)
return -ENOMEM;
return log_oom();
if (arg_full)
table_set_width(table, 0);
r = table_set_sort(table, 0, SIZE_MAX);
if (r < 0)
@ -883,14 +889,18 @@ static int dump_address_labels(sd_netlink *rtnl) {
r = table_add_cell(table, NULL, TABLE_UINT32, &label);
if (r < 0)
return r;
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s/%u", pretty, prefixlen);
if (r < 0)
return r;
return table_log_add_error(r);
}
return table_print(table, NULL);
r = table_print(table, NULL);
if (r < 0)
return log_error_errno(r, "Failed to print table: %m");
return 0;
}
static int list_address_labels(int argc, char *argv[], void *userdata) {
@ -982,7 +992,7 @@ static int dump_lldp_neighbors(Table *table, const char *prefix, int ifindex) {
TABLE_EMPTY,
TABLE_STRING, c == 0 ? prefix : "");
if (r < 0)
return r;
return table_log_add_error(r);
(void) sd_lldp_neighbor_get_system_name(n, &system_name);
(void) sd_lldp_neighbor_get_port_id_as_string(n, &port_id);
@ -995,7 +1005,7 @@ static int dump_lldp_neighbors(Table *table, const char *prefix, int ifindex) {
strempty(port_description),
isempty(port_description) ? "" : ")");
if (r < 0)
return r;
return table_log_add_error(r);
c++;
}
@ -1018,7 +1028,7 @@ static int dump_ifindexes(Table *table, const char *prefix, const int *ifindexes
TABLE_STRING, c == 0 ? prefix : "",
TABLE_IFINDEX, ifindexes[c]);
if (r < 0)
return r;
return table_log_add_error(r);
}
return 0;
@ -1037,7 +1047,7 @@ static int dump_list(Table *table, const char *prefix, char **l) {
TABLE_STRING, i == l ? prefix : "",
TABLE_STRING, *i);
if (r < 0)
return r;
return table_log_add_error(r);
}
return 0;
@ -1048,12 +1058,12 @@ static int dump_list(Table *table, const char *prefix, char **l) {
TABLE_EMPTY, \
TABLE_STRING, name ":"); \
if (r < 0) \
return r; \
return table_log_add_error(r); \
r = table_add_cell(table, NULL, \
info->has_stats64 ? TABLE_UINT64 : TABLE_UINT32, \
info->has_stats64 ? (void*) &info->stats64.val_name : (void*) &info->stats.val_name); \
if (r < 0) \
return r;
return table_log_add_error(r);
static int dump_statistics(Table *table, const LinkInfo *info) {
int r;
@ -1195,7 +1205,10 @@ static int link_status_one(
table = table_new("dot", "key", "value");
if (!table)
return -ENOMEM;
return log_oom();
if (arg_full)
table_set_width(table, 0);
assert_se(cell = table_get_cell(table, 0, 0));
(void) table_set_ellipsize_percent(table, cell, 100);
@ -1209,10 +1222,10 @@ static int link_status_one(
TABLE_STRING, special_glyph(SPECIAL_GLYPH_BLACK_CIRCLE),
TABLE_SET_COLOR, on_color_operational);
if (r < 0)
return r;
return table_log_add_error(r);
r = table_add_cell_stringf(table, &cell, "%i: %s", info->ifindex, info->name);
if (r < 0)
return r;
return table_log_add_error(r);
(void) table_set_align_percent(table, cell, 0);
r = table_add_many(table,
@ -1230,14 +1243,14 @@ static int link_status_one(
TABLE_EMPTY,
TABLE_STRING, "State:");
if (r < 0)
return r;
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s%s%s (%s%s%s)",
on_color_operational, strna(operational_state), off_color_operational,
on_color_setup, strna(setup_state), off_color_setup);
if (r < 0)
return r;
return table_log_add_error(r);
STRV_FOREACH(p, info->alternative_names)
STRV_FOREACH(p, info->alternative_names) {
if (p == info->alternative_names)
r = table_add_many(table,
TABLE_EMPTY,
@ -1248,6 +1261,9 @@ static int link_status_one(
TABLE_EMPTY,
TABLE_EMPTY,
TABLE_STRING, *p);
if (r < 0)
return table_log_add_error(r);
}
if (path) {
r = table_add_many(table,
@ -1255,7 +1271,7 @@ static int link_status_one(
TABLE_STRING, "Path:",
TABLE_STRING, path);
if (r < 0)
return r;
return table_log_add_error(r);
}
if (driver) {
r = table_add_many(table,
@ -1263,7 +1279,7 @@ static int link_status_one(
TABLE_STRING, "Driver:",
TABLE_STRING, driver);
if (r < 0)
return r;
return table_log_add_error(r);
}
if (vendor) {
r = table_add_many(table,
@ -1271,7 +1287,7 @@ static int link_status_one(
TABLE_STRING, "Vendor:",
TABLE_STRING, vendor);
if (r < 0)
return r;
return table_log_add_error(r);
}
if (model) {
r = table_add_many(table,
@ -1279,7 +1295,7 @@ static int link_status_one(
TABLE_STRING, "Model:",
TABLE_STRING, model);
if (r < 0)
return r;
return table_log_add_error(r);
}
if (info->has_mac_address) {
@ -1292,14 +1308,14 @@ static int link_status_one(
TABLE_EMPTY,
TABLE_STRING, "HW Address:");
if (r < 0)
return r;
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s%s%s%s",
ether_addr_to_string(&info->mac_address, ea),
description ? " (" : "",
strempty(description),
description ? ")" : "");
if (r < 0)
return r;
return table_log_add_error(r);
}
if (info->has_permanent_mac_address) {
@ -1312,14 +1328,14 @@ static int link_status_one(
TABLE_EMPTY,
TABLE_STRING, "HW Permanent Address:");
if (r < 0)
return r;
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s%s%s%s",
ether_addr_to_string(&info->permanent_mac_address, ea),
description ? " (" : "",
strempty(description),
description ? ")" : "");
if (r < 0)
return r;
return table_log_add_error(r);
}
if (info->mtu > 0) {
@ -1332,7 +1348,7 @@ static int link_status_one(
TABLE_EMPTY,
TABLE_STRING, "MTU:");
if (r < 0)
return r;
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%" PRIu32 "%s%s%s%s%s%s%s",
info->mtu,
info->min_mtu > 0 || info->max_mtu > 0 ? " (" : "",
@ -1343,7 +1359,7 @@ static int link_status_one(
info->max_mtu > 0 ? max_str : "",
info->min_mtu > 0 || info->max_mtu > 0 ? ")" : "");
if (r < 0)
return r;
return table_log_add_error(r);
}
if (streq_ptr(info->netdev_kind, "bridge")) {
@ -1370,7 +1386,7 @@ static int link_status_one(
TABLE_STRING, "Multicast IGMP Version:",
TABLE_UINT8, info->mcast_igmp_version);
if (r < 0)
return r;
return table_log_add_error(r);
} else if (streq_ptr(info->netdev_kind, "vxlan")) {
if (info->vxlan_info.vni > 0) {
@ -1379,7 +1395,7 @@ static int link_status_one(
TABLE_STRING, "VNI:",
TABLE_UINT32, info->vxlan_info.vni);
if (r < 0)
return r;
return table_log_add_error(r);
}
if (IN_SET(info->vxlan_info.group_family, AF_INET, AF_INET6)) {
@ -1389,7 +1405,7 @@ static int link_status_one(
info->vxlan_info.group_family == AF_INET ? TABLE_IN_ADDR : TABLE_IN6_ADDR,
&info->vxlan_info.group);
if (r < 0)
return r;
return table_log_add_error(r);
}
if (IN_SET(info->vxlan_info.local_family, AF_INET, AF_INET6)) {
@ -1399,7 +1415,7 @@ static int link_status_one(
info->vxlan_info.local_family == AF_INET ? TABLE_IN_ADDR : TABLE_IN6_ADDR,
&info->vxlan_info.local);
if (r < 0)
return r;
return table_log_add_error(r);
}
if (info->vxlan_info.dest_port > 0) {
@ -1408,7 +1424,7 @@ static int link_status_one(
TABLE_STRING, "Destination Port:",
TABLE_UINT16, be16toh(info->vxlan_info.dest_port));
if (r < 0)
return r;
return table_log_add_error(r);
}
if (info->vxlan_info.link > 0) {
@ -1417,7 +1433,7 @@ static int link_status_one(
TABLE_STRING, "Underlying Device:",
TABLE_IFINDEX, info->vxlan_info.link);
if (r < 0)
return r;
return table_log_add_error(r);
}
}
@ -1429,7 +1445,7 @@ static int link_status_one(
TABLE_EMPTY,
TABLE_STRING, "WiFi access point:");
if (r < 0)
return r;
return table_log_add_error(r);
if (info->ssid)
esc = cescape(info->ssid);
@ -1438,7 +1454,7 @@ static int link_status_one(
strnull(esc),
ether_addr_to_string(&info->bssid, buf));
if (r < 0)
return r;
return table_log_add_error(r);
}
if (info->has_bitrates) {
@ -1448,12 +1464,12 @@ static int link_status_one(
TABLE_EMPTY,
TABLE_STRING, "Bit Rate (Tx/Rx):");
if (r < 0)
return r;
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%sbps/%sbps",
format_bytes_full(tx, sizeof tx, info->tx_bitrate, 0),
format_bytes_full(rx, sizeof rx, info->rx_bitrate, 0));
if (r < 0)
return r;
return table_log_add_error(r);
}
if (info->has_tx_queues || info->has_rx_queues) {
@ -1461,10 +1477,10 @@ static int link_status_one(
TABLE_EMPTY,
TABLE_STRING, "Queue Length (Tx/Rx):");
if (r < 0)
return r;
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%" PRIu32 "/%" PRIu32, info->tx_queues, info->rx_queues);
if (r < 0)
return r;
return table_log_add_error(r);
}
if (info->has_ethtool_link_info) {
@ -1477,7 +1493,7 @@ static int link_status_one(
TABLE_STRING, "Auto negotiation:",
TABLE_BOOLEAN, info->autonegotiation == AUTONEG_ENABLE);
if (r < 0)
return r;
return table_log_add_error(r);
}
if (info->speed > 0) {
@ -1486,7 +1502,7 @@ static int link_status_one(
TABLE_STRING, "Speed:",
TABLE_BPS, (uint64_t) info->speed);
if (r < 0)
return r;
return table_log_add_error(r);
}
if (duplex) {
@ -1495,7 +1511,7 @@ static int link_status_one(
TABLE_STRING, "Duplex:",
TABLE_STRING, duplex);
if (r < 0)
return r;
return table_log_add_error(r);
}
if (port) {
@ -1504,7 +1520,7 @@ static int link_status_one(
TABLE_STRING, "Port:",
TABLE_STRING, port);
if (r < 0)
return r;
return table_log_add_error(r);
}
}
@ -1540,7 +1556,7 @@ static int link_status_one(
TABLE_STRING, "Time Zone:",
TABLE_STRING, tz);
if (r < 0)
return r;
return table_log_add_error(r);
}
r = dump_lldp_neighbors(table, "Connected To:", info->ifindex);
@ -1553,7 +1569,7 @@ static int link_status_one(
r = table_print(table, NULL);
if (r < 0)
return r;
return log_error_errno(r, "Failed to print table: %m");
return show_logs(info);
}
@ -1573,7 +1589,10 @@ static int system_status(sd_netlink *rtnl, sd_hwdb *hwdb) {
table = table_new("dot", "key", "value");
if (!table)
return -ENOMEM;
return log_oom();
if (arg_full)
table_set_width(table, 0);
assert_se(cell = table_get_cell(table, 0, 0));
(void) table_set_ellipsize_percent(table, cell, 100);
@ -1590,6 +1609,8 @@ static int system_status(sd_netlink *rtnl, sd_hwdb *hwdb) {
TABLE_STRING, "State:",
TABLE_STRING, strna(operational_state),
TABLE_SET_COLOR, on_color_operational);
if (r < 0)
return table_log_add_error(r);
r = dump_addresses(rtnl, table, 0);
if (r < 0)
@ -1620,7 +1641,7 @@ static int system_status(sd_netlink *rtnl, sd_hwdb *hwdb) {
r = table_print(table, NULL);
if (r < 0)
return r;
return log_error_errno(r, "Failed to print table: %m");
return show_logs(NULL);
}
@ -1740,7 +1761,10 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
"port id",
"port description");
if (!table)
return -ENOMEM;
return log_oom();
if (arg_full)
table_set_width(table, 0);
table_set_header(table, arg_legend);
@ -1829,7 +1853,7 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
TABLE_STRING, strna(port_id),
TABLE_STRING, strna(port_description));
if (r < 0)
return r;
return table_log_add_error(r);
m++;
}
@ -1837,7 +1861,7 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
r = table_print(table, NULL);
if (r < 0)
return r;
return log_error_errno(r, "Failed to print table: %m");
if (arg_legend) {
lldp_capabilities_legend(all);

View File

@ -511,8 +511,6 @@ static int list_images(int argc, char *argv[], void *userdata) {
for (;;) {
const char *name, *type, *state;
uint64_t crtime, mtime, usage;
TableCell *cell;
bool ro_bool;
int ro_int;
r = sd_bus_message_read(reply, "(ssbtttso)", &name, &type, &ro_int, &crtime, &mtime, &usage, &state, NULL);
@ -523,37 +521,16 @@ static int list_images(int argc, char *argv[], void *userdata) {
r = table_add_many(table,
TABLE_STRING, name,
TABLE_STRING, type);
if (r < 0)
return log_error_errno(r, "Failed to add row to table: %m");
ro_bool = ro_int;
r = table_add_cell(table, &cell, TABLE_BOOLEAN, &ro_bool);
if (r < 0)
return log_error_errno(r, "Failed to add row to table: %m");
if (ro_bool) {
r = table_set_color(table, cell, ansi_highlight_red());
if (r < 0)
return log_error_errno(r, "Failed to set table cell color: %m");
}
r = table_add_many(table,
TABLE_STRING, type,
TABLE_BOOLEAN, ro_int,
TABLE_SET_COLOR, ro_int ? ansi_highlight_red() : NULL,
TABLE_TIMESTAMP, crtime,
TABLE_TIMESTAMP, mtime,
TABLE_SIZE, usage);
TABLE_SIZE, usage,
TABLE_STRING, state,
TABLE_SET_COLOR, !streq(state, "detached") ? ansi_highlight_green() : NULL);
if (r < 0)
return log_error_errno(r, "Failed to add row to table: %m");
r = table_add_cell(table, &cell, TABLE_STRING, state);
if (r < 0)
return log_error_errno(r, "Failed to add row to table: %m");
if (!streq(state, "detached")) {
r = table_set_color(table, cell, ansi_highlight_green());
if (r < 0)
return log_error_errno(r, "Failed to set table cell color: %m");
}
return table_log_add_error(r);
}
r = sd_bus_message_exit_container(reply);

View File

@ -118,3 +118,6 @@ const void *table_get_at(Table *t, size_t row, size_t column);
int table_to_json(Table *t, JsonVariant **ret);
int table_print_json(Table *t, FILE *f, JsonFormatFlags json_flags);
#define table_log_add_error(r) \
log_error_errno(r, "Failed to add cell(s) to table: %m")

View File

@ -105,7 +105,6 @@ DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(unit_file_type, UnitFileType);
static int in_search_path(const LookupPaths *p, const char *path) {
_cleanup_free_ char *parent = NULL;
char **i;
assert(path);
@ -113,11 +112,7 @@ static int in_search_path(const LookupPaths *p, const char *path) {
if (!parent)
return -ENOMEM;
STRV_FOREACH(i, p->search_path)
if (path_equal(parent, *i))
return true;
return false;
return path_strv_contains(p->search_path, parent);
}
static const char* skip_root(const LookupPaths *p, const char *path) {

View File

@ -14,6 +14,7 @@
#include <unistd.h>
#include "alloc-util.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "loop-util.h"
@ -157,14 +158,30 @@ int loop_device_make(
int loop_device_make_by_path(const char *path, int open_flags, uint32_t loop_flags, LoopDevice **ret) {
_cleanup_close_ int fd = -1;
int r;
assert(path);
assert(ret);
assert(IN_SET(open_flags, O_RDWR, O_RDONLY));
assert(open_flags < 0 || IN_SET(open_flags, O_RDWR, O_RDONLY));
fd = open(path, O_CLOEXEC|O_NONBLOCK|O_NOCTTY|open_flags);
if (fd < 0)
return -errno;
/* Passing < 0 as open_flags here means we'll try to open the device writable if we can, retrying
* read-only if we cannot. */
fd = open(path, O_CLOEXEC|O_NONBLOCK|O_NOCTTY|(open_flags >= 0 ? open_flags : O_RDWR));
if (fd < 0) {
r = -errno;
/* Retry read-only? */
if (open_flags >= 0 || !(ERRNO_IS_PRIVILEGE(r) || r == -EROFS))
return r;
fd = open(path, O_CLOEXEC|O_NONBLOCK|O_NOCTTY|O_RDONLY);
if (fd < 0)
return r; /* Propagate original error */
open_flags = O_RDONLY;
} else if (open_flags < 0)
open_flags = O_RDWR;
return loop_device_make(fd, open_flags, 0, 0, loop_flags, ret);
}

View File

@ -100,7 +100,7 @@ static int print_status_info(const StatusInfo *i) {
TABLE_STRING, "Local time:",
TABLE_STRING, have_time && n > 0 ? a : "n/a");
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
if (have_time)
n = strftime(a, sizeof a, "%a %Y-%m-%d %H:%M:%S UTC", gmtime_r(&sec, &tm));
@ -109,7 +109,7 @@ static int print_status_info(const StatusInfo *i) {
TABLE_STRING, "Universal time:",
TABLE_STRING, have_time && n > 0 ? a : "n/a");
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
if (i->rtc_time > 0) {
time_t rtc_sec;
@ -122,18 +122,18 @@ static int print_status_info(const StatusInfo *i) {
TABLE_STRING, "RTC time:",
TABLE_STRING, i->rtc_time > 0 && n > 0 ? a : "n/a");
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
if (have_time)
n = strftime(a, sizeof a, "%Z, %z", localtime_r(&sec, &tm));
r = table_add_cell(table, NULL, TABLE_STRING, "Time zone:");
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s (%s)", strna(i->timezone), have_time && n > 0 ? a : "n/a");
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
/* Restore the $TZ */
@ -154,7 +154,7 @@ static int print_status_info(const StatusInfo *i) {
TABLE_STRING, "RTC in local TZ:",
TABLE_BOOLEAN, i->rtc_local);
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
r = table_print(table, NULL);
if (r < 0)
@ -429,29 +429,29 @@ static int print_ntp_status_info(NTPStatusInfo *i) {
r = table_add_cell(table, NULL, TABLE_STRING, "Server:");
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s (%s)", i->server_address, i->server_name);
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
r = table_add_cell(table, NULL, TABLE_STRING, "Poll interval:");
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s (min: %s; max %s)",
format_timespan(ts, sizeof(ts), i->poll_interval, 0),
format_timespan(tmin, sizeof(tmin), i->poll_min, 0),
format_timespan(tmax, sizeof(tmax), i->poll_max, 0));
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
if (i->packet_count == 0) {
r = table_add_many(table,
TABLE_STRING, "Packet count:",
TABLE_STRING, "0");
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
r = table_print(table, NULL);
if (r < 0)
@ -487,44 +487,44 @@ static int print_ntp_status_info(NTPStatusInfo *i) {
TABLE_UINT32, i->stratum,
TABLE_STRING, "Reference:");
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
if (i->stratum <= 1)
r = table_add_cell(table, NULL, TABLE_STRING, i->reference.str);
else
r = table_add_cell_stringf(table, NULL, "%" PRIX32, be32toh(i->reference.val));
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
r = table_add_cell(table, NULL, TABLE_STRING, "Precision:");
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s (%" PRIi32 ")",
format_timespan(ts, sizeof(ts), DIV_ROUND_UP((nsec_t) (exp2(i->precision) * NSEC_PER_SEC), NSEC_PER_USEC), 0),
i->precision);
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
r = table_add_cell(table, NULL, TABLE_STRING, "Root distance:");
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s (max: %s)",
format_timespan(ts, sizeof(ts), root_distance, 0),
format_timespan(tmax, sizeof(tmax), i->root_distance_max, 0));
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
r = table_add_cell(table, NULL, TABLE_STRING, "Offset:");
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s%s",
offset_sign ? "+" : "-",
format_timespan(ts, sizeof(ts), offset, 0));
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
r = table_add_many(table,
TABLE_STRING, "Delay:",
@ -534,16 +534,16 @@ static int print_ntp_status_info(NTPStatusInfo *i) {
TABLE_STRING, "Packet count:",
TABLE_UINT64, i->packet_count);
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
if (!i->spike) {
r = table_add_cell(table, NULL, TABLE_STRING, "Frequency:");
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%+.3fppm", (double) i->freq / 0x10000);
if (r < 0)
return log_error_errno(r, "Failed to add cell(s): %m");
return table_log_add_error(r);
}
r = table_print(table, NULL);