ap

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

commit 8d1ae8fdc51355243f996b3c068976d82acb4faf
parent bffec1be6a98d9bcb8d82ffbb6d54f1f0e27003b
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Sun,  4 Jun 2023 20:21:38 -0700

Allow configuring aps using arguments

It simply executes apc(1) with it's own arguments (even if there
are no arguments) and calls aps_update() in a loop as long as there
is at least one client.

While the need for this is questionable, there is a difference
between running

	aps && apc ...

versus

	aps ...

in that (A) pplay() isn't called during configuration, and (B) the
server hasn't made itself "public" by exiting yet.

Diffstat:
Maps/main.c | 36+++++++++++++++++++++++++++++++++++-
Mman/aps.1 | 8++++++++
2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/aps/main.c b/aps/main.c @@ -79,6 +79,36 @@ sigint(int sig) } int +configure(struct aps *aps, char **argv) +{ + int status; + pid_t pid; + + pid = fork(); + if (pid < 0) + die("unable to fork"); + + if (pid == 0) { + *argv = "apsrc"; + execvp("apc", argv); + perror("unable to execute apc"); + _exit(1); + } + + if (aps_update(aps)) + return 1; + + while (!aps->close && aps->nfds > 0) { + if (aps_update(aps) && errno != EINTR) + return 1; + } + + if (waitpid(pid, &status, 0) < 0) + return 1; + return WIFEXITED(status) ? WEXITSTATUS(status) : 1; +} + +int run(struct aps *aps) { while (!aps->close) { @@ -111,12 +141,16 @@ main(int argc, char *argv[]) aps->coms = commands; aps->ncoms = LEN(commands); - signal(SIGCHLD, sigchld); signal(SIGHUP, SIG_IGN); signal(SIGINT, sigint); signal(SIGQUIT, sigclose); signal(SIGTERM, sigclose); + if (configure(aps, argv)) + die("unable to re-configure"); + + signal(SIGCHLD, sigchld); + error = fork(); if (error == -1) die("unable to fork"); diff --git a/man/aps.1 b/man/aps.1 @@ -6,6 +6,7 @@ .Nd audio player server .Sh SYNOPSIS .Nm aps +.Op Ar command .Sh DESCRIPTION The .Nm @@ -22,6 +23,13 @@ listens for clients on a UNIX socket bound to .Pa /tmp/aps (but see .Sx ENVIRONMENT ) . +Before entering the main loop, +.Nm +will +.Xr fork 2 +and execute +.Xr apc 1 +to re-configure the itself. Once .Nm is fully initialized and listening for clients, it will