static esl_handle_t *global_handle;
static cli_profile_t *global_profile;
static int running = 1;
-static int thread_running = 0;
+static int thread_running = 0, thread_up = 0, check_up = 0;
static char *filter_uuid;
static char *logfilter;
static int timeout = 0;
static void redisplay(void)
{
+ esl_mutex_lock(MUTEX);
+ {
#ifdef HAVE_LIBEDIT
-#ifdef HAVE_DECL_EL_REFRESH
+#ifdef XHAVE_DECL_EL_REFRESH
#ifdef HAVE_EL_WSET
- /* Current libedit versions don't implement EL_REFRESH in eln.c so
- * use the wide version instead. */
- el_wset(el, EL_REFRESH);
+ /* Current libedit versions don't implement EL_REFRESH in eln.c so
+ * use the wide version instead. */
+ el_wset(el, EL_REFRESH);
#else
- /* This will work on future libedit versions and versions built
- * without wide character support. */
- el_set(el, EL_REFRESH);
+ /* This will work on future libedit versions and versions built
+ * without wide character support. */
+ el_set(el, EL_REFRESH);
#endif
#else
- /* Old libedit versions don't implement EL_REFRESH at all so use
- * our own implementation instead. */
- const LineInfo *lf = el_line(el);
- const char *c = lf->buffer;
- if (global_profile->batch_mode) return;
- printf("%s",prompt_str);
- while (c < lf->lastchar && *c) {
- putchar(*c);
- c++;
- }
- {
- int pos = (int)(lf->cursor - lf->buffer);
- char s1[12], s2[12];
- putchar('\r');
- snprintf(s1, sizeof(s1), "\033[%dC", bare_prompt_str_len);
- snprintf(s2, sizeof(s2), "\033[%dC", pos);
- printf("%s%s",s1,s2);
- }
- fflush(stdout);
- return;
+ /* Old libedit versions don't implement EL_REFRESH at all so use
+ * our own implementation instead. */
+ const LineInfo *lf = el_line(el);
+ const char *c = lf->buffer;
+ if (global_profile->batch_mode) return;
+ printf("%s",prompt_str);
+ while (c < lf->lastchar && *c) {
+ putchar(*c);
+ c++;
+ }
+ {
+ int pos = (int)(lf->cursor - lf->buffer);
+ char s1[12], s2[12] = "";
+
+ putchar('\r');
+ snprintf(s1, sizeof(s1), "\033[%dC", bare_prompt_str_len);
+ if (pos) snprintf(s2, sizeof(s2), "\033[%dC", pos);
+ printf("%s%s",s1,s2);
+ }
+ fflush(stdout);
#endif
#endif
+ }
+ esl_mutex_unlock(MUTEX);
+ return;
}
static int output_printf(const char *fmt, ...)
{
esl_handle_t *handle = (esl_handle_t *) obj;
thread_running = 1;
+ esl_mutex_lock(MUTEX);
+ thread_up = 1;
+ esl_mutex_unlock(MUTEX);
while(thread_running && handle->connected) {
int aok = 1;
esl_status_t status;
}
//sleep_ms(1);
}
+
+ esl_mutex_lock(MUTEX);
+ thread_up = 0;
+ esl_mutex_unlock(MUTEX);
thread_running = 0;
esl_log(ESL_LOG_DEBUG, "Thread Done\n");
return NULL;
snprintf(cmd_str, sizeof(cmd_str), "api console_complete %s\n\n", buf);
}
+ esl_mutex_lock(MUTEX);
esl_send_recv(global_handle, cmd_str);
-
+ esl_mutex_unlock(MUTEX);
+
if (global_handle->last_sr_event && global_handle->last_sr_event->body) {
char *r = global_handle->last_sr_event->body;
char *w, *p1;
output_printf("%s\n", handle.last_sr_reply);
while (running > 0) {
int r;
+
#ifdef HAVE_LIBEDIT
if (!(global_profile->batch_mode)) {
line = el_gets(el, &count);
global_handle = NULL;
thread_running = 0;
+ do {
+ esl_mutex_lock(MUTEX);
+ check_up = thread_up;
+ esl_mutex_unlock(MUTEX);
+ sleep_ms(10);
+ } while (check_up > 0);
+
esl_mutex_destroy(&MUTEX);
return 0;