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:
+6
-5
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user