]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wpa_cli: Redisplay readline edit after event messages
authorJouni Malinen <jouni.malinen@atheros.com>
Fri, 12 Mar 2010 15:24:50 +0000 (17:24 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 12 Mar 2010 15:24:50 +0000 (17:24 +0200)
wpa_supplicant/wpa_cli.c

index 518afa089cf342d8c39fb09236afa31fe8eb27da..454852c1240d1cc58716f6df989ae6b361719289 100644 (file)
@@ -128,6 +128,16 @@ static void usage(void)
 
 
 #ifdef CONFIG_WPA_CLI_FORK
+static int in_query = 0;
+
+static void wpa_cli_monitor_sig(int sig)
+{
+       if (sig == SIGUSR1)
+               in_query = 1;
+       else if (sig == SIGUSR2)
+               in_query = 0;
+}
+
 static void wpa_cli_monitor(void)
 {
        char buf[256];
@@ -135,6 +145,9 @@ static void wpa_cli_monitor(void)
        struct timeval tv;
        fd_set rfds;
 
+       signal(SIGUSR1, wpa_cli_monitor_sig);
+       signal(SIGUSR2, wpa_cli_monitor_sig);
+
        while (mon_conn) {
                int s = wpa_ctrl_get_fd(mon_conn);
                tv.tv_sec = 5;
@@ -142,6 +155,8 @@ static void wpa_cli_monitor(void)
                FD_ZERO(&rfds);
                FD_SET(s, &rfds);
                if (select(s + 1, &rfds, NULL, NULL, &tv) < 0) {
+                       if (errno == EINTR)
+                               continue;
                        perror("select");
                        break;
                }
@@ -155,7 +170,10 @@ static void wpa_cli_monitor(void)
                                break;
                        }
                        buf[len] = '\0';
+                       if (in_query)
+                               printf("\r");
                        printf("%s\n", buf);
+                       kill(getppid(), SIGUSR1);
                }
        }
 }
@@ -1841,9 +1859,13 @@ static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl, int in_read,
                                wpa_cli_action_process(buf);
                        else {
                                if (in_read && first)
-                                       printf("\n");
+                                       printf("\r");
                                first = 0;
                                printf("%s\n", buf);
+#ifdef CONFIG_READLINE
+                               rl_on_new_line();
+                               rl_redisplay();
+#endif /* CONFIG_READLINE */
                        }
                } else {
                        printf("Could not read pending message.\n");
@@ -1930,6 +1952,10 @@ static void wpa_cli_interactive(void)
 #ifndef CONFIG_NATIVE_WINDOWS
                alarm(ping_interval);
 #endif /* CONFIG_NATIVE_WINDOWS */
+#ifdef CONFIG_WPA_CLI_FORK
+               if (mon_pid)
+                       kill(mon_pid, SIGUSR1);
+#endif /* CONFIG_WPA_CLI_FORK */
 #ifdef CONFIG_READLINE
                cmd = readline("> ");
                if (cmd && *cmd) {
@@ -1985,6 +2011,10 @@ static void wpa_cli_interactive(void)
 
                if (cmd != cmdbuf)
                        free(cmd);
+#ifdef CONFIG_WPA_CLI_FORK
+               if (mon_pid)
+                       kill(mon_pid, SIGUSR2);
+#endif /* CONFIG_WPA_CLI_FORK */
        } while (!wpa_cli_quit);
 
 #ifdef CONFIG_READLINE
@@ -2074,6 +2104,17 @@ static void wpa_cli_terminate(int sig)
 }
 
 
+#ifdef CONFIG_WPA_CLI_FORK
+static void wpa_cli_usr1(int sig)
+{
+#ifdef CONFIG_READLINE
+       rl_on_new_line();
+       rl_redisplay();
+#endif /* CONFIG_READLINE */
+}
+#endif /* CONFIG_WPA_CLI_FORK */
+
+
 #ifndef CONFIG_NATIVE_WINDOWS
 static void wpa_cli_alarm(int sig)
 {
@@ -2221,6 +2262,9 @@ int main(int argc, char *argv[])
 #ifndef CONFIG_NATIVE_WINDOWS
        signal(SIGALRM, wpa_cli_alarm);
 #endif /* CONFIG_NATIVE_WINDOWS */
+#ifdef CONFIG_WPA_CLI_FORK
+       signal(SIGUSR1, wpa_cli_usr1);
+#endif /* CONFIG_WPA_CLI_FORK */
 
        if (ctrl_ifname == NULL)
                ctrl_ifname = wpa_cli_get_default_ifname();