cli: merge branch 'th/cli-interactive-mode-crash-bgo788104'
https://bugzilla.gnome.org/show_bug.cgi?id=788104
This commit is contained in:
@@ -6888,25 +6888,22 @@ menu_switch_to_level1 (NmcColorOption color_option,
|
|||||||
static gboolean
|
static gboolean
|
||||||
editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_type)
|
editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_type)
|
||||||
{
|
{
|
||||||
|
gs_unref_object NMRemoteConnection *rem_con = NULL;
|
||||||
NMSettingConnection *s_con;
|
NMSettingConnection *s_con;
|
||||||
NMRemoteConnection *rem_con;
|
|
||||||
NMRemoteConnection *con_tmp;
|
NMRemoteConnection *con_tmp;
|
||||||
GWeakRef weak = { { NULL } };
|
GWeakRef weak = { { NULL } };
|
||||||
gboolean removed;
|
gboolean removed;
|
||||||
NmcEditorMainCmd cmd;
|
NmcEditorMainCmd cmd;
|
||||||
char *cmd_user;
|
|
||||||
gboolean cmd_loop = TRUE;
|
gboolean cmd_loop = TRUE;
|
||||||
char *cmd_arg = NULL;
|
|
||||||
char *cmd_arg_s, *cmd_arg_p, *cmd_arg_v;
|
|
||||||
const NMMetaSettingValidPartItem *const*valid_settings_main;
|
const NMMetaSettingValidPartItem *const*valid_settings_main;
|
||||||
const NMMetaSettingValidPartItem *const*valid_settings_slave;
|
const NMMetaSettingValidPartItem *const*valid_settings_slave;
|
||||||
char *valid_settings_str = NULL;
|
gs_free char *valid_settings_str = NULL;
|
||||||
const char *s_type = NULL;
|
const char *s_type = NULL;
|
||||||
AddConnectionInfo *info = NULL;
|
AddConnectionInfo *info = NULL;
|
||||||
gboolean dirty;
|
gboolean dirty;
|
||||||
gboolean temp_changes;
|
gboolean temp_changes;
|
||||||
GError *err1 = NULL;
|
GError *err1 = NULL;
|
||||||
NmcEditorMenuContext menu_ctx;
|
NmcEditorMenuContext menu_ctx = { 0 };
|
||||||
|
|
||||||
s_con = nm_connection_get_setting_connection (connection);
|
s_con = nm_connection_get_setting_connection (connection);
|
||||||
if (s_con)
|
if (s_con)
|
||||||
@@ -6918,12 +6915,8 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
valid_settings_str = get_valid_options_string (valid_settings_main, valid_settings_slave);
|
valid_settings_str = get_valid_options_string (valid_settings_main, valid_settings_slave);
|
||||||
g_print (_("You may edit the following settings: %s\n"), valid_settings_str);
|
g_print (_("You may edit the following settings: %s\n"), valid_settings_str);
|
||||||
|
|
||||||
menu_ctx.level = 0;
|
|
||||||
menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL,
|
menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL,
|
||||||
BASE_PROMPT);
|
BASE_PROMPT);
|
||||||
menu_ctx.curr_setting = NULL;
|
|
||||||
menu_ctx.valid_props = NULL;
|
|
||||||
menu_ctx.valid_props_str = NULL;
|
|
||||||
|
|
||||||
/* Get remote connection */
|
/* Get remote connection */
|
||||||
con_tmp = nm_client_get_connection_by_uuid (nmc->client,
|
con_tmp = nm_client_get_connection_by_uuid (nmc->client,
|
||||||
@@ -6932,6 +6925,12 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
rem_con = g_weak_ref_get (&weak);
|
rem_con = g_weak_ref_get (&weak);
|
||||||
|
|
||||||
while (cmd_loop) {
|
while (cmd_loop) {
|
||||||
|
gs_free char *cmd_user = NULL;
|
||||||
|
gs_free char *cmd_arg = NULL;
|
||||||
|
gs_free char *cmd_arg_s = NULL;
|
||||||
|
gs_free char *cmd_arg_p = NULL;
|
||||||
|
gs_free char *cmd_arg_v = NULL;
|
||||||
|
|
||||||
/* Connection is dirty? (not saved or differs from the saved) */
|
/* Connection is dirty? (not saved or differs from the saved) */
|
||||||
dirty = is_connection_dirty (connection, rem_con);
|
dirty = is_connection_dirty (connection, rem_con);
|
||||||
temp_changes = rem_con ? nm_remote_connection_get_unsaved (rem_con) : TRUE;
|
temp_changes = rem_con ? nm_remote_connection_get_unsaved (rem_con) : TRUE;
|
||||||
@@ -6951,9 +6950,6 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
continue;
|
continue;
|
||||||
cmd = parse_editor_main_cmd (g_strstrip (cmd_user), &cmd_arg);
|
cmd = parse_editor_main_cmd (g_strstrip (cmd_user), &cmd_arg);
|
||||||
|
|
||||||
cmd_arg_s = NULL;
|
|
||||||
cmd_arg_p = NULL;
|
|
||||||
cmd_arg_v = NULL;
|
|
||||||
split_editor_main_cmd_args (cmd_arg, &cmd_arg_s, &cmd_arg_p, &cmd_arg_v);
|
split_editor_main_cmd_args (cmd_arg, &cmd_arg_s, &cmd_arg_p, &cmd_arg_v);
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case NMC_EDITOR_MAIN_CMD_SET:
|
case NMC_EDITOR_MAIN_CMD_SET:
|
||||||
@@ -6992,22 +6988,22 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
g_print (_("use 'goto <setting>' first, or 'set <setting>.<property>'\n"));
|
g_print (_("use 'goto <setting>' first, or 'set <setting>.<property>'\n"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
gs_free char *prop_name = NULL;
|
||||||
|
gs_unref_object NMSetting *ss_created = NULL;
|
||||||
NMSetting *ss = NULL;
|
NMSetting *ss = NULL;
|
||||||
gboolean created_ss = FALSE;
|
|
||||||
char *prop_name;
|
|
||||||
GError *tmp_err = NULL;
|
GError *tmp_err = NULL;
|
||||||
|
|
||||||
if (cmd_arg_s) {
|
if (cmd_arg_s) {
|
||||||
/* setting provided as "setting.property" */
|
/* setting provided as "setting.property" */
|
||||||
ss = is_setting_valid (connection, valid_settings_main, valid_settings_slave, cmd_arg_s);
|
ss = is_setting_valid (connection, valid_settings_main, valid_settings_slave, cmd_arg_s);
|
||||||
if (!ss) {
|
if (!ss) {
|
||||||
ss = create_setting_by_name (cmd_arg_s, valid_settings_main, valid_settings_slave);
|
ss_created = create_setting_by_name (cmd_arg_s, valid_settings_main, valid_settings_slave);
|
||||||
|
ss = ss_created;
|
||||||
if (!ss) {
|
if (!ss) {
|
||||||
g_print (_("Error: invalid setting argument '%s'; valid are [%s]\n"),
|
g_print (_("Error: invalid setting argument '%s'; valid are [%s]\n"),
|
||||||
cmd_arg_s, valid_settings_str);
|
cmd_arg_s, valid_settings_str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
created_ss = TRUE;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (menu_ctx.curr_setting)
|
if (menu_ctx.curr_setting)
|
||||||
@@ -7022,13 +7018,9 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
if (!prop_name) {
|
if (!prop_name) {
|
||||||
g_print (_("Error: invalid property: %s\n"), tmp_err->message);
|
g_print (_("Error: invalid property: %s\n"), tmp_err->message);
|
||||||
g_clear_error (&tmp_err);
|
g_clear_error (&tmp_err);
|
||||||
if (created_ss)
|
|
||||||
g_object_unref (ss);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Ask for value */
|
/* Ask for value */
|
||||||
if (!cmd_arg_v) {
|
if (!cmd_arg_v) {
|
||||||
gs_strfreev char **avals_to_free = NULL;
|
gs_strfreev char **avals_to_free = NULL;
|
||||||
@@ -7052,9 +7044,8 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
g_clear_error (&tmp_err);
|
g_clear_error (&tmp_err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (created_ss)
|
if (ss_created)
|
||||||
nm_connection_add_setting (connection, ss);
|
nm_connection_add_setting (connection, g_steal_pointer (&ss_created));
|
||||||
g_free (prop_name);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -7187,8 +7178,10 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
nmc_tab_completion.setting = NULL; /* for TAB completion */
|
nmc_tab_completion.setting = NULL; /* for TAB completion */
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
gs_free char *prop_name = NULL;
|
||||||
GError *tmp_err = NULL;
|
GError *tmp_err = NULL;
|
||||||
char *prop_name = is_property_valid (ss, cmd_arg_p, &tmp_err);
|
|
||||||
|
prop_name = is_property_valid (ss, cmd_arg_p, &tmp_err);
|
||||||
if (prop_name) {
|
if (prop_name) {
|
||||||
/* Delete property value */
|
/* Delete property value */
|
||||||
if (!nmc_setting_reset_property (ss, prop_name, &tmp_err)) {
|
if (!nmc_setting_reset_property (ss, prop_name, &tmp_err)) {
|
||||||
@@ -7217,7 +7210,6 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
tmp_err->message);
|
tmp_err->message);
|
||||||
g_clear_error (&tmp_err);
|
g_clear_error (&tmp_err);
|
||||||
}
|
}
|
||||||
g_free (prop_name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -7241,8 +7233,8 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
g_print (_("use 'goto <setting>' first, or 'describe <setting>.<property>'\n"));
|
g_print (_("use 'goto <setting>' first, or 'describe <setting>.<property>'\n"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
gs_unref_object NMSetting *ss_free = NULL;
|
||||||
NMSetting *ss = NULL;
|
NMSetting *ss = NULL;
|
||||||
gboolean unref_ss = FALSE;
|
|
||||||
gboolean descr_all;
|
gboolean descr_all;
|
||||||
char *user_s;
|
char *user_s;
|
||||||
|
|
||||||
@@ -7263,23 +7255,29 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
user_s, valid_settings_str);
|
user_s, valid_settings_str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
unref_ss = TRUE;
|
ss_free = ss;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
ss = menu_ctx.curr_setting;
|
ss = menu_ctx.curr_setting;
|
||||||
|
|
||||||
if (descr_all) {
|
if (!ss) {
|
||||||
|
g_print (_("Error: no setting selected; valid are [%s]\n"), valid_settings_str);
|
||||||
|
g_print (_("use 'goto <setting>' first, or 'describe <setting>.<property>'\n"));
|
||||||
|
} else if (descr_all) {
|
||||||
/* Show description for all properties */
|
/* Show description for all properties */
|
||||||
print_setting_description (ss);
|
print_setting_description (ss);
|
||||||
} else {
|
} else {
|
||||||
GError *tmp_err = NULL;
|
GError *tmp_err = NULL;
|
||||||
char *prop_name = is_property_valid (ss, cmd_arg_p, &tmp_err);
|
gs_free char *prop_name = NULL;
|
||||||
|
|
||||||
|
prop_name = is_property_valid (ss, cmd_arg_p, &tmp_err);
|
||||||
if (prop_name) {
|
if (prop_name) {
|
||||||
/* Show property description */
|
/* Show property description */
|
||||||
print_property_description (ss, prop_name);
|
print_property_description (ss, prop_name);
|
||||||
} else {
|
} else {
|
||||||
/* If the string is not a property, try it as a setting */
|
/* If the string is not a property, try it as a setting */
|
||||||
NMSetting *s_tmp;
|
NMSetting *s_tmp;
|
||||||
|
|
||||||
s_tmp = is_setting_valid (connection,
|
s_tmp = is_setting_valid (connection,
|
||||||
valid_settings_main,
|
valid_settings_main,
|
||||||
valid_settings_slave,
|
valid_settings_slave,
|
||||||
@@ -7292,10 +7290,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
tmp_err->message);
|
tmp_err->message);
|
||||||
g_clear_error (&tmp_err);
|
g_clear_error (&tmp_err);
|
||||||
}
|
}
|
||||||
g_free (prop_name);
|
|
||||||
}
|
}
|
||||||
if (unref_ss)
|
|
||||||
g_object_unref (ss);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -7335,13 +7330,16 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
/* Print the whole setting */
|
/* Print the whole setting */
|
||||||
editor_show_setting (ss, nmc);
|
editor_show_setting (ss, nmc);
|
||||||
} else {
|
} else {
|
||||||
|
gs_free char *prop_name = NULL;
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
char *prop_name = is_property_valid (ss, cmd_arg_p, &err);
|
|
||||||
|
prop_name = is_property_valid (ss, cmd_arg_p, &err);
|
||||||
if (prop_name) {
|
if (prop_name) {
|
||||||
/* Print one property */
|
/* Print one property */
|
||||||
char *prop_val = nmc_setting_get_property (ss, prop_name, NULL);
|
gs_free char *prop_val = NULL;
|
||||||
|
|
||||||
|
prop_val = nmc_setting_get_property (ss, prop_name, NULL);
|
||||||
g_print ("%s.%s: %s\n", nm_setting_get_name (ss),prop_name , prop_val);
|
g_print ("%s.%s: %s\n", nm_setting_get_name (ss),prop_name , prop_val);
|
||||||
g_free (prop_val);
|
|
||||||
} else {
|
} else {
|
||||||
/* If the string is not a property, try it as a setting */
|
/* If the string is not a property, try it as a setting */
|
||||||
NMSetting *s_tmp;
|
NMSetting *s_tmp;
|
||||||
@@ -7358,7 +7356,6 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
cmd_arg_s ? "" : _(", neither a valid setting name"));
|
cmd_arg_s ? "" : _(", neither a valid setting name"));
|
||||||
g_clear_error (&err);
|
g_clear_error (&err);
|
||||||
}
|
}
|
||||||
g_free (prop_name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -7469,7 +7466,8 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
* adding ipv{4,6} settings when not present.
|
* adding ipv{4,6} settings when not present.
|
||||||
*/
|
*/
|
||||||
if (con_tmp) {
|
if (con_tmp) {
|
||||||
char *s_name = NULL;
|
gs_free char *s_name = NULL;
|
||||||
|
|
||||||
if (menu_ctx.curr_setting)
|
if (menu_ctx.curr_setting)
|
||||||
s_name = g_strdup (nm_setting_get_name (menu_ctx.curr_setting));
|
s_name = g_strdup (nm_setting_get_name (menu_ctx.curr_setting));
|
||||||
|
|
||||||
@@ -7480,7 +7478,6 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
/* Also update setting for menu context and TAB-completion */
|
/* Also update setting for menu context and TAB-completion */
|
||||||
menu_ctx.curr_setting = s_name ? nm_connection_get_setting_by_name (connection, s_name) : NULL;
|
menu_ctx.curr_setting = s_name ? nm_connection_get_setting_by_name (connection, s_name) : NULL;
|
||||||
nmc_tab_completion.setting = menu_ctx.curr_setting;
|
nmc_tab_completion.setting = menu_ctx.curr_setting;
|
||||||
g_free (s_name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7605,15 +7602,16 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
g_clear_error (&tmp_err);
|
g_clear_error (&tmp_err);
|
||||||
} else {
|
} else {
|
||||||
nmc->editor_prompt_color = color;
|
nmc->editor_prompt_color = color;
|
||||||
g_free (menu_ctx.main_prompt);
|
nm_clear_g_free (&menu_ctx.main_prompt);
|
||||||
if (menu_ctx.level == 0)
|
if (menu_ctx.level == 0) {
|
||||||
menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL,
|
menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL,
|
||||||
BASE_PROMPT);
|
BASE_PROMPT);
|
||||||
else
|
} else {
|
||||||
menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL,
|
menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL,
|
||||||
"nmcli %s> ",
|
"nmcli %s> ",
|
||||||
nm_setting_get_name (menu_ctx.curr_setting));
|
nm_setting_get_name (menu_ctx.curr_setting));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (!cmd_arg_p) {
|
} else if (!cmd_arg_p) {
|
||||||
g_print (_("Current nmcli configuration:\n"));
|
g_print (_("Current nmcli configuration:\n"));
|
||||||
g_print ("status-line: %s\n"
|
g_print ("status-line: %s\n"
|
||||||
@@ -7643,19 +7641,11 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
g_print (_("Unknown command: '%s'\n"), cmd_user);
|
g_print (_("Unknown command: '%s'\n"), cmd_user);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (cmd_user);
|
|
||||||
g_free (cmd_arg);
|
|
||||||
g_free (cmd_arg_s);
|
|
||||||
g_free (cmd_arg_p);
|
|
||||||
g_free (cmd_arg_v);
|
|
||||||
}
|
}
|
||||||
g_free (valid_settings_str);
|
|
||||||
g_free (menu_ctx.main_prompt);
|
g_free (menu_ctx.main_prompt);
|
||||||
g_strfreev (menu_ctx.valid_props);
|
g_strfreev (menu_ctx.valid_props);
|
||||||
g_free (menu_ctx.valid_props_str);
|
g_free (menu_ctx.valid_props_str);
|
||||||
if (rem_con)
|
|
||||||
g_object_unref (rem_con);
|
|
||||||
g_weak_ref_clear (&weak);
|
g_weak_ref_clear (&weak);
|
||||||
|
|
||||||
/* Save history file */
|
/* Save history file */
|
||||||
|
Reference in New Issue
Block a user