+static bool_t termprint, init;
+static FILE *logfile;
+
+static void openlogfile(const char *logfilename)
+{
+ int fd, flags;
+ logfile = fopen(logfilename, "a");
+ if (logfile == NULL) {
+ Log_fatal("Failed to open log file '%s' for writing: %s\n", logfilename, strerror(errno));
+ }
+
+ /* Set the stream as line buffered */
+ if (setvbuf(logfile, NULL, _IOLBF, 0) < 0)
+ Log_fatal("setvbuf() failed: %s\n", strerror(errno));
+
+ /* XXX - Is it neccessary/appropriate that logging to file is non-blocking?
+ * If not, there's a risk that execution blocks, meaning that voice blocks
+ * as well since uMurmur is single threaded by design. OTOH, what could
+ * cause a block? If the disk causes blocking, it is probably br0ken, but
+ * the log could be on a nfs or smb share, so let's set it up as
+ * non-blocking and we'll see what happens.
+ */
+ fd = fileno(logfile);
+ flags = fcntl(fd, F_GETFL, 0);
+ fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+}