summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-11-13 00:54:56 +0100
committerLennart Poettering <lennart@poettering.net>2015-11-13 13:02:49 +0100
commiteb3da9012f462da2451edeb8d67c5b67c833a0b1 (patch)
treec009896e29778ebe5ac2fdcb140f5fdb27aa2788 /src/network
parent87fde73e185fabc346ee4d9c9befe972e3502dc3 (diff)
util-lib: optionally, when writing a string to a file, verify string on failure
With this change, the idiom: r = write_string_file(p, buf, 0); if (r < 0) { if (verify_one_line_file(p, buf) > 0) r = 0; } gets reduced to: r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE); i.e. when writing the string fails and the new flag WRITE_STRING_FILE_VERIFY_ON_FAILURE is specified we'll not return a failure immediately, but check the contents of the file. If it matches what we wanted to write we suppress the error and exit cleanly.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkd-link.c54
1 files changed, 12 insertions, 42 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 00c57b2960..07910c2c3b 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1859,14 +1859,9 @@ static int link_set_ipv4_forward(Link *link) {
p = strjoina("/proc/sys/net/ipv4/conf/", link->ifname, "/forwarding");
v = one_zero(link_ipv4_forward_enabled(link));
- r = write_string_file(p, v, 0);
- if (r < 0) {
- /* If the right value is set anyway, don't complain */
- if (verify_one_line_file(p, v) > 0)
- return 0;
-
+ r = write_string_file(p, v, WRITE_STRING_FILE_VERIFY_ON_FAILURE);
+ if (r < 0)
log_link_warning_errno(link, r, "Cannot configure IPv4 forwarding for interface %s: %m", link->ifname);
- }
return 0;
}
@@ -1888,14 +1883,9 @@ static int link_set_ipv6_forward(Link *link) {
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/forwarding");
v = one_zero(link_ipv6_forward_enabled(link));
- r = write_string_file(p, v, 0);
- if (r < 0) {
- /* If the right value is set anyway, don't complain */
- if (verify_one_line_file(p, v) > 0)
- return 0;
-
+ r = write_string_file(p, v, WRITE_STRING_FILE_VERIFY_ON_FAILURE);
+ if (r < 0)
log_link_warning_errno(link, r, "Cannot configure IPv6 forwarding for interface: %m");
- }
return 0;
}
@@ -1917,14 +1907,9 @@ static int link_set_ipv6_privacy_extensions(Link *link) {
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/use_tempaddr");
xsprintf(buf, "%u", link->network->ipv6_privacy_extensions);
- r = write_string_file(p, buf, 0);
- if (r < 0) {
- /* If the right value is set anyway, don't complain */
- if (verify_one_line_file(p, buf) > 0)
- return 0;
-
+ r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE);
+ if (r < 0)
log_link_warning_errno(link, r, "Cannot configure IPv6 privacy extension for interface: %m");
- }
return 0;
}
@@ -1943,14 +1928,9 @@ static int link_set_ipv6_accept_ra(Link *link) {
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/accept_ra");
/* we handle router advertisments ourselves, tell the kernel to GTFO */
- r = write_string_file(p, "0", 0);
- if (r < 0) {
- /* If the right value is set anyway, don't complain */
- if (verify_one_line_file(p, "0") > 0)
- return 0;
-
+ r = write_string_file(p, "0", WRITE_STRING_FILE_VERIFY_ON_FAILURE);
+ if (r < 0)
log_link_warning_errno(link, r, "Cannot disable kernel IPv6 accept_ra for interface: %m");
- }
return 0;
}
@@ -1974,14 +1954,9 @@ static int link_set_ipv6_dad_transmits(Link *link) {
xsprintf(buf, "%u", link->network->ipv6_dad_transmits);
- r = write_string_file(p, buf, 0);
- if (r < 0) {
- /* If the right value is set anyway, don't complain */
- if (verify_one_line_file(p, buf) > 0)
- return 0;
-
+ r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE);
+ if (r < 0)
log_link_warning_errno(link, r, "Cannot set IPv6 dad transmits for interface: %m");
- }
return 0;
}
@@ -2005,14 +1980,9 @@ static int link_set_ipv6_hop_limit(Link *link) {
xsprintf(buf, "%u", link->network->ipv6_hop_limit);
- r = write_string_file(p, buf, 0);
- if (r < 0) {
- /* If the right value is set anyway, don't complain */
- if (verify_one_line_file(p, buf) > 0)
- return 0;
-
+ r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE);
+ if (r < 0)
log_link_warning_errno(link, r, "Cannot set IPv6 hop limit for interface: %m");
- }
return 0;
}