initrd: avoid assertion inparse_rd_znet() and cleanup
- nm_setting_wired_add_s390_option() asserts that a "value" argument is given. Check that the string contains a '=' where we can split. - pass the requested NM_SETTING_WIRED_SETTING_NAME type to get_conn(). Otherwise, @s_wired might be %NULL, resulting in an assertion. I do wonder whether this always retrieves a connection of the appropriate type for modification, or whether a profile could be returned that was created for a different purpose. But that isn't changed. - avoid "g_strcmp0 (nettype, "ctc") != 0". I find it unexpected, that we add the 3rd subchannel component, if the nettype is "ctc" (intuitively, I'd expect it to be the opposite). The reasons for this are not documented, but I presume it is correct. Anyway, using streq() makes this slightly more clear to me, as with strcmp() I would wonder whether this was just a typo while with streq() I'd be more confident that this is indeed intended. - don't initialize local variables unnecessarily. The compiler would warn if we would forget about this. Also, don'\''t use { } for a one-line block.
This commit is contained in:
@@ -686,20 +686,19 @@ parse_rd_peerdns (GHashTable *connections, char *argument)
|
||||
static void
|
||||
parse_rd_znet (GHashTable *connections, char *argument)
|
||||
{
|
||||
const char *nettype = NULL;
|
||||
const char *tmp = NULL;
|
||||
const char *nettype;
|
||||
const char *subchannels[4] = { 0, 0, 0, 0 };
|
||||
const char *tmp;
|
||||
NMConnection *connection;
|
||||
NMSettingWired *s_wired = NULL;
|
||||
NMSettingWired *s_wired;
|
||||
|
||||
nettype = get_word (&argument, ',');
|
||||
subchannels[0] = get_word (&argument, ',');
|
||||
subchannels[1] = get_word (&argument, ',');
|
||||
if (g_strcmp0 (nettype, "ctc") != 0) {
|
||||
if (!nm_streq0 (nettype, "ctc"))
|
||||
subchannels[2] = get_word (&argument, ',');
|
||||
}
|
||||
|
||||
connection = get_conn (connections, NULL, NULL);
|
||||
connection = get_conn (connections, NULL, NM_SETTING_WIRED_SETTING_NAME);
|
||||
s_wired = nm_connection_get_setting_wired (connection);
|
||||
g_object_set (s_wired,
|
||||
NM_SETTING_WIRED_S390_NETTYPE, nettype,
|
||||
@@ -707,10 +706,17 @@ parse_rd_znet (GHashTable *connections, char *argument)
|
||||
NULL);
|
||||
|
||||
while ((tmp = get_word (&argument, ',')) != NULL) {
|
||||
gs_strfreev char ** optval = NULL;
|
||||
char *val;
|
||||
|
||||
optval = g_strsplit (tmp, "=", 2);
|
||||
nm_setting_wired_add_s390_option (s_wired, optval[0], optval[1]);
|
||||
val = strchr (tmp, '=');
|
||||
if (val) {
|
||||
gs_free char *key = NULL;
|
||||
|
||||
key = g_strndup (tmp, val - tmp);
|
||||
val[0] = '\0';
|
||||
val++;
|
||||
nm_setting_wired_add_s390_option (s_wired, key, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user