Beniamino Galvani 2020-07-06 09:59:56 +02:00
commit db1363fcec
3 changed files with 60 additions and 17 deletions

View file

@ -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;

View file

@ -132,6 +132,7 @@ reader_get_default_connection (Reader *reader)
NULL,
NM_SETTING_WIRED_SETTING_NAME,
NM_CONNECTION_MULTI_CONNECT_MULTIPLE);
nm_connection_add_setting (con, nm_setting_wired_new ());
reader->default_connection = con;
}
return reader->default_connection;

View file

@ -1217,7 +1217,7 @@ test_rd_znet_no_ip (void)
}
static void
test_bootif (void)
test_bootif_ip (void)
{
gs_unref_hashtable GHashTable *connections = NULL;
const char *const*ARGV = NM_MAKE_STRV ("BOOTIF=00:53:AB:cd:02:03",
@ -1254,6 +1254,42 @@ test_bootif (void)
g_assert (!nm_setting_ip_config_get_ignore_auto_dns (s_ip6));
}
static void
test_bootif_no_ip (void)
{
gs_unref_hashtable GHashTable *connections = NULL;
const char *const*ARGV = NM_MAKE_STRV ("BOOTIF=00:53:AB:cd:02:03");
NMConnection *connection;
NMSettingWired *s_wired;
NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
gs_free char *hostname = NULL;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, NULL);
connection = g_hash_table_lookup (connections, "default_connection");
g_assert (connection);
nmtst_assert_connection_verifies_without_normalization (connection);
g_assert_cmpstr (nm_connection_get_id (connection), ==, "Wired Connection");
s_wired = nm_connection_get_setting_wired (connection);
g_assert_cmpstr (nm_setting_wired_get_mac_address (s_wired), ==, "00:53:AB:CD:02:03");
g_assert (s_wired);
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
g_assert (nm_setting_ip_config_get_may_fail (s_ip4));
s_ip6 = nm_connection_get_setting_ip6_config (connection);
g_assert (s_ip6);
g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
g_assert (nm_setting_ip_config_get_may_fail (s_ip6));
}
static void
test_bootif_hwtype (void)
{
@ -1410,7 +1446,8 @@ int main (int argc, char **argv)
g_test_add_func ("/initrd/cmdline/rd_znet", test_rd_znet);
g_test_add_func ("/initrd/cmdline/rd_znet/legacy", test_rd_znet_legacy);
g_test_add_func ("/initrd/cmdline/rd_znet/no_ip", test_rd_znet_no_ip);
g_test_add_func ("/initrd/cmdline/bootif", test_bootif);
g_test_add_func ("/initrd/cmdline/bootif/ip", test_bootif_ip);
g_test_add_func ("/initrd/cmdline/bootif/no_ip", test_bootif_no_ip);
g_test_add_func ("/initrd/cmdline/bootif/hwtype", test_bootif_hwtype);
g_test_add_func ("/initrd/cmdline/bootif/off", test_bootif_off);