summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-04-28 14:02:42 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-04-28 18:50:47 +0900
commit657152a459f8bc30d004a70298e81a0ad896fbfd (patch)
treedb1b5aa5a441fb8947fe9707383c262b3557f202 /src/network
parent75fd8ad0083cc3542367ee44efa70258c29aecc8 (diff)
downloadsystemd-657152a459f8bc30d004a70298e81a0ad896fbfd.tar.gz
network-generator: shorten code a bit
Diffstat (limited to 'src/network')
-rw-r--r--src/network/generator/main.c36
1 files changed, 11 insertions, 25 deletions
diff --git a/src/network/generator/main.c b/src/network/generator/main.c
index 492980249b..6c995b152f 100644
--- a/src/network/generator/main.c
+++ b/src/network/generator/main.c
@@ -18,9 +18,9 @@
static const char *arg_root = NULL;
static int network_save(Network *network, const char *dest_dir) {
- _cleanup_free_ char *filename = NULL, *p = NULL;
_cleanup_(unlink_and_freep) char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
+ _cleanup_free_ char *p = NULL;
int r;
assert(network);
@@ -31,14 +31,10 @@ static int network_save(Network *network, const char *dest_dir) {
network_dump(network, f);
- r = asprintf(&filename, "%s-%s.network",
+ if (asprintf(&p, "%s/%s-%s.network",
+ dest_dir,
isempty(network->ifname) ? "91" : "90",
- isempty(network->ifname) ? "default" : network->ifname);
- if (r < 0)
- return log_oom();
-
- p = path_join(dest_dir, filename);
- if (!p)
+ isempty(network->ifname) ? "default" : network->ifname) < 0)
return log_oom();
r = conservative_rename(temp_path, p);
@@ -50,9 +46,9 @@ static int network_save(Network *network, const char *dest_dir) {
}
static int netdev_save(NetDev *netdev, const char *dest_dir) {
- _cleanup_free_ char *filename = NULL, *p = NULL;
_cleanup_(unlink_and_freep) char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
+ _cleanup_free_ char *p = NULL;
int r;
assert(netdev);
@@ -63,13 +59,7 @@ static int netdev_save(NetDev *netdev, const char *dest_dir) {
netdev_dump(netdev, f);
- r = asprintf(&filename, "90-%s.netdev",
- netdev->ifname);
- if (r < 0)
- return log_oom();
-
- p = path_join(dest_dir, filename);
- if (!p)
+ if (asprintf(&p, "%s/90-%s.netdev", dest_dir, netdev->ifname) < 0)
return log_oom();
r = conservative_rename(temp_path, p);
@@ -81,9 +71,9 @@ static int netdev_save(NetDev *netdev, const char *dest_dir) {
}
static int link_save(Link *link, const char *dest_dir) {
- _cleanup_free_ char *filename = NULL, *p = NULL;
_cleanup_(unlink_and_freep) char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
+ _cleanup_free_ char *p = NULL;
int r;
assert(link);
@@ -94,14 +84,10 @@ static int link_save(Link *link, const char *dest_dir) {
link_dump(link, f);
- filename = strjoin(!isempty(link->ifname) ? "90" :
- !hw_addr_is_null(&link->mac) ? "91" : "92",
- "-", link->filename, ".link");
- if (!filename)
- return log_oom();
-
- p = path_join(dest_dir, filename);
- if (!p)
+ if (asprintf(&p, "%s/%s-%s.link",
+ dest_dir,
+ !isempty(link->ifname) ? "90" : !hw_addr_is_null(&link->mac) ? "91" : "92",
+ link->filename) < 0)
return log_oom();
r = conservative_rename(temp_path, p);