shithub: cuefs

Download patch

ref: 8e5da639758f408f3fdaf0047848c2d6a625aa97
parent: 8e4d1533c2665c832bc8f0548bfc9594e601529b
author: Tevo <estevan.cps@gmail.com>
date: Sun Feb 14 17:48:26 EST 2021

flacserve: read from decoder with readn, allocate with mallocz

fixes  infinite reads  on slow machines, possibly fixes  forward seeking 

--- a/BUGS
+++ b/BUGS
@@ -13,3 +13,4 @@
 		REM DATE 2002
 	it probably wouldn't hurt to try parsing some of those; not a high priority at the moment
 • cuefs does not respect PREGAP and POSTGAP tags on cuesheets
+• zuke's mkplist dislikes cuefs, somehow (trying to mkplist on a cuefs mountpoint doesn't even generate 9p rpcs, something's really wrong)
--- a/cuefs.h
+++ b/cuefs.h
@@ -24,6 +24,7 @@
 void parserfatal(char*, ...);
 
 void debug(char*, ...);
+void trace(char*, ...);
 
 extern int verbosity;
 
--- a/fs.c
+++ b/fs.c
@@ -186,7 +186,7 @@
 {
 	long ret, n;
 
-	debug("readdec: decoder offset = %lld, decoder end = %lld, count = %ld\n",
+	trace("readdec: decoder offset = %lld, decoder end = %lld, count = %ld\n",
 		dec->curoff, dec->end, count);
 
 	/* dec->end == 0 means "there's no end, read what you can" */
@@ -197,7 +197,7 @@
 			count += n;
 	}
 
-	debug("readdec: reading %ld bytes from pid %d\n", count, dec->pid);
+	trace("readdec: reading %ld bytes from pid %d\n", count, dec->pid);
 
 	ret = read(dec->fd, buf, count);
 	dec->curoff += ret;
@@ -346,10 +346,10 @@
 	case 0:
 		for(int n = -1; n != 0;)
 		{
-			debug("polldec: reading %d from decoder\n", sizeof(buf));
+			trace("polldec: reading %d from decoder\n", sizeof(buf));
 			n = readdec(dec, buf, sizeof(buf));
 			write(fd, buf, sizeof(buf));
-			debug("polldec: writing %d into poll pipe\n", n);
+			trace("polldec: writing %d into poll pipe\n", n);
 		}
 		debug("polldec: decoder finished, exiting\n");
 		closedec(dec);
@@ -446,7 +446,7 @@
 	if(pipe(encfd) < 0 || pipe(decfd) < 0)
 		sysfatal("flacenc: pipe: %r");
 
-	enc = emalloc(sizeof(*enc));
+	enc = emallocz(sizeof(*enc), 1);
 	enc->cleanup = (void(*)(void*))closeflac;
 	enc->fd = encfd[0];
 	enc->dec = pipedec(e->file, t2sec(*prefindex(e)), 0, entrylen(e));
@@ -462,7 +462,7 @@
 	long ret;
 
 	debug("readflac: reading %ld bytes from poll pipe\n", count);
-	ret = read(enc->fd, buf, count);
+	ret = readn(enc->fd, buf, count);
 	enc->curoff += ret;
 
 	return ret;
@@ -474,9 +474,12 @@
 	char buf[4096];
 
 	if(offset < enc->curoff)
+	{
+		debug("seekflac: tried to seek to %lld but we're on %lld, refusing\n", offset, enc->curoff);
 		return enc->curoff;
+	}
 
-	debug("seekflac: %lld → %lld\n", offset);
+	debug("seekflac: %lld → %lld\n", enc->curoff, offset);
 
 	for(int todo; (todo = enc->curoff - offset) == 0;)
 	{
--- a/misc.c
+++ b/misc.c
@@ -117,6 +117,19 @@
 {
 	va_list args;
 
+	if(verbosity < 2)
+		return;
+
+	va_start(args, fmt);
+	vfprint(2, fmt, args);
+	va_end(args);
+}
+
+void
+trace(char *fmt, ...)
+{
+	va_list args;
+
 	if(verbosity < 3)
 		return;
 
--- a/mkfile
+++ b/mkfile
@@ -46,3 +46,12 @@
 
 $RCBIN/%: %
 	cp $prereq $target
+
+acid:V: debug.$objtype.acid
+clean nuke:V: cleanacid
+
+cleanacid:V:
+	rm -f debug.^($CPUS)^.acid
+
+debug.$objtype.acid: $HFILES
+	$CC -a *.c >$target