Compare commits

..

No commits in common. "cd6cf81b3fca3fd389a9d1b5586cdd653e603b9e" and "0e05be8405132fb392bc0bd01ea520e58d447467" have entirely different histories.

38 changed files with 334 additions and 432 deletions

View File

@ -388,15 +388,6 @@
<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,8 +680,7 @@
<term><option>-l</option></term>
<term><option>--full</option></term>
<listitem><para>Do not ellipsize process tree entries or table. This implies
<option>--max-addresses=full</option>.</para>
<listitem><para>Do not ellipsize process tree entries.</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 output.</para>
<para>Do not ellipsize the logs in <command>status</command> command.</para>
</listitem>
</varlistentry>

View File

@ -95,15 +95,6 @@
</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 --full --no-legend --no-pager 2>/dev/null |
machinectl list --no-legend --no-pager 2>/dev/null |
{ while read a b; do echo " $a"; done; };
}
__get_busnames() {
local mode=$1
local a b
busctl $mode list --no-legend --no-pager --full 2>/dev/null |
COLUMNS=65535 busctl $mode list --no-legend --no-pager 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 -l --full'
--watch-bind=yes -j'
[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 --full --no-legend --no-pager; machinectl list --full --no-legend --no-pager; echo ".host") | \
(machinectl list-images --no-legend --no-pager; machinectl list --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 --full --no-legend --no-pager 2>/dev/null |
machinectl list --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 --full --no-legend --no-pager; machinectl list --full --no-legend --no-pager; echo ".host") | \
(machinectl list-images --no-legend --no-pager; machinectl list --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 --full | { while read -r a b c; do echo " $b"; done; };
networkctl list --no-legend --no-pager --all | { 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 --full --no-legend --no-pager 2>/dev/null |
machinectl list --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 --full --no-legend --no-pager; machinectl list --full --no-legend --no-pager; } | \
{ machinectl list-images --no-legend --no-pager; machinectl list --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 --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
machinectl list --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 --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
machinectl list --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 --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
machinectl list --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 --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
machinectl list --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 --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
machinectl list --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 --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
}
__get_interfaces(){

View File

@ -1484,6 +1484,7 @@ 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 = " ";
@ -1506,12 +1507,13 @@ 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,
@ -1519,7 +1521,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 table_log_add_error(r);
return log_error_errno(r, "Failed to add cells to table: %m");
}
}
@ -1595,26 +1597,35 @@ 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;
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;
if (info->fragment_path) {
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_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));
r = table_add_cell(overview_table, &cell, TABLE_STRING, buf);
if (r < 0)
return table_log_add_error(r);
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);
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 0;

View File

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

View File

@ -1115,13 +1115,3 @@ 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,7 +71,17 @@ 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, ...) path_strv_contains(STRV_MAKE(__VA_ARGS__), p)
#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; \
})
char* path_startswith_strv(const char *p, char **set);
#define PATH_STARTSWITH_SET(p, ...) path_startswith_strv(p, STRV_MAKE(__VA_ARGS__))
@ -171,5 +181,3 @@ 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,7 +38,6 @@ 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;
@ -196,9 +195,6 @@ 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");
@ -237,7 +233,7 @@ static int list_bus_names(int argc, char **argv, void *userdata) {
TABLE_EMPTY,
TABLE_EMPTY);
if (r < 0)
return table_log_add_error(r);
return log_error_errno(r, "Failed to fill line: %m");
continue;
}
@ -254,7 +250,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 table_log_add_error(r);
return log_error_errno(r, "Failed to add name %s to table: %m", k);
r = sd_bus_get_name_creds(
bus, k,
@ -283,7 +279,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 table_log_add_error(r);
return log_error_errno(r, "Failed to add fields to table: %m");
r = sd_bus_creds_get_euid(creds, &uid);
if (r >= 0) {
@ -297,7 +293,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 table_log_add_error(r);
return log_error_errno(r, "Failed to add field to table: %m");
(void) sd_bus_creds_get_unique_name(creds, &unique);
(void) sd_bus_creds_get_unit(creds, &unit);
@ -312,7 +308,7 @@ static int list_bus_names(int argc, char **argv, void *userdata) {
TABLE_STRING, cn);
}
if (r < 0)
return table_log_add_error(r);
return log_error_errno(r, "Failed to add fields to table: %m");
if (arg_show_machine) {
sd_id128_t mid;
@ -325,7 +321,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 table_log_add_error(r);
return log_error_errno(r, "Failed to add field to table: %m");
continue; /* line fully filled, no need to fill the remainder below */
}
@ -2255,7 +2251,6 @@ 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"
@ -2328,7 +2323,6 @@ 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 },
@ -2378,10 +2372,6 @@ 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,23 +12,16 @@
#include "unit.h"
static int swap_get_priority(Swap *s) {
assert(s);
if (s->from_proc_swaps && s->parameters_proc_swaps.priority_set)
if (s->from_proc_swaps)
return s->parameters_proc_swaps.priority;
if (s->from_fragment && s->parameters_fragment.priority_set)
if (s->from_fragment)
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_swap_priority, 0, 0
Swap.Priority, config_parse_int, 0, offsetof(Swap, parameters_fragment.priority)
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,51 +5002,3 @@ 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,7 +121,6 @@ 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,57 +1190,6 @@ 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,
@ -1279,17 +1228,13 @@ int setup_namespace(
if (root_image) {
dissect_image_flags |= DISSECT_IMAGE_REQUIRE_ROOT;
/* 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) &&
if (protect_system == PROTECT_SYSTEM_STRICT &&
protect_home != PROTECT_HOME_NO &&
strv_isempty(read_write_paths))
dissect_image_flags |= DISSECT_IMAGE_READ_ONLY;
r = loop_device_make_by_path(root_image,
FLAGS_SET(dissect_image_flags, DISSECT_IMAGE_READ_ONLY) ? O_RDONLY : -1 /* < 0 means writable if possible, read-only as fallback */,
dissect_image_flags & DISSECT_IMAGE_READ_ONLY ? O_RDONLY : O_RDWR,
LO_FLAGS_PARTSCAN,
&loop_device);
if (r < 0)

View File

@ -63,6 +63,7 @@ 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;
}
@ -116,6 +117,9 @@ 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;
@ -768,21 +772,19 @@ static void swap_enter_activating(Swap *s) {
r = fstab_find_pri(s->parameters_fragment.options, &priority);
if (r < 0)
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.");
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.");
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) {
r = -ENOMEM;
if (r < 0)
goto fail;
}
}
}
r = exec_command_set(s->control_command, "/sbin/swapon", NULL);
if (r < 0)
@ -790,7 +792,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;
}
@ -806,6 +808,7 @@ 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 table_log_add_error(r);
return log_error_errno(r, "Failed to add table row: %m");
}
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 table_log_add_error(r);
return log_error_errno(r, "Failed to add row to table: %m");
}
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 table_log_add_error(r);
return log_error_errno(r, "Failed to add row to table: %m");
}
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 table_log_add_error(r);
return log_error_errno(r, "Failed to add row to table: %m");
}
r = sd_bus_message_exit_container(reply);

View File

@ -306,9 +306,6 @@ 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);
@ -341,7 +338,7 @@ static int list_machines(int argc, char *argv[], void *userdata) {
0,
"",
" ",
arg_full ? ALL_IP_ADDRESSES : arg_addrs,
arg_addrs,
&addresses);
r = table_add_many(table,
@ -352,7 +349,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 table_log_add_error(r);
return log_error_errno(r, "Failed to add table row: %m");
}
r = sd_bus_message_exit_container(reply);
@ -389,9 +386,6 @@ 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)");
@ -401,6 +395,8 @@ 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);
@ -414,14 +410,27 @@ static int list_images(int argc, char *argv[], void *userdata) {
r = table_add_many(table,
TABLE_STRING, name,
TABLE_STRING, type,
TABLE_BOOLEAN, ro_int,
TABLE_SET_COLOR, ro_int ? ansi_highlight_red() : NULL,
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_SIZE, size,
TABLE_TIMESTAMP, crtime,
TABLE_TIMESTAMP, mtime);
if (r < 0)
return table_log_add_error(r);
return log_error_errno(r, "Failed to add table row: %m");
}
r = sd_bus_message_exit_container(reply);

View File

@ -46,7 +46,6 @@ 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;
@ -93,7 +92,6 @@ 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"
@ -152,7 +150,6 @@ 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 },
@ -185,7 +182,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:AuGl", options, NULL)) >= 0)
while ((c = getopt_long(argc, argv, "hqH:M:t:o:p:AuG", options, NULL)) >= 0)
switch (c) {
@ -207,10 +204,6 @@ 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;
@ -1400,9 +1393,6 @@ 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");
@ -1446,7 +1436,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 table_log_add_error(r);
return log_error_errno(r, "Failed to add cell: %m");
}
}

View File

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

View File

@ -511,6 +511,8 @@ 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);
@ -521,16 +523,37 @@ static int list_images(int argc, char *argv[], void *userdata) {
r = table_add_many(table,
TABLE_STRING, name,
TABLE_STRING, type,
TABLE_BOOLEAN, ro_int,
TABLE_SET_COLOR, ro_int ? ansi_highlight_red() : NULL,
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_TIMESTAMP, crtime,
TABLE_TIMESTAMP, mtime,
TABLE_SIZE, usage,
TABLE_STRING, state,
TABLE_SET_COLOR, !streq(state, "detached") ? ansi_highlight_green() : NULL);
TABLE_SIZE, usage);
if (r < 0)
return table_log_add_error(r);
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");
}
}
r = sd_bus_message_exit_container(reply);

View File

@ -118,6 +118,3 @@ 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,6 +105,7 @@ 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);
@ -112,7 +113,11 @@ static int in_search_path(const LookupPaths *p, const char *path) {
if (!parent)
return -ENOMEM;
return path_strv_contains(p->search_path, parent);
STRV_FOREACH(i, p->search_path)
if (path_equal(parent, *i))
return true;
return false;
}
static const char* skip_root(const LookupPaths *p, const char *path) {

View File

@ -14,7 +14,6 @@
#include <unistd.h>
#include "alloc-util.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "loop-util.h"
@ -158,30 +157,14 @@ 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(open_flags < 0 || IN_SET(open_flags, O_RDWR, O_RDONLY));
assert(IN_SET(open_flags, O_RDWR, O_RDONLY));
/* 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);
fd = open(path, O_CLOEXEC|O_NONBLOCK|O_NOCTTY|open_flags);
if (fd < 0)
return r; /* Propagate original error */
open_flags = O_RDONLY;
} else if (open_flags < 0)
open_flags = O_RDWR;
return -errno;
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 table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
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 table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
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 table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
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 table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
r = table_add_cell_stringf(table, NULL, "%s (%s)", strna(i->timezone), have_time && n > 0 ? a : "n/a");
if (r < 0)
return table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
/* 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 table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
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 table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
r = table_add_cell_stringf(table, NULL, "%s (%s)", i->server_address, i->server_name);
if (r < 0)
return table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
r = table_add_cell(table, NULL, TABLE_STRING, "Poll interval:");
if (r < 0)
return table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
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 table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
if (i->packet_count == 0) {
r = table_add_many(table,
TABLE_STRING, "Packet count:",
TABLE_STRING, "0");
if (r < 0)
return table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
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 table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
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 table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
r = table_add_cell(table, NULL, TABLE_STRING, "Precision:");
if (r < 0)
return table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
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 table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
r = table_add_cell(table, NULL, TABLE_STRING, "Root distance:");
if (r < 0)
return table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
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 table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
r = table_add_cell(table, NULL, TABLE_STRING, "Offset:");
if (r < 0)
return table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
r = table_add_cell_stringf(table, NULL, "%s%s",
offset_sign ? "+" : "-",
format_timespan(ts, sizeof(ts), offset, 0));
if (r < 0)
return table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
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 table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
if (!i->spike) {
r = table_add_cell(table, NULL, TABLE_STRING, "Frequency:");
if (r < 0)
return table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
r = table_add_cell_stringf(table, NULL, "%+.3fppm", (double) i->freq / 0x10000);
if (r < 0)
return table_log_add_error(r);
return log_error_errno(r, "Failed to add cell(s): %m");
}
r = table_print(table, NULL);