[systemd-commits] 3 commits - man/systemd-analyze.xml src/analyze src/libsystemd-network src/shared src/systemctl
Zbigniew Jędrzejewski-Szmek
zbyszek at kemper.freedesktop.org
Mon Feb 16 10:17:22 PST 2015
man/systemd-analyze.xml | 23 ++++++++----
src/analyze/analyze.c | 54 ++++++++----------------------
src/libsystemd-network/network-internal.c | 45 ++-----------------------
src/shared/strv.c | 10 +++++
src/shared/strv.h | 9 +++++
src/systemctl/systemctl.c | 51 +++-------------------------
6 files changed, 62 insertions(+), 130 deletions(-)
New commits:
commit 6ecb6cec66739d733e95302031998f517261380c
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Fri Feb 13 18:38:33 2015 -0500
analyze: change behaviour of combined --to/from--pattern
We would require a match against all three: patterns specified
with --to, with --from, and as positional arguments to show an
edge. This does not seem useful. Let instead the positional args
behave like they were specified in both --to and --from, which is
fairly intuitive and should be more useful.
diff --git a/man/systemd-analyze.xml b/man/systemd-analyze.xml
index 61315a0..1ff81d3 100644
--- a/man/systemd-analyze.xml
+++ b/man/systemd-analyze.xml
@@ -227,13 +227,22 @@
<listitem><para>When used in conjunction with the
<command>dot</command> command (see above), this selects which
- relationships are shown in the dependency graph. They both
- require
+ relationships are shown in the dependency graph. Both options
+ require a
<citerefentry><refentrytitle>glob</refentrytitle><manvolnum>7</manvolnum></citerefentry>
- patterns as arguments, which are matched against left-hand and
- right-hand, respectively, nodes of a relationship. Each of
- these can be used more than once, which means a unit name must
- match one of the given values.</para></listitem>
+ pattern as an argument, which will be matched against the
+ left-hand and the right-hand, respectively, nodes of a
+ relationship.</para>
+
+ <para>Each of these can be used more than once, in which case
+ the unit name must match one of the values. When tests for
+ both sides of the relation are present, a relation must pass
+ both tests to be shown. When patterns are also specified as
+ positional arguments, they must match at least one side of the
+ relation. In other words, patterns specified with those two
+ options will trim the list of edges matched by the positional
+ arguments, if any are given, and fully determine the list of
+ edges shown otherwise.</para></listitem>
</varlistentry>
<varlistentry>
@@ -252,7 +261,7 @@
<term><option>--no-man</option></term>
<listitem><para>Do not invoke man to verify the existence of
- man pages listen in <varname>Documentation=</varname>.
+ man pages listed in <varname>Documentation=</varname>.
</para></listitem>
</varlistentry>
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index 672a0d7..1e2a6bb 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -974,24 +974,34 @@ static int graph_one_property(sd_bus *bus, const UnitInfo *u, const char* prop,
_cleanup_strv_free_ char **units = NULL;
char **unit;
int r;
+ bool match_patterns;
assert(u);
assert(prop);
assert(color);
+ match_patterns = strv_fnmatch(u->id, patterns, 0);
+
+ if (!strv_isempty(arg_dot_from_patterns) &&
+ !match_patterns &&
+ !strv_fnmatch(u->id, arg_dot_from_patterns, 0))
+ return 0;
+
r = bus_get_unit_property_strv(bus, u->unit_path, prop, &units);
if (r < 0)
return r;
STRV_FOREACH(unit, units) {
- if (!strv_fnmatch_or_empty(u->id, arg_dot_from_patterns, 0))
- continue;
+ bool match_patterns2;
+
+ match_patterns2 = strv_fnmatch(*unit, patterns, 0);
- if (!strv_fnmatch_or_empty(*unit, arg_dot_to_patterns, 0))
+ if (!strv_isempty(arg_dot_to_patterns) &&
+ !match_patterns2 &&
+ !strv_fnmatch(*unit, arg_dot_to_patterns, 0))
continue;
- if (!strv_fnmatch_or_empty(u->id, patterns, 0) &&
- !strv_fnmatch_or_empty(*unit, patterns, 0))
+ if (!strv_isempty(patterns) && !match_patterns && !match_patterns2)
continue;
printf("\t\"%s\"->\"%s\" [color=\"%s\"];\n", u->id, *unit, color);
commit ee5de57b9d474161df259e7faa958fa9d7bbd736
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Fri Feb 13 18:38:22 2015 -0500
network-internal: chain matches with AND in net_match_config()
The test would treat the first non-empty set of matches in
match_paths, match_drivers, match_types, match_names as definitive
(essentially chaining them with OR). Make those tests instead match
like other tests and require all to pass if the set of patterns is
nonempty.
diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c
index 5867aef..b6bddd9 100644
--- a/src/libsystemd-network/network-internal.c
+++ b/src/libsystemd-network/network-internal.c
@@ -112,17 +112,17 @@ bool net_match_config(const struct ether_addr *match_mac,
if (match_mac && (!dev_mac || memcmp(match_mac, dev_mac, ETH_ALEN)))
return false;
- if (!strv_isempty(match_paths))
- return strv_fnmatch(dev_path, match_paths, 0);
+ if (!strv_fnmatch_or_empty(dev_path, match_paths, 0))
+ return false;
- if (!strv_isempty(match_drivers))
- return strv_fnmatch(dev_driver, match_drivers, 0);
+ if (!strv_fnmatch_or_empty(dev_driver, match_drivers, 0))
+ return false;
- if (!strv_isempty(match_types))
- return strv_fnmatch(dev_type, match_types, 0);
+ if (!strv_fnmatch_or_empty(dev_type, match_types, 0))
+ return false;
- if (!strv_isempty(match_names))
- return strv_fnmatch(dev_name, match_names, 0);
+ if (!strv_fnmatch_or_empty(dev_name, match_names, 0))
+ return false;
return true;
}
commit bceccd5ecc393c344ab008737ba6aab211a5ea9f
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Fri Feb 13 18:37:43 2015 -0500
Add helper for fnmatch over strv
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index 46a97eb..672a0d7 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -25,7 +25,6 @@
#include <getopt.h>
#include <locale.h>
#include <sys/utsname.h>
-#include <fnmatch.h>
#include "sd-bus.h"
#include "bus-util.h"
@@ -985,46 +984,15 @@ static int graph_one_property(sd_bus *bus, const UnitInfo *u, const char* prop,
return r;
STRV_FOREACH(unit, units) {
- char **p;
- bool match_found;
-
- if (!strv_isempty(arg_dot_from_patterns)) {
- match_found = false;
-
- STRV_FOREACH(p, arg_dot_from_patterns)
- if (fnmatch(*p, u->id, 0) == 0) {
- match_found = true;
- break;
- }
-
- if (!match_found)
- continue;
- }
-
- if (!strv_isempty(arg_dot_to_patterns)) {
- match_found = false;
-
- STRV_FOREACH(p, arg_dot_to_patterns)
- if (fnmatch(*p, *unit, 0) == 0) {
- match_found = true;
- break;
- }
-
- if (!match_found)
- continue;
- }
+ if (!strv_fnmatch_or_empty(u->id, arg_dot_from_patterns, 0))
+ continue;
- if (!strv_isempty(patterns)) {
- match_found = false;
+ if (!strv_fnmatch_or_empty(*unit, arg_dot_to_patterns, 0))
+ continue;
- STRV_FOREACH(p, patterns)
- if (fnmatch(*p, u->id, 0) == 0 || fnmatch(*p, *unit, 0) == 0) {
- match_found = true;
- break;
- }
- if (!match_found)
- continue;
- }
+ if (!strv_fnmatch_or_empty(u->id, patterns, 0) &&
+ !strv_fnmatch_or_empty(*unit, patterns, 0))
+ continue;
printf("\t\"%s\"->\"%s\" [color=\"%s\"];\n", u->id, *unit, color);
}
diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c
index 41f43d3..5867aef 100644
--- a/src/libsystemd-network/network-internal.c
+++ b/src/libsystemd-network/network-internal.c
@@ -22,7 +22,6 @@
#include <netinet/ether.h>
#include <linux/if.h>
#include <arpa/inet.h>
-#include <fnmatch.h>
#include "strv.h"
#include "siphash24.h"
@@ -97,10 +96,6 @@ bool net_match_config(const struct ether_addr *match_mac,
const char *dev_driver,
const char *dev_type,
const char *dev_name) {
- char * const *match_path;
- char * const *match_driver;
- char * const *match_type;
- char * const *match_name;
if (match_host && !condition_test(match_host))
return false;
@@ -117,49 +112,17 @@ bool net_match_config(const struct ether_addr *match_mac,
if (match_mac && (!dev_mac || memcmp(match_mac, dev_mac, ETH_ALEN)))
return false;
- if (!strv_isempty(match_paths)) {
- if (!dev_path)
- return false;
+ if (!strv_isempty(match_paths))
+ return strv_fnmatch(dev_path, match_paths, 0);
- STRV_FOREACH(match_path, match_paths)
- if (fnmatch(*match_path, dev_path, 0) == 0)
- return true;
+ if (!strv_isempty(match_drivers))
+ return strv_fnmatch(dev_driver, match_drivers, 0);
- return false;
- }
-
- if (!strv_isempty(match_drivers)) {
- if (!dev_driver)
- return false;
-
- STRV_FOREACH(match_driver, match_drivers)
- if (fnmatch(*match_driver, dev_driver, 0) == 0)
- return true;
-
- return false;
- }
-
- if (!strv_isempty(match_types)) {
- if (!dev_type)
- return false;
+ if (!strv_isempty(match_types))
+ return strv_fnmatch(dev_type, match_types, 0);
- STRV_FOREACH(match_type, match_types)
- if (fnmatch(*match_type, dev_type, 0) == 0)
- return true;
-
- return false;
- }
-
- if (!strv_isempty(match_names)) {
- if (!dev_name)
- return false;
-
- STRV_FOREACH(match_name, match_names)
- if (fnmatch(*match_name, dev_name, 0) == 0)
- return true;
-
- return false;
- }
+ if (!strv_isempty(match_names))
+ return strv_fnmatch(dev_name, match_names, 0);
return true;
}
diff --git a/src/shared/strv.c b/src/shared/strv.c
index e418312..2268bf6 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -692,3 +692,13 @@ char **strv_reverse(char **l) {
return l;
}
+
+bool strv_fnmatch(const char *s, char* const* patterns, int flags) {
+ char* const* p;
+
+ STRV_FOREACH(p, patterns)
+ if (fnmatch(*p, s, 0) == 0)
+ return true;
+
+ return false;
+}
diff --git a/src/shared/strv.h b/src/shared/strv.h
index e385bf7..a899395 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -23,6 +23,7 @@
#include <stdarg.h>
#include <stdbool.h>
+#include <fnmatch.h>
#include "util.h"
@@ -144,3 +145,11 @@ void strv_print(char **l);
}))
char **strv_reverse(char **l);
+
+bool strv_fnmatch(const char *s, char* const* patterns, int flags);
+
+static inline bool strv_fnmatch_or_empty(const char *s, char* const* patterns, int flags) {
+ assert(s);
+ return strv_isempty(patterns) ||
+ strv_fnmatch(s, patterns, flags);
+}
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index d1b7f8a..66bfd0e 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -37,7 +37,6 @@
#include <sys/stat.h>
#include <stddef.h>
#include <sys/prctl.h>
-#include <fnmatch.h>
#include "sd-daemon.h"
#include "sd-shutdown.h"
@@ -311,16 +310,9 @@ static int compare_unit_info(const void *a, const void *b) {
}
static bool output_show_unit(const UnitInfo *u, char **patterns) {
- if (!strv_isempty(patterns)) {
- char **pattern;
-
- STRV_FOREACH(pattern, patterns)
- if (fnmatch(*pattern, u->id, FNM_NOESCAPE) == 0)
- goto next;
+ if (!strv_fnmatch_or_empty(u->id, patterns, FNM_NOESCAPE))
return false;
- }
-next:
if (arg_types) {
const char *dot;
@@ -1255,16 +1247,9 @@ static int compare_unit_file_list(const void *a, const void *b) {
}
static bool output_show_unit_file(const UnitFileList *u, char **patterns) {
- if (!strv_isempty(patterns)) {
- char **pattern;
-
- STRV_FOREACH(pattern, patterns)
- if (fnmatch(*pattern, basename(u->path), FNM_NOESCAPE) == 0)
- goto next;
+ if (!strv_fnmatch_or_empty(basename(u->path), patterns, FNM_NOESCAPE))
return false;
- }
-next:
if (!strv_isempty(arg_types)) {
const char *dot;
@@ -1276,10 +1261,9 @@ next:
return false;
}
- if (!strv_isempty(arg_states)) {
- if (!strv_find(arg_states, unit_file_state_to_string(u->state)))
- return false;
- }
+ if (!strv_isempty(arg_states) &&
+ !strv_find(arg_states, unit_file_state_to_string(u->state)))
+ return false;
return true;
}
@@ -1736,18 +1720,7 @@ static int get_machine_properties(sd_bus *bus, struct machine_info *mi) {
}
static bool output_show_machine(const char *name, char **patterns) {
- char **i;
-
- assert(name);
-
- if (strv_isempty(patterns))
- return true;
-
- STRV_FOREACH(i, patterns)
- if (fnmatch(*i, name, FNM_NOESCAPE) == 0)
- return true;
-
- return false;
+ return strv_fnmatch_or_empty(name, patterns, FNM_NOESCAPE);
}
static int get_machine_list(
@@ -2100,17 +2073,7 @@ static void output_jobs_list(const struct job_info* jobs, unsigned n, bool skipp
}
static bool output_show_job(struct job_info *job, char **patterns) {
- char **pattern;
-
- assert(job);
-
- if (strv_isempty(patterns))
- return true;
-
- STRV_FOREACH(pattern, patterns)
- if (fnmatch(*pattern, job->name, FNM_NOESCAPE) == 0)
- return true;
- return false;
+ return strv_fnmatch_or_empty(job->name, patterns, FNM_NOESCAPE);
}
static int list_jobs(sd_bus *bus, char **args) {
More information about the systemd-commits
mailing list