networkctl: return error or warning when interfaces are not matched

We'd just print nothing and exit with 0. If the user gave an explicit
name, we should fail. If a pattern didn't match, we should at least warn.

$ networkctl status enx54ee75cb1dc0a* --no-pager && echo $?
No interfaces matched.
0

$ networkctl status enx54ee75cb1dc0a --no-pager
Interface "enx54ee75cb1dc0a" not found.
1
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-01-14 13:09:46 +01:00
parent 0e05be8405
commit 0ef84b80c5
4 changed files with 50 additions and 13 deletions
+6 -5
View File
@@ -800,12 +800,13 @@ char **strv_shell_escape(char **l, const char *bad) {
return l;
}
bool strv_fnmatch(char* const* patterns, const char *s, int flags) {
char* const* p;
STRV_FOREACH(p, patterns)
if (fnmatch(*p, s, flags) == 0)
bool strv_fnmatch_full(char* const* patterns, const char *s, int flags, size_t *matched_pos) {
for (size_t i = 0; patterns && patterns[i]; i++)
if (fnmatch(patterns[i], s, flags) == 0) {
if (matched_pos)
*matched_pos = i;
return true;
}
return false;
}
+4 -1
View File
@@ -177,7 +177,10 @@ void strv_print(char * const *l);
char **strv_reverse(char **l);
char **strv_shell_escape(char **l, const char *bad);
bool strv_fnmatch(char* const* patterns, const char *s, int flags);
bool strv_fnmatch_full(char* const* patterns, const char *s, int flags, size_t *matched_pos);
static inline bool strv_fnmatch(char* const* patterns, const char *s, int flags) {
return strv_fnmatch_full(patterns, s, flags, NULL);
}
static inline bool strv_fnmatch_or_empty(char* const* patterns, const char *s, int flags) {
assert(s);