summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-04-26 14:55:41 +0200
committerGitHub <noreply@github.com>2023-04-26 14:55:41 +0200
commitd21d71fb285ebd4726536159c4ccaa08b7046215 (patch)
tree03c8202c726881e003229aed98bf94ffeac7cb41 /src/network
parent914f280d0c0f1555ff94d5490dc4f264af7f331f (diff)
parentf3e4d04298bb73b836dd7ca90f7c7b09de1e776b (diff)
downloadsystemd-d21d71fb285ebd4726536159c4ccaa08b7046215.tar.gz
Merge pull request #26944 from aafeijoo-suse/systemd-network-generator-initrd-fix
network-generator: do not parse kernel command line more than once
Diffstat (limited to 'src/network')
-rw-r--r--src/network/generator/main.c55
1 files changed, 43 insertions, 12 deletions
diff --git a/src/network/generator/main.c b/src/network/generator/main.c
index a0af0b831b..492980249b 100644
--- a/src/network/generator/main.c
+++ b/src/network/generator/main.c
@@ -4,6 +4,7 @@
#include "build.h"
#include "fd-util.h"
+#include "fs-util.h"
#include "generator.h"
#include "macro.h"
#include "main-func.h"
@@ -17,67 +18,97 @@
static const char *arg_root = NULL;
static int network_save(Network *network, const char *dest_dir) {
- _cleanup_free_ char *filename = NULL;
+ _cleanup_free_ char *filename = NULL, *p = NULL;
+ _cleanup_(unlink_and_freep) char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
int r;
assert(network);
+ r = generator_open_unit_file_full(dest_dir, NULL, NULL, &f, &temp_path);
+ if (r < 0)
+ return r;
+
+ network_dump(network, f);
+
r = asprintf(&filename, "%s-%s.network",
isempty(network->ifname) ? "91" : "90",
isempty(network->ifname) ? "default" : network->ifname);
if (r < 0)
return log_oom();
- r = generator_open_unit_file(dest_dir, "kernel command line", filename, &f);
+ p = path_join(dest_dir, filename);
+ if (!p)
+ return log_oom();
+
+ r = conservative_rename(temp_path, p);
if (r < 0)
return r;
- network_dump(network, f);
-
+ temp_path = mfree(temp_path);
return 0;
}
static int netdev_save(NetDev *netdev, const char *dest_dir) {
- _cleanup_free_ char *filename = NULL;
+ _cleanup_free_ char *filename = NULL, *p = NULL;
+ _cleanup_(unlink_and_freep) char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
int r;
assert(netdev);
+ r = generator_open_unit_file_full(dest_dir, NULL, NULL, &f, &temp_path);
+ if (r < 0)
+ return r;
+
+ netdev_dump(netdev, f);
+
r = asprintf(&filename, "90-%s.netdev",
netdev->ifname);
if (r < 0)
return log_oom();
- r = generator_open_unit_file(dest_dir, "kernel command line", filename, &f);
+ p = path_join(dest_dir, filename);
+ if (!p)
+ return log_oom();
+
+ r = conservative_rename(temp_path, p);
if (r < 0)
return r;
- netdev_dump(netdev, f);
-
+ temp_path = mfree(temp_path);
return 0;
}
static int link_save(Link *link, const char *dest_dir) {
- _cleanup_free_ char *filename = NULL;
+ _cleanup_free_ char *filename = NULL, *p = NULL;
+ _cleanup_(unlink_and_freep) char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
int r;
assert(link);
+ r = generator_open_unit_file_full(dest_dir, NULL, NULL, &f, &temp_path);
+ if (r < 0)
+ return r;
+
+ 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();
- r = generator_open_unit_file(dest_dir, "kernel command line", filename, &f);
+ p = path_join(dest_dir, filename);
+ if (!p)
+ return log_oom();
+
+ r = conservative_rename(temp_path, p);
if (r < 0)
return r;
- link_dump(link, f);
-
+ temp_path = mfree(temp_path);
return 0;
}