mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-29 18:30:11 +01:00
initrd: write the hostname to stdout with --stdout
Don't try to open /run/NetworkManager/initrd when called with
--stdout, but instead write the hostname to the standard output.
Fixes: ff70adf873 ('initrd: save hostname to a file in /run')
This commit is contained in:
parent
3023c70e4e
commit
5fa97d7796
1 changed files with 20 additions and 15 deletions
|
|
@ -130,23 +130,28 @@ 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 (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);
|
||||
|
||||
if (!g_file_set_contents (hostname_file, data, strlen (data), &error)) {
|
||||
_LOGW (LOGD_CORE, "%s: %s", hostname_file, error->message);
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue