ap

An audio player suited to my tastes
Log | Files | Refs | README | LICENSE

commit 3f794f5fedfbf253b5876e491b30fe5d47d30c6e
parent c2ae9384b581171be968e1408f4e4bea7724e379
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Wed, 25 Aug 2021 16:21:10 -0700

Add queue logging and revise logging functions

Diffstat:
Maps/command.c | 1+
Maps/log.c | 19+++++++++++++++----
Maps/log.h | 5+++--
Maps/main.c | 18++++++++----------
Maps/queue.c | 7++++++-
5 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/aps/command.c b/aps/command.c @@ -27,6 +27,7 @@ #include "aps.h" #include "arg.h" #include "find.h" +#include "log.h" #include "queue.h" #include "util.h" diff --git a/aps/log.c b/aps/log.c @@ -20,6 +20,7 @@ #include <limits.h> #include <poll.h> +#include <stdarg.h> #include <stdio.h> #include "aps.h" @@ -39,20 +40,30 @@ apstrll(int level) return "fatal"; case COMMAND: return "command"; + case QUEUE: + return "queue"; default: return "undefined"; } } void -aplog(int level, int fd, char *msg) +aps_logfmt(struct aps *aps, int level, int fd, char *fmt, ...) { - fprintf(stderr, "ap: %s (%d): %s\n", apstrll(level), fd, msg); + va_list ap; + + if (fmt == NULL || (aps && !(level & aps->logmask))) + return; + + fprintf(stderr, "ap(%d): %s: ", fd, apstrll(level)); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fputs("\n", stderr); } void aps_log(struct aps *aps, int level, int fd, char *msg) { - if (aps == NULL || level & aps->logmask) - aplog(level, fd, msg); + aps_logfmt(aps, level, fd, "%s", msg); } diff --git a/aps/log.h b/aps/log.h @@ -3,8 +3,9 @@ enum { WARN = 1 << 1, ERROR = 1 << 2, FATAL = 1 << 3, - COMMAND = 1 << 4 + COMMAND = 1 << 4, + QUEUE = 1 << 5 }; -void aplog(int, int, char *); +void aps_logfmt(struct aps *, int, int, char *, ...); void aps_log(struct aps *, int, int, char *); diff --git a/aps/main.c b/aps/main.c @@ -24,6 +24,7 @@ #include <poll.h> #include <signal.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #ifdef __OpenBSD__ @@ -53,9 +54,10 @@ static struct command commands[] = { }; void -slog(char *s) +die(char *s) { - aplog(FATAL, 0, errstr); + aps_logfmt(NULL, FATAL, 0, "%s: %s", s, errstr); + exit(1); } void @@ -107,17 +109,13 @@ main(int argc, char *argv[]) int error; #ifdef __OpenBSD__ - if (pledge("stdio rpath cpath proc exec unix", NULL)) { - slog("pledge"); - return 1; - } + if (pledge("stdio rpath cpath proc exec unix", NULL)) + die("pledge"); #endif aps = aps_open(NULL, player); - if (aps == NULL) { - slog("unable to setup server"); - return 1; - } + if (aps == NULL) + die("unable to setup server"); aps->player->state = STOPPED; aps->logmask = ~0; diff --git a/aps/queue.c b/aps/queue.c @@ -23,11 +23,14 @@ #include <stddef.h> #include "aps.h" +#include "log.h" int queue_set(struct aps *aps, struct item *item) { aps->queue = item; + aps_logfmt(aps, QUEUE, 0, "set '%s'", item ? item->path : ""); + if (aps->player->state != OFF && aps->player->state != STOPPED) { if (pstop(aps->player)) return 1; @@ -52,6 +55,7 @@ queue_add(struct aps *aps, char *s) return 1; } + aps_logfmt(aps, QUEUE, 0, "add '%s'", item->path); return 0; } @@ -60,9 +64,10 @@ queue_remove(struct aps *aps, struct item *item) { if (item == NULL) return; + + aps_logfmt(aps, QUEUE, 0, "remove '%s'", item->path); if (aps->queue == item) queue_set(aps, item->next == item ? NULL : item->next); - item_unlink(item); item_free(item); }