summaryrefslogtreecommitdiff
path: root/src/ui.c
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@lavabit.com>2009-04-07 22:48:52 +0200
committerLars-Dominik Braun <PromyLOPh@lavabit.com>2009-04-07 22:48:52 +0200
commit575ae18234fa5f4d164457ab4f60616ad71b766a (patch)
treed22d3dcc59a32bbf9a80ca3fcb3941909e58adfc /src/ui.c
parent1945a09a7b665a0c6a3980caa64c16c369bd8016 (diff)
downloadpianobar-windows-575ae18234fa5f4d164457ab4f60616ad71b766a.tar.gz
pianobar-windows-575ae18234fa5f4d164457ab4f60616ad71b766a.tar.bz2
pianobar-windows-575ae18234fa5f4d164457ab4f60616ad71b766a.zip
Initial eventcmd work
More useful events should be added...
Diffstat (limited to 'src/ui.c')
-rw-r--r--src/ui.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/ui.c b/src/ui.c
index 694e06c..6154371 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -29,6 +29,11 @@ THE SOFTWARE.
#include <stdlib.h>
#include <string.h>
#include <readline/readline.h>
+#include <errno.h>
+
+/* waitpid () */
+#include <sys/types.h>
+#include <sys/wait.h>
#include "ui.h"
@@ -398,3 +403,60 @@ inline void BarUiPrintSong (PianoSong_t *song, PianoStation_t *station) {
station != NULL ? " @ " : "",
station != NULL ? station->name : "");
}
+
+/* Excute external event handler
+ * @param settings containing the cmdline
+ * @param event type
+ * @param current station
+ * @param current song
+ * @param piano error-code
+ */
+void BarUiStartEventCmd (const BarSettings_t *settings, const char *type,
+ const PianoStation_t *curStation, const PianoSong_t *curSong) {
+ pid_t chld;
+ char pipeBuf[1024];
+ int pipeFd[2];
+
+ if (settings->eventCmd == NULL) {
+ /* nothing to do... */
+ return;
+ }
+
+ /* prepare stdin content */
+ memset (pipeBuf, 0, sizeof (pipeBuf));
+ snprintf (pipeBuf, sizeof (pipeBuf),
+ "artist=%s\n"
+ "title=%s\n"
+ "album=%s\n"
+ "stationName=%s\n",
+ curSong->artist,
+ curSong->title,
+ curSong->album,
+ curStation->name);
+
+ if (pipe (pipeFd) == -1) {
+ BarUiMsg (MSG_ERR, "Cannot create eventcmd pipe. (%s)\n", strerror (errno));
+ return;
+ }
+
+ chld = fork ();
+ if (chld == 0) {
+ /* child */
+ close (pipeFd[1]);
+ dup2 (pipeFd[0], fileno (stdin));
+ execl (settings->eventCmd, settings->eventCmd, type, NULL);
+ BarUiMsg (MSG_ERR, "Cannot start eventcmd. (%s)\n", strerror (errno));
+ close (pipeFd[0]);
+ exit (1);
+ } else if (chld == -1) {
+ BarUiMsg (MSG_ERR, "Cannot fork eventcmd. (%s)\n", strerror (errno));
+ } else {
+ /* parent */
+ int status;
+ close (pipeFd[0]);
+ write (pipeFd[1], pipeBuf, strlen (pipeBuf));
+ close (pipeFd[1]);
+ /* wait to get rid of the zombie */
+ waitpid (chld, &status, 0);
+ }
+}