aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortoni <matzeton@googlemail.com>2016-07-24 00:21:56 +0200
committertoni <matzeton@googlemail.com>2016-07-24 00:21:56 +0200
commit4c331adc73694bd62c81a05f770a5d4ed4fa9979 (patch)
treefcb626234cabbf12917d21a200fbdce38ee50adc /src
parentf567bc9b6789cddb8100bc478ee25b053be8f684 (diff)
cleanup 2.0
Diffstat (limited to 'src')
-rw-r--r--src/config.h1
-rw-r--r--src/main.c3
-rw-r--r--src/ui.c34
-rw-r--r--src/ui.h3
-rw-r--r--src/ui_elements.c2
-rw-r--r--src/ui_ipc.c2
-rw-r--r--src/ui_ipc.h3
7 files changed, 34 insertions, 14 deletions
diff --git a/src/config.h b/src/config.h
index 797376f..7313669 100644
--- a/src/config.h
+++ b/src/config.h
@@ -8,7 +8,6 @@
#define SEM_GUI "/naskpass-gui"
#define SEM_INP "/naskpass-input"
#define SEM_BSY "/naskpass-busy"
-#define SEM_RDY "/naskpass-initialized"
#define MSQ_PWD "/naskpass-passwd"
#define MSQ_INF "/naskpass-info"
diff --git a/src/main.c b/src/main.c
index d4ba0f9..9d911d7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -191,10 +191,11 @@ main(int argc, char **argv)
}
ret = EXIT_SUCCESS;
+ ui_ipc_free(1);
error:
logs("%s\n", "exiting ..");
if (ffd >= 0) close(ffd);
- ui_ipc_free(1);
+ ui_ipc_free(0);
log_free();
exit(ret);
}
diff --git a/src/ui.c b/src/ui.c
index 2363db6..8dab68a 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -180,16 +180,18 @@ do_ui_update(bool timed_out)
if (timed_out == TRUE && atmout > 0) {
atmout--;
} else if (timed_out == TRUE && atmout == 0) {
- ui_ipc_semwait(SEM_UI);
+ ui_ipc_semtrywait(SEM_UI);
} else {
atmout = APP_TIMEOUT;
}
while (cur != NULL) {
if (cur->cbs.ui_element != NULL) {
- cur->cbs.ui_element(cur->wnd, cur->data, timed_out);
+ if ( (retval = cur->cbs.ui_element(cur->wnd, cur->data, timed_out)) != UICB_OK)
+ break;
doupdate();
} else {
retval = UICB_ERR_CB;
+ break;
}
cur = cur->next;
}
@@ -198,7 +200,7 @@ do_ui_update(bool timed_out)
mvprintw(0, max_x - STRLEN(APP_TIMEOUT_FMT), "[" APP_TIMEOUT_FMT "]", atmout);
attroff(COLOR_PAIR(1));
/* EoT (End of Todo) */
- retval |= (wmove(wnd_main, cur_y, cur_x) << 4);
+ wmove(wnd_main, cur_y, cur_x);
wrefresh(wnd_main);
return (retval);
}
@@ -210,13 +212,13 @@ ui_thrd(void *arg)
struct timespec now;
do_ui_update(true);
- ui_ipc_sempost(SEM_RD);
pthread_mutex_lock(&mtx_update);
clock_gettime(CLOCK_REALTIME, &now);
now.tv_sec += UILOOP_TIMEOUT;
while ( ui_ipc_getvalue(SEM_UI) > 0 ) {
cnd_ret = pthread_cond_timedwait(&cnd_update, &mtx_update, &now);
- do_ui_update( (cnd_ret == ETIMEDOUT ? true : false) );
+ if ( do_ui_update( (cnd_ret == ETIMEDOUT ? true : false) ) != UICB_OK )
+ break;
if (cnd_ret == ETIMEDOUT) {
clock_gettime(CLOCK_REALTIME, &now);
now.tv_sec += UILOOP_TIMEOUT;
@@ -292,12 +294,31 @@ stop_ui_thrd(void)
return (pthread_join(thrd, NULL));
}
+int ui_wgetchtest(int timeout, char testchar)
+{
+ int retval = DOUI_OK;
+ usleep(timeout/2);
+ pthread_mutex_lock(&mtx_update);
+ if ( ui_ipc_getvalue(SEM_UI) <= 0 ) {
+ retval = DOUI_KEY;
+ } else if ( wgetch(wnd_main) == testchar ) {
+ retval = DOUI_KEY;
+ }
+ pthread_mutex_unlock(&mtx_update);
+ usleep(timeout/2);
+ return retval;
+}
+
char ui_wgetch(int timeout)
{
char key;
usleep(timeout/2);
pthread_mutex_lock(&mtx_update);
- key = wgetch(wnd_main);
+ if ( ui_ipc_getvalue(SEM_UI) <= 0 ) {
+ key = ERR;
+ } else {
+ key = wgetch(wnd_main);
+ }
pthread_mutex_unlock(&mtx_update);
usleep(timeout/2);
return key;
@@ -318,7 +339,6 @@ do_ui(void)
pthread_mutex_unlock(&mtx_update);
return ret;
}
- ui_ipc_semwait(SEM_RD);
pthread_mutex_unlock(&mtx_update);
timeout(0);
while ( ui_ipc_getvalue(SEM_UI) > 0 ) {
diff --git a/src/ui.h b/src/ui.h
index 94eaa17..d8b1f9b 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -13,6 +13,7 @@
#define DOUI_ERR 4
#define DOUI_TMOUT 5
#define DOUI_NINIT 6
+#define DOUI_KEY 7
#define UILOOP_TIMEOUT 1
@@ -86,6 +87,8 @@ free_ui(void);
char ui_wgetch(int timeout);
+int ui_wgetchtest(int timeout, char testchar);
+
int
do_ui(void);
diff --git a/src/ui_elements.c b/src/ui_elements.c
index 94bff5c..aae1aff 100644
--- a/src/ui_elements.c
+++ b/src/ui_elements.c
@@ -97,7 +97,7 @@ passwd_input_cb(WINDOW *wnd, void *data, int key)
if (ui_ipc_msgcount(MQ_IF) > 0) {
ui_ipc_msgrecv(MQ_IF, ipc_buf);
show_info_wnd(infownd, "ERROR", ipc_buf, COLOR_PAIR(4), COLOR_PAIR(4), true, true);
- while (ui_wgetch(1500) != '\n') { };
+ while (ui_wgetchtest(1500, '\n') != DOUI_KEY) { };
}
ui_thrd_suspend();
diff --git a/src/ui_ipc.c b/src/ui_ipc.c
index cf137e7..669c1d6 100644
--- a/src/ui_ipc.c
+++ b/src/ui_ipc.c
@@ -48,7 +48,6 @@ ui_ipc_init(int is_master)
JMP_IF( sems[SEM_UI] = sem_open(SEM_GUI, sp_oflags, crt_flags, 0), SEM_FAILED, error );
JMP_IF( sems[SEM_IN] = sem_open(SEM_INP, sp_oflags, crt_flags, 0), SEM_FAILED, error );
JMP_IF( sems[SEM_BS] = sem_open(SEM_BSY, sp_oflags, crt_flags, 0), SEM_FAILED, error );
- JMP_IF( sems[SEM_RD] = sem_open(SEM_RDY, sp_oflags, crt_flags, 0), SEM_FAILED, error );
return 0;
error:
return errno;
@@ -69,7 +68,6 @@ ui_ipc_free(int is_master)
sem_unlink(SEM_BSY);
sem_unlink(SEM_GUI);
sem_unlink(SEM_INP);
- sem_unlink(SEM_RDY);
mq_unlink(MSQ_PWD);
mq_unlink(MSQ_INF);
}
diff --git a/src/ui_ipc.h b/src/ui_ipc.h
index 5ecfaa4..0b71d08 100644
--- a/src/ui_ipc.h
+++ b/src/ui_ipc.h
@@ -8,8 +8,7 @@
enum UI_IPC_SEM {
- SEM_RD = 0, /* UI Init done? */
- SEM_UI, /* TUI active? */
+ SEM_UI = 0, /* TUI active? */
SEM_IN, /* Textfield has input avail */
SEM_BS, /* Master process busy */
SEM_NUM