ifcfg-rh: cleanup make_bond_port_setting()

- use svGetValue() instead of svGetValueStr(). The difference is that
  svGetValueStr() coerces "" to NULL. "" is not a valid value, but we
  want to parse the value and print an warning message about it. Also,
  the presence of the variable determines whether we add the bond-port
  setting or not.

- don't use nm_clear_g_free(). @value_to_free is gs_free, it will be
  cleared automatically.

- use g_object_set() instead of nm_g_object_set_property_uint(). The
  latter is our own implementation that does error checking (e.g., that
  the value is in range (0..2^16-1). But we already ensured that to
  be the case. So just call g_object_set(), it cannot fail and if it
  would, we want the assertion failure that it would cause.

- queue_id should be a "guint". It is always true on Linux/glib that
  sizeof(guint) >= sizeof(guint32), the opposite theoretically might not
  be true.
  But later we use the variable in the variadic function g_object_set(),
  where it should be guint.

- the errno from _nm_utils_ascii_str_to_uint64() isn't very useful for
  logging. It's either ERANGE or EINVAL, and logging the numeric values
  of these error codes isn't gonna help the user. We could stringify
  with nm_strerror_native(errno), but that message is also not very
  useful. Just say that the string is not a number.
This commit is contained in:
Thomas Haller 2021-08-26 17:25:11 +02:00
parent a15d991d49
commit f15498eda3
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -5500,26 +5500,20 @@ make_bond_port_setting(shvarFile *ifcfg)
NMSetting * s_port = NULL;
gs_free char *value_to_free = NULL;
const char * value;
guint32 queue_id = 0;
guint queue_id;
g_return_val_if_fail(ifcfg != NULL, FALSE);
value = svGetValueStr(ifcfg, "BOND_PORT_QUEUE_ID", &value_to_free);
value = svGetValue(ifcfg, "BOND_PORT_QUEUE_ID", &value_to_free);
if (value) {
s_port = nm_setting_bond_port_new();
queue_id =
_nm_utils_ascii_str_to_uint64(value, 10, 0, G_MAXUINT16, NM_BOND_PORT_QUEUE_ID_DEF);
if (errno != 0) {
PARSE_WARNING("Invalid bond port queue_id value '%s': error %d", value, errno);
nm_clear_g_free(&value_to_free);
PARSE_WARNING("Invalid bond port queue_id value '%s'", value);
return s_port;
} else {
nm_clear_g_free(&value_to_free);
nm_g_object_set_property_uint(G_OBJECT(s_port),
NM_SETTING_BOND_PORT_QUEUE_ID,
queue_id,
NULL);
}
g_object_set(G_OBJECT(s_port), NM_SETTING_BOND_PORT_QUEUE_ID, queue_id, NULL);
}
return s_port;