aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/Makefile.in2
-rw-r--r--src/main.c2
-rw-r--r--src/ui.c45
-rw-r--r--src/ui.h2
5 files changed, 33 insertions, 20 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index affd4d4..ed6b8d4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,5 +5,5 @@ naskshell_SOURCES=shell/shell.c
if DEBUG
naskpass_CFLAGS=-O0 -g3 -DDEBUG
else
-naskpass_CFLAGS=-Os
+naskpass_CFLAGS=-fPIC -fomit-frame-pointer -Os
endif
diff --git a/src/Makefile.in b/src/Makefile.in
index 9ec6a53..ca78767 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -276,7 +276,7 @@ top_srcdir = @top_srcdir@
naskpass_SOURCES = main.c log.c opt.c status.c ui_ani.c ui.c ui_elements.c ui_input.c ui_ipc.c ui_txtwindow.c ui_statusbar.c
naskpass_check_SOURCES = check/check.c
naskshell_SOURCES = shell/shell.c
-@DEBUG_FALSE@naskpass_CFLAGS = -Os
+@DEBUG_FALSE@naskpass_CFLAGS = -fPIC -fomit-frame-pointer -Os
@DEBUG_TRUE@naskpass_CFLAGS = -O0 -g3 -DDEBUG
all: aconfig.h
$(MAKE) $(AM_MAKEFLAGS) all-am
diff --git a/src/main.c b/src/main.c
index fd56027..e518721 100644
--- a/src/main.c
+++ b/src/main.c
@@ -142,6 +142,7 @@ main(int argc, char **argv)
ui_ipc_semwait(SEM_BS);
do_ui();
}
+ ui_ipc_free(0);
exit(0);
} else if (child > 0) {
/* parent */
@@ -200,7 +201,6 @@ main(int argc, char **argv)
error:
logs("%s\n", "exiting ..");
if (ffd >= 0) close(ffd);
- ui_ipc_free(0);
log_free();
exit(ret);
}
diff --git a/src/ui.c b/src/ui.c
index 8dab68a..463c2a1 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -45,7 +45,7 @@ static WINDOW *wnd_main;
static struct nask_ui /* simple linked list to all UI objects */ *nui = NULL,
/* current active input */ *active = NULL;
static pthread_t thrd;
-static unsigned int atmout = APP_TIMEOUT;
+static int atmout = APP_TIMEOUT;
static pthread_cond_t cnd_update = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t mtx_update = PTHREAD_MUTEX_INITIALIZER;
@@ -177,12 +177,12 @@ do_ui_update(bool timed_out)
/* call all draw callback's */
erase();
- if (timed_out == TRUE && atmout > 0) {
+ if (!timed_out) {
+ atmout = APP_TIMEOUT;
+ } else if (atmout > 0) {
atmout--;
- } else if (timed_out == TRUE && atmout == 0) {
+ } else if (atmout == 0) {
ui_ipc_semtrywait(SEM_UI);
- } else {
- atmout = APP_TIMEOUT;
}
while (cur != NULL) {
if (cur->cbs.ui_element != NULL) {
@@ -205,23 +205,35 @@ do_ui_update(bool timed_out)
return (retval);
}
+static int
+ui_cond_timedwait(pthread_cond_t* cnd, pthread_mutex_t* mtx, int timeInMs)
+{
+ struct timeval tv;
+ struct timespec ts;
+
+ gettimeofday(&tv, NULL);
+ ts.tv_sec = time(NULL) + timeInMs/1000;
+ ts.tv_nsec = tv.tv_usec * 1000 + 1000 * 1000 * (timeInMs % 1000);
+ ts.tv_sec += ts.tv_nsec / (1000 * 1000 * 1000);
+ ts.tv_nsec %= (1000 * 1000 * 1000);
+
+ return pthread_cond_timedwait(cnd, mtx, &ts);
+}
+
static void *
ui_thrd(void *arg)
{
int cnd_ret;
- struct timespec now;
- do_ui_update(true);
pthread_mutex_lock(&mtx_update);
- clock_gettime(CLOCK_REALTIME, &now);
- now.tv_sec += UILOOP_TIMEOUT;
+ do_ui_update(false);
+
while ( ui_ipc_getvalue(SEM_UI) > 0 ) {
- cnd_ret = pthread_cond_timedwait(&cnd_update, &mtx_update, &now);
- 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;
+ cnd_ret = ui_cond_timedwait(&cnd_update, &mtx_update, UILOOP_TIMEOUT);
+ if (cnd_ret == 0) {
+ do_ui_update(false);
+ } else if (cnd_ret == ETIMEDOUT) {
+ do_ui_update(true);
}
}
pthread_mutex_unlock(&mtx_update);
@@ -339,8 +351,9 @@ do_ui(void)
pthread_mutex_unlock(&mtx_update);
return ret;
}
- pthread_mutex_unlock(&mtx_update);
timeout(0);
+ pthread_mutex_unlock(&mtx_update);
+
while ( ui_ipc_getvalue(SEM_UI) > 0 ) {
if ( (key = ui_wgetch(3000)) == ERR )
continue;
diff --git a/src/ui.h b/src/ui.h
index d8b1f9b..d0a80a2 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -15,7 +15,7 @@
#define DOUI_NINIT 6
#define DOUI_KEY 7
-#define UILOOP_TIMEOUT 1
+#define UILOOP_TIMEOUT 1000
#define UIKEY_ACTIVATE 0
#define UIKEY_ENTER 10