diff --git a/src/base/common.c b/src/base/common.c index 647b06aaccdba814a0de94c26dbc7032c85542a0..4b72f9e055a45afa4a24392e53b68485cae95ae5 100644 --- a/src/base/common.c +++ b/src/base/common.c @@ -6,7 +6,9 @@ #include <stdlib.h> #include <string.h> #include <stdarg.h> +#include <time.h> #include <sys/stat.h> +#include <sys/time.h> /* Assert function */ @@ -43,10 +45,23 @@ __lkt_log(enum log_level level, const char *section, const char *func, const cha { char line[LKT_MESSAGE_MAX]; va_list ap; + int hour = 0, min = 0, sec = 0; + time_t rawtime = time(NULL); + struct tm *timeval = localtime(&rawtime); + if (timeval != NULL) { + hour = timeval->tm_hour; + min = timeval->tm_min; + sec = timeval->tm_sec; + } + +#define SEC_PER_DAY 86400 +#define SEC_PER_HOUR 3600 +#define SEC_PER_MIN 60 if (level <= __log_level) { - safe_snprintf(line, LKT_MESSAGE_MAX, " %c [%s] %s: %s\n", + safe_snprintf(line, LKT_MESSAGE_MAX, " %c [%02d:%02d:%02d] %-10s %s: %s\n", level == ERROR ? '!' : level == WARN ? '*' : level == INFO ? '.' : ' ', + hour, min, sec, section, func, format); va_start(ap, format); vfprintf(stderr, line, ap); diff --git a/src/main/server.c b/src/main/server.c index 719574d9594a736dd1687466549dbdf888aef839..852059f44c528761b39a9ead6cda59116326b667 100644 --- a/src/main/server.c +++ b/src/main/server.c @@ -17,12 +17,45 @@ #include <strings.h> #include <pthread.h> #include <sys/stat.h> +#include <termios.h> #if defined (LKT_STATIC_MODULE) REG_DECLARE(sdl2_reg) REG_DECLARE(repo_reg) #endif +/* Disable echo in the console, only for the program */ + +struct termios ___tty_cur, ___tty_save; + +__attribute__((constructor)) +static void ___tty_disable_echo(void) +{ + GOTO_IF((tcgetattr(STDIN_FILENO, &___tty_cur) == -1), + "Failed to get termios flags", error); + + ___tty_save = ___tty_cur; + ___tty_cur.c_lflag &= ~ ECHO; + + GOTO_IF((tcsetattr(STDIN_FILENO, TCSAFLUSH, &___tty_cur) == -1), + "Failed to turned of echo in termios flags", error); + + return; +error: + /* Fails silently for the moment */ + return; +} + +__attribute__((destructor)) +static void ___tty_enable_echo(void) +{ + if (tcsetattr(STDIN_FILENO, TCSANOW, &___tty_save) == -1) + LOG_ERROR("GENERAL", "Failed to reset termios flags"); + errno = 0; + if (fflush(stdin) != 0) + LOG_ERROR("GENERAL", "Failed to flush stdin: %s", strerror(errno)); +} + /* Recursive mkdir, where the last word of the string is a file, not a folder. */ static inline void __mkdir(const char *dir) diff --git a/src/module/mpv.c b/src/module/mpv.c index 7186bd20ce1f932f41921d748ce97d5c3646cb3e..e9a580af9736b6ecf140c22f8a731bd23c070ed0 100644 --- a/src/module/mpv.c +++ b/src/module/mpv.c @@ -50,15 +50,15 @@ lmpv_prepare(volatile sqlite3 *db) MPV_SET_OPTION(opt, _opt); MPV_SET_OPTION("input-default-bindings", "yes"); - MPV_SET_OPTION("input-vo-keyboard", "yes"); - MPV_SET_OPTION("replaygain", "track"); - MPV_SET_OPTION("gpu-context", "x11"); /* Wayland you sucks */ + MPV_SET_OPTION("input-vo-keyboard", "yes"); + MPV_SET_OPTION("replaygain", "track"); + MPV_SET_OPTION("gpu-context", "x11"); /* Wayland you sucks */ MPV_SET_OPTION("demuxer-readahead-secs", "5.0"); - MPV_SET_OPTION("demuxer-max-bytes", "100M"); - MPV_SET_OPTION("hwdec", "yes"); - MPV_SET_FROM_INI("osd-font-size", "player", "font_size"); - MPV_SET_FROM_INI("osd-font", "player", "font_name"); - MPV_SET_FROM_INI("osd-duration", "player", "msg_duration"); + MPV_SET_OPTION("demuxer-max-bytes", "100M"); + MPV_SET_OPTION("hwdec", "yes"); + MPV_SET_FROM_INI("osd-font-size", "player", "font_size"); + MPV_SET_FROM_INI("osd-font", "player", "font_name"); + MPV_SET_FROM_INI("osd-duration", "player", "msg_duration"); return ctx; #undef MPV_SET_OPTION #undef MPV_SET_FROM_INI @@ -68,9 +68,9 @@ int lmpv_observe_properties(mpv_handle *ctx) { return (mpv_observe_property(ctx, 0, "ao-volume", MPV_FORMAT_INT64) >= 0) && - (mpv_observe_property(ctx, 0, "duration", MPV_FORMAT_INT64) >= 0) && - (mpv_observe_property(ctx, 0, "time-pos", MPV_FORMAT_INT64) >= 0) && - (mpv_observe_property(ctx, 0, "pause", MPV_FORMAT_FLAG) >= 0); + (mpv_observe_property(ctx, 0, "duration", MPV_FORMAT_INT64) >= 0) && + (mpv_observe_property(ctx, 0, "time-pos", MPV_FORMAT_INT64) >= 0) && + (mpv_observe_property(ctx, 0, "pause", MPV_FORMAT_FLAG) >= 0); } mpv_handle * @@ -192,13 +192,13 @@ loop: prop = (mpv_event_property *) event->data; if (prop->format == MPV_FORMAT_NONE) break; - // MPV volume (BUG: The flag is not MPV_FORMAT_NONE only at the end of the song...) // + /* MPV volume (BUG: The flag is not MPV_FORMAT_NONE only at the end of the song...) */ if (STR_MATCH(prop->name, "ao-volume") && prop->format == MPV_FORMAT_INT64) { ao_volume = *(int *) prop->data; lkt_queue_send(queue, lkt_event_prop_vol, (void *) ao_volume); } - // File duration // + /* File duration */ if (STR_MATCH(prop->name, "duration") && prop->format == MPV_FORMAT_INT64) { *time_duration = *(int *) prop->data; @@ -209,7 +209,7 @@ loop: *time_pos = *(int *) prop->data; lkt_queue_send(queue, lkt_event_prop_time, (void *) (size_t) *time_pos); } - // Pause state // + /* Pause state */ if (STR_MATCH(prop->name, "pause") && prop->format == MPV_FORMAT_FLAG) { if (* (bool *) prop->data) { @@ -235,5 +235,5 @@ loop: LOG_WARN("WINDOW", "Unhandled mpv event '%s'", mpv_event_name(event->event_id)); break; } - goto loop; /* A loop without indentation. */ + goto loop; /* A loop without indentation. Ugly but better for not-really-wide screens */ } diff --git a/src/net/listen.c b/src/net/listen.c index 4e81d14b8d02b5631235ad35dc493d64adb16aca..00f7c7f8bec7eb5565a1c5d6b592c0555c56b207 100644 --- a/src/net/listen.c +++ b/src/net/listen.c @@ -809,11 +809,11 @@ __signal_handler(int sig) break; switch (sig) { - __HANDLE(INT) - __HANDLE(ILL) - __HANDLE(QUIT) - __HANDLE(USR1) - __HANDLE(USR2) + __HANDLE(INT) + __HANDLE(ILL) + __HANDLE(QUIT) + __HANDLE(USR1) + __HANDLE(USR2) default: LOG_WARN("SIGNAL", "Not handled signal %d", sig); break;