diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2022-10-14 15:25:32 +1100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2022-10-15 02:10:36 +0200 |
commit | ea5936dd3f6293fb761e3b670a0f40233e5396fd (patch) | |
tree | ff4744bab430784cd416bc063902022018e905bf /pasta.c | |
parent | 096e48669b56273d44a3242d7af4840b38335961 (diff) | |
download | passt-ea5936dd3f6293fb761e3b670a0f40233e5396fd.tar passt-ea5936dd3f6293fb761e3b670a0f40233e5396fd.tar.gz passt-ea5936dd3f6293fb761e3b670a0f40233e5396fd.tar.bz2 passt-ea5936dd3f6293fb761e3b670a0f40233e5396fd.tar.lz passt-ea5936dd3f6293fb761e3b670a0f40233e5396fd.tar.xz passt-ea5936dd3f6293fb761e3b670a0f40233e5396fd.tar.zst passt-ea5936dd3f6293fb761e3b670a0f40233e5396fd.zip |
Replace FWRITE with a function
In a few places we use the FWRITE() macro to open a file, replace it's
contents with a given string and close it again. There's no real
reason this needs to be a macro rather than just a function though.
Turn it into a function 'write_file()' and make some ancillary
cleanups while we're there:
- Add a return code so the caller can handle giving a useful error message
- Handle the case of short write()s (unlikely, but possible)
- Add O_TRUNC, to make sure we replace the existing contents entirely
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'pasta.c')
-rw-r--r-- | pasta.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -167,8 +167,8 @@ static int pasta_setup_ns(void *arg) { const struct pasta_setup_ns_arg *a; - FWRITE("/proc/sys/net/ipv4/ping_group_range", "0 0", - "Cannot set ping_group_range, ICMP requests might fail"); + if (write_file("/proc/sys/net/ipv4/ping_group_range", "0 0")) + warn("Cannot set ping_group_range, ICMP requests might fail"); a = (const struct pasta_setup_ns_arg *)arg; execvp(a->exe, a->argv); |