diff options
-rw-r--r-- | src/main.c | 16 | ||||
-rw-r--r-- | src/ui.c | 10 | ||||
-rw-r--r-- | src/ui_input.c | 5 | ||||
-rw-r--r-- | src/ui_statusbar.c | 4 |
4 files changed, 8 insertions, 27 deletions
@@ -1,17 +1,10 @@ #include <stdio.h> #include <stdlib.h> -#include <unistd.h> -#include <stdbool.h> #include <string.h> -#include <unistd.h> #include <errno.h> #include <sys/stat.h> -#include <sys/types.h> #include <sys/wait.h> #include <fcntl.h> -#include <semaphore.h> -#include <time.h> -#include <mqueue.h> #include "config.h" #include "opt.h" @@ -97,16 +90,13 @@ main(int argc, char **argv) int ret = EXIT_FAILURE, ffd = -1, c_status; pid_t child; char pbuf[IPC_MQSIZ+1]; - struct timespec ts_sem_input; bool csetup_ok = false; signal(SIGINT, SIG_IGN); signal(SIGTERM, sigfunc); - if ( clock_gettime(CLOCK_REALTIME, &ts_sem_input) == -1 ) { - fprintf(stderr, "%s: clock get time error: %d (%s)\n", argv[0], errno, strerror(errno)); - goto error; - } + if ( parse_cmd(argc, argv) != 0 ) + exit(EXIT_FAILURE); if (ui_ipc_init(1) != 0) { fprintf(stderr, "%s: can not create semaphore/message queue: %d (%s)\n", argv[0], errno, strerror(errno)); @@ -114,8 +104,6 @@ main(int argc, char **argv) } memset(pbuf, '\0', IPC_MQSIZ+1); - if ( parse_cmd(argc, argv) != 0 ) - goto error; log_init( GETOPT(LOG_FILE).str ); logs("%s\n", "log init"); logs_dbg("%s\n", "debug mode active"); @@ -1,18 +1,10 @@ #include <stdio.h> #include <stdlib.h> -#include <stdbool.h> -#include <unistd.h> #include <errno.h> #include <pthread.h> -#include <semaphore.h> #include <string.h> #include <ncurses.h> -#include <signal.h> #include <sys/time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <mqueue.h> #include "ui.h" #include "ui_ipc.h" @@ -362,7 +354,7 @@ do_ui(void) continue; if ( process_key(key) != true ) { - raise(SIGTERM); + ui_ipc_semtrywait(SEM_UI); } pthread_mutex_lock(&mtx_update); diff --git a/src/ui_input.c b/src/ui_input.c index 9c53330..4ba4769 100644 --- a/src/ui_input.c +++ b/src/ui_input.c @@ -1,5 +1,6 @@ #include <stdlib.h> #include <string.h> +#include <alloca.h> #include "ui.h" #include "ui_input.h" @@ -106,16 +107,16 @@ print_input(WINDOW *win, struct input *a) } else { mvprintw(a->y, a->x, a->prompt); } - tmp = calloc(a->width+1, sizeof(char)); + tmp = alloca(a->width+1 * sizeof(char)); for (i = 0; i < a->width; i++) { *(tmp + i) = '_'; } + tmp[i] = '\0'; if (win) { mvwprintw(win, a->y, a->x + p_len, tmp); } else { mvprintw(a->y, a->x + p_len, tmp); } - free(tmp); print_input_text(win, a); attroff(a->attrs); } diff --git a/src/ui_statusbar.c b/src/ui_statusbar.c index df88683..bec4e50 100644 --- a/src/ui_statusbar.c +++ b/src/ui_statusbar.c @@ -1,5 +1,6 @@ #include <stdlib.h> #include <string.h> +#include <alloca.h> #include "ui.h" #include "ui_statusbar.h" @@ -41,7 +42,7 @@ statusbar_cb(WINDOW *win, void *data, bool timed_out) if (len < a->width) { diff_pos = (unsigned int) (a->width - len)/2; } - tmp = (char *) malloc(a->width + 1); + tmp = (char *) alloca(a->width + 1); memset(tmp, ' ', a->width); tmp[a->width] = '\0'; strncpy((tmp + diff_pos), a->text, len); @@ -53,7 +54,6 @@ statusbar_cb(WINDOW *win, void *data, bool timed_out) } else { mvprintw(a->y, 0, tmp); } - free(tmp); attroff(a->attrs); return (UICB_OK); } |