summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2020-07-03 16:38:57 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2020-07-03 16:53:55 +0200
commit93c9318e91057c354eb1b059862cc1cbabbc724c (patch)
tree8eda41fe38ca8afae7a7009503bc77e72dcc2c54
parente74310e0a1becea1f8a492c377ef2734848500d7 (diff)
downloadNetworkManager-bg/initrd-bootif.tar.gz
initrd: write the hostname to stdout with --stdoutbg/initrd-bootif
Don't try to open /run/NetworkManager/initrd when called with --stdout, but instead write the hostname to the standard output. Fixes: ff70adf873ef ('initrd: save hostname to a file in /run')
-rw-r--r--src/initrd/nm-initrd-generator.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/initrd/nm-initrd-generator.c b/src/initrd/nm-initrd-generator.c
index ac81dde03c..f984ed739c 100644
--- a/src/initrd/nm-initrd-generator.c
+++ b/src/initrd/nm-initrd-generator.c
@@ -130,22 +130,27 @@ main (int argc, char *argv[])
g_hash_table_foreach (connections, output_conn, connections_dir);
g_hash_table_destroy (connections);
- if (g_mkdir_with_parents (initrd_dir, 0755) != 0) {
- errsv = errno;
- _LOGW (LOGD_CORE, "%s: %s", initrd_dir, nm_strerror_native (errsv));
- return 1;
- }
+ if (dump_to_stdout) {
+ if (hostname)
+ g_print ("\n*** Hostname '%s' ***\n", hostname);
+ } else {
+ if (g_mkdir_with_parents (initrd_dir, 0755) != 0) {
+ errsv = errno;
+ _LOGW (LOGD_CORE, "%s: %s", initrd_dir, nm_strerror_native (errsv));
+ return 1;
+ }
- if (hostname) {
- gs_free char *hostname_file = NULL;
- gs_free char *data = NULL;
+ if (hostname) {
+ gs_free char *hostname_file = NULL;
+ gs_free char *data = NULL;
- hostname_file = g_strdup_printf ("%s/hostname", initrd_dir);
- data = g_strdup_printf ("%s\n", hostname);
+ hostname_file = g_strdup_printf ("%s/hostname", initrd_dir);
+ data = g_strdup_printf ("%s\n", hostname);
- if (!g_file_set_contents (hostname_file, data, strlen (data), &error)) {
- _LOGW (LOGD_CORE, "%s: %s", hostname_file, error->message);
- return 1;
+ if (!g_file_set_contents (hostname_file, data, strlen (data), &error)) {
+ _LOGW (LOGD_CORE, "%s: %s", hostname_file, error->message);
+ return 1;
+ }
}
}