[tlbuild] dvi test?

John Hawkinson jhawk at alum.mit.edu
Wed Feb 2 16:13:15 CET 2022



Paul Vojta <vojta at math.berkeley.edu> wrote on Tue,  1 Feb 2022
at 23:08:58 EST in <YfoD2q6SXifEqpoj at math.berkeley.edu>:

> Most notably, probably it would be a good idea to call fseek() and fflush() 
> before ftruncate().

As previously reported, calling fseek() before ftruncate() does not resolve the matter, and fseek() returns an error which we now check in TeXLive as of r61850. It does so regardless of whether fseek() is called after ftruncate() [as it is now], or before ftruncate() [as I tested yesterday]:

John Hawkinson <jhawk at alum.mit.edu> wrote on Tue,  1 Feb 2022
at 16:12:25 EST in <YfmiOXrR/toWYf5p at louder-room.local>:

> But in any event, reordering them to put the ftruncate() after 1 or both fseek()s does not solve the problem.

Adding an fflush(target_fp) ahead of fseek(target_fp) generates EINVAL.
That is, this output:

jhawk at lrr xdvik % TEXMFROOT=/usr/local/texlive/2021 TEXMFCNF=$TEXMFROOT/texmf-dist/web2c  ./xdvi-bin ~/xdvi-tmp/t2a
fflush: Invalid argument
xdvi-bin: Error: Couldn't seek to start of file /var/folders/m2/16zlwjgj2p5d3qdy99z2gzf40000gn/T/xdvi-Vn2vpo: Invalid argument - disabling `useTempFp'; target_fp: 0x219c06d40.

from this debugging patch:

--- a/texk/xdvik/dvi-init.c
+++ b/texk/xdvik/dvi-init.c
@@ -1185,6 +1185,13 @@ make_backup_fp(FILE *source_fp, FILE *target_fp)
 	ASSERT(target_fp != NULL, "");
 	ASSERT(source_fp != NULL, "");
 
+	if (fflush(target_fp)) { perror("fflush"); }
+	if (fseek(target_fp, 0L, SEEK_SET)) {
+	  XDVI_ERROR((stderr, "Couldn't seek to start of file %s: %s - disabling `useTempFp'; target_fp: %p.",
+			m_tmp_dvi_name, strerror(errno), target_fp));
+	  goto fclose_and_fail;
+	}
+
 #if HAVE_FTRUNCATE
 	if (ftruncate(tmp_fd, 0) < 0) {
 	    XDVI_ERROR((stderr, "Couldn't truncate file %s: %s - disabling `useTempFp'; target_fp: %p.",
@@ -1192,11 +1199,6 @@ make_backup_fp(FILE *source_fp, FILE *target_fp)
 	    goto fclose_and_fail;
 	}
 #endif
-	if (fseek(target_fp, 0L, SEEK_SET)) {
-	  XDVI_ERROR((stderr, "Couldn't seek to start of file %s: %s - disabling `useTempFp'; target_fp: %p.",
-			m_tmp_dvi_name, strerror(errno), target_fp));
-	  goto fclose_and_fail;
-	}
 	if (fseek(source_fp, 0L, SEEK_SET)) {
 	  perror("fseek of source_fp");
 	  goto fclose_and_fail;


Same result if I call fflush(NULL), to flush all streams. [Huh, I didn't know you could do that.]

Ultimately this is not particularly surprising. If we have corrupted the FILE* stream state for whatever reason such that some parts of stdio don't work (fseek()), it's not surprising that other parts (fflush()) do not work right either.


Bruno Haible <bruno at clisp.org> wrote on Wed,  2 Feb 2022
at 00:14:14 EST in <6375922.q0ZmV6gNhb at omega>:

> Note that fflush() then fseek() on input streams behaves in an OS
> dependent way [1]. About fseek() then fflush(), I don't know.

Given that fseek() fails [whether called before or after ftruncate()] there's not much point in testing fflush() after fseek().

--
jhawk at alum.mit.edu
John Hawkinson


More information about the tlbuild mailing list.