Merge code sanitizing team config being passed to libteamdctl (rh #1051517)

libteamdctl has fixed the problem with multi-line configuration:
7262e2ce0c
But we still want to remove new-lines in order not to depend on the newest
libteamdctl.

https://bugzilla.redhat.com/show_bug.cgi?id=1051517
This commit is contained in:
Jiří Klimeš 2014-03-12 10:52:15 +01:00
commit 7a4ecc27b4
2 changed files with 16 additions and 2 deletions

View file

@ -907,6 +907,17 @@ nmc_bond_validate_mode (const char *mode, GError **error)
return nmc_string_is_valid (mode, valid_modes, error);
}
/*
* nmc_team_check_config:
* @config: file name with team config, or raw team JSON config data
* @out_config: raw team JSON config data (with removed new-line characters)
* @error: location to store error, or %NUL
*
* Check team config from @config parameter and return the checked/sanitized
* config in @out_config.
*
* Returns: %TRUE if the config is valid, %FALSE if it is invalid
*/
gboolean
nmc_team_check_config (const char *config, char **out_config, GError **error)
{
@ -936,7 +947,7 @@ nmc_team_check_config (const char *config, char **out_config, GError **error)
g_free (contents);
return FALSE;
}
*out_config = contents;
*out_config = g_strdelimit (contents, "\r\n", ' ');
return TRUE;
}

View file

@ -679,8 +679,11 @@ enslave_slave (NMDevice *device,
iface, slave_iface);
} else {
int err;
char *sanitized_config;
err = teamdctl_port_config_update_raw (priv->tdc, slave_iface, config);
sanitized_config = g_strdelimit (g_strdup (config), "\r\n", ' ');
err = teamdctl_port_config_update_raw (priv->tdc, slave_iface, sanitized_config);
g_free (sanitized_config);
if (err != 0) {
nm_log_err (LOGD_TEAM, "(%s): failed to update config for port %s (err=%d)",
iface, slave_iface, err);