mirror of
https://github.com/systemd/systemd
synced 2026-03-27 17:24:51 +01:00
Compare commits
2 Commits
f90eea7d18
...
8be102f8b8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8be102f8b8 | ||
|
|
99db797bc6 |
@ -7,6 +7,7 @@
|
|||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "main-func.h"
|
#include "main-func.h"
|
||||||
|
#include "path-util.h"
|
||||||
#include "pretty-print.h"
|
#include "pretty-print.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
#include "strv.h"
|
#include "strv.h"
|
||||||
@ -171,8 +172,36 @@ static int run(int argc, char *argv[]) {
|
|||||||
case ACTION_ESCAPE:
|
case ACTION_ESCAPE:
|
||||||
if (arg_path) {
|
if (arg_path) {
|
||||||
r = unit_name_path_escape(*i, &e);
|
r = unit_name_path_escape(*i, &e);
|
||||||
if (r < 0)
|
if (r < 0) {
|
||||||
|
if (r == -EINVAL) {
|
||||||
|
/* If escaping failed because the string was invalid, let's print a
|
||||||
|
* friendly message about it. Catch these specific error cases
|
||||||
|
* explicitly. */
|
||||||
|
|
||||||
|
if (!path_is_valid(*i))
|
||||||
|
return log_error_errno(r, "Input '%s' is not a valid file system path, failed to escape.", *i);
|
||||||
|
if (!path_is_absolute(*i))
|
||||||
|
return log_error_errno(r, "Input '%s' is not an absolute file system path, failed to escape.", *i);
|
||||||
|
if (!path_is_normalized(*i))
|
||||||
|
return log_error_errno(r, "Input '%s' is not a normalized file system path, failed to escape.", *i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* All other error cases. */
|
||||||
return log_error_errno(r, "Failed to escape string: %m");
|
return log_error_errno(r, "Failed to escape string: %m");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the escaping worked, then still warn if the path is not like we'd like
|
||||||
|
* it. Because that means escaping is not necessarily reversible. */
|
||||||
|
|
||||||
|
if (!path_is_valid(*i))
|
||||||
|
log_warning("Input '%s' is not a valid file system path, escaping is likely not going be reversible.", *i);
|
||||||
|
else if (!path_is_absolute(*i))
|
||||||
|
log_warning("Input '%s' is not an absolute file system path, escaping is likely not going to be reversible.", *i);
|
||||||
|
|
||||||
|
/* Note that we don't complain about paths not being normalized here, because
|
||||||
|
* some forms of non-normalization is actually OK, such as a series // and
|
||||||
|
* unit_name_path_escape() will clean those up silently, and the reversal is
|
||||||
|
* "close enough" to be OK. */
|
||||||
} else {
|
} else {
|
||||||
e = unit_name_escape(*i);
|
e = unit_name_escape(*i);
|
||||||
if (!e)
|
if (!e)
|
||||||
|
|||||||
@ -2061,12 +2061,10 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
|
|||||||
print('### ip route show table 42 dev dummy98')
|
print('### ip route show table 42 dev dummy98')
|
||||||
print(output)
|
print(output)
|
||||||
self.assertRegex(output, 'local 10.20.22.1 proto kernel scope host src 10.20.22.1')
|
self.assertRegex(output, 'local 10.20.22.1 proto kernel scope host src 10.20.22.1')
|
||||||
self.assertRegex(output, 'broadcast 10.20.33.0 proto kernel scope link src 10.20.33.1')
|
|
||||||
self.assertRegex(output, '10.20.33.0/24 proto kernel scope link src 10.20.33.1')
|
self.assertRegex(output, '10.20.33.0/24 proto kernel scope link src 10.20.33.1')
|
||||||
self.assertRegex(output, 'local 10.20.33.1 proto kernel scope host src 10.20.33.1')
|
self.assertRegex(output, 'local 10.20.33.1 proto kernel scope host src 10.20.33.1')
|
||||||
self.assertRegex(output, 'broadcast 10.20.33.255 proto kernel scope link src 10.20.33.1')
|
self.assertRegex(output, 'broadcast 10.20.33.255 proto kernel scope link src 10.20.33.1')
|
||||||
self.assertRegex(output, 'local 10.20.44.1 proto kernel scope host src 10.20.44.1')
|
self.assertRegex(output, 'local 10.20.44.1 proto kernel scope host src 10.20.44.1')
|
||||||
self.assertRegex(output, 'broadcast 10.20.55.0 proto kernel scope link src 10.20.55.1')
|
|
||||||
self.assertRegex(output, 'local 10.20.55.1 proto kernel scope host src 10.20.55.1')
|
self.assertRegex(output, 'local 10.20.55.1 proto kernel scope host src 10.20.55.1')
|
||||||
self.assertRegex(output, 'broadcast 10.20.55.255 proto kernel scope link src 10.20.55.1')
|
self.assertRegex(output, 'broadcast 10.20.55.255 proto kernel scope link src 10.20.55.1')
|
||||||
output = check_output('ip -6 route show table 42 dev dummy98')
|
output = check_output('ip -6 route show table 42 dev dummy98')
|
||||||
@ -2093,11 +2091,9 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
|
|||||||
print('### ip route show table local dev test1')
|
print('### ip route show table local dev test1')
|
||||||
print(output)
|
print(output)
|
||||||
self.assertRegex(output, 'local 10.21.22.1 proto kernel scope host src 10.21.22.1')
|
self.assertRegex(output, 'local 10.21.22.1 proto kernel scope host src 10.21.22.1')
|
||||||
self.assertRegex(output, 'broadcast 10.21.33.0 proto kernel scope link src 10.21.33.1')
|
|
||||||
self.assertRegex(output, 'local 10.21.33.1 proto kernel scope host src 10.21.33.1')
|
self.assertRegex(output, 'local 10.21.33.1 proto kernel scope host src 10.21.33.1')
|
||||||
self.assertRegex(output, 'broadcast 10.21.33.255 proto kernel scope link src 10.21.33.1')
|
self.assertRegex(output, 'broadcast 10.21.33.255 proto kernel scope link src 10.21.33.1')
|
||||||
self.assertRegex(output, 'local 10.21.44.1 proto kernel scope host src 10.21.44.1')
|
self.assertRegex(output, 'local 10.21.44.1 proto kernel scope host src 10.21.44.1')
|
||||||
self.assertRegex(output, 'broadcast 10.21.55.0 proto kernel scope link src 10.21.55.1')
|
|
||||||
self.assertRegex(output, 'local 10.21.55.1 proto kernel scope host src 10.21.55.1')
|
self.assertRegex(output, 'local 10.21.55.1 proto kernel scope host src 10.21.55.1')
|
||||||
self.assertRegex(output, 'broadcast 10.21.55.255 proto kernel scope link src 10.21.55.1')
|
self.assertRegex(output, 'broadcast 10.21.55.255 proto kernel scope link src 10.21.55.1')
|
||||||
output = check_output('ip -6 route show dev test1')
|
output = check_output('ip -6 route show dev test1')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user