summary refs log tree commit diff
path: root/src/nmcli/agent.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nmcli/agent.c')
-rw-r--r--src/nmcli/agent.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/nmcli/agent.c b/src/nmcli/agent.c
index a0b23dd1..bdbd6e45 100644
--- a/src/nmcli/agent.c
+++ b/src/nmcli/agent.c
@@ -7,9 +7,12 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#if HAVE_EDITLINE_READLINE
+#include <editline/readline.h>
+#else
 #include <readline/readline.h>
 #include <readline/history.h>
-
+#endif
 #include "common.h"
 #include "utils.h"
 #include "libnmc-base/nm-secret-agent-simple.h"
@@ -51,16 +54,14 @@ usage_agent_all(void)
                  "Runs nmcli as both NetworkManager secret and a polkit agent.\n\n"));
 }
 
-/* for pre-filling a string to readline prompt */
 static char *pre_input_deftext;
-static int
-set_deftext(void)
+
+static int set_deftext(_NMC_RL_STARTUPHOOK_ARGS)
 {
     if (pre_input_deftext && rl_startup_hook) {
         rl_insert_text(pre_input_deftext);
-        g_free(pre_input_deftext);
-        pre_input_deftext = NULL;
-        rl_startup_hook   = NULL;
+        nm_clear_g_free(&pre_input_deftext);
+        rl_startup_hook = NULL;
     }
     return 0;
 }
@@ -83,8 +84,8 @@ get_secrets_from_user(const NmcConfig *nmc_config,
             g_print("%s\n", msg);
         if (secret->value) {
             /* Prefill the password if we have it. */
-            rl_startup_hook   = set_deftext;
-            pre_input_deftext = g_strdup(secret->value);
+            rl_startup_hook = set_deftext;
+            nm_strdup_reset(&pre_input_deftext, secret->value);
         }
         if (secret->no_prompt_entry_id)
             pwd = nmc_readline(nmc_config, "%s: ", secret->pretty_name);